-
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes dev/core#5179 Users with 'access uploaded files' permission (or afform entities with permission checks disables) will see uploaded files as a link which can be clicked to download the file
- Loading branch information
Showing
5 changed files
with
110 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
{{dataProvider.getFieldData()[$ctrl.fieldName]}} | ||
<span ng-if="dataProvider.getFieldData()[$ctrl.fieldName].file_name"> | ||
<a ng-if="dataProvider.getFieldData()[$ctrl.fieldName].url" ng-href="{{:: dataProvider.getFieldData()[$ctrl.fieldName].url }}"> | ||
<i class="crm-i {{ dataProvider.getFieldData()[$ctrl.fieldName].icon }}"></i> | ||
{{ dataProvider.getFieldData()[$ctrl.fieldName].file_name }} | ||
</a> | ||
<span ng-if="!dataProvider.getFieldData()[$ctrl.fieldName].url"> | ||
<i class="crm-i {{ dataProvider.getFieldData()[$ctrl.fieldName].icon }}"></i> | ||
{{ dataProvider.getFieldData()[$ctrl.fieldName].file_name }} | ||
</span> | ||
</span> | ||
<span ng-if="!dataProvider.getFieldData()[$ctrl.fieldName].file_name"> | ||
{{ dataProvider.getFieldData()[$ctrl.fieldName] }} | ||
</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* @package CRM | ||
* @copyright CiviCRM LLC https://civicrm.org/licensing | ||
*/ | ||
|
||
namespace Civi\tests\phpunit\api\v4\Custom; | ||
|
||
use api\v4\Custom\CustomTestBase; | ||
use Civi\Api4\CustomGroup; | ||
use Civi\Api4\CustomField; | ||
use Civi\Api4\File; | ||
|
||
/** | ||
* @group headless | ||
*/ | ||
class CustomFileTest extends CustomTestBase { | ||
|
||
/** | ||
*/ | ||
public function testCustomFileField(): void { | ||
$group = CustomGroup::create()->setValues([ | ||
'title' => 'FileFields', | ||
'extends' => 'Individual', | ||
])->execute()->single(); | ||
$field = CustomField::create()->setValues([ | ||
'label' => 'TestMyFile', | ||
'custom_group_id.name' => 'FileFields', | ||
'html_type' => 'File', | ||
'data_type' => 'File', | ||
])->execute()->single(); | ||
|
||
$fieldName = 'FileFields.TestMyFile'; | ||
|
||
$contact = $this->createTestRecord('Individual'); | ||
|
||
// FIXME: Use Api4 when available | ||
$file = civicrm_api3('Attachment', 'create', [ | ||
// The mismatch between entity id and entity table feels very wrong but that's how core does it for now | ||
'entity_id' => $contact['id'], | ||
'entity_table' => $group['table_name'], | ||
'mime_type' => 'text/plain', | ||
'name' => 'test123.txt', | ||
'content' => 'Hello World 123', | ||
]); | ||
|
||
civicrm_api4('Individual', 'update', [ | ||
'values' => [ | ||
'id' => $contact['id'], | ||
$fieldName => $file['id'], | ||
], | ||
'checkPermissions' => FALSE, | ||
]); | ||
|
||
$file = File::get(FALSE) | ||
->addSelect('id', 'file_name', 'url') | ||
->addWhere('id', '=', $file['id']) | ||
->execute()->single(); | ||
|
||
$this->assertEquals('test123.txt', $file['file_name']); | ||
$this->assertStringContainsString("id={$file['id']}&eid={$contact['id']}&fcs=", $file['url']); | ||
} | ||
|
||
} |