Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHRAS-4034 Prod - api - test sub definition substitution for unknown type #4483

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,15 @@ public function indexAction(Request $request)
/** @var record_adapter $rec */
foreach ($records as $rec) {

$databoxSubdefs = $rec->getDatabox()->get_subdef_structure()->getSubdefGroup($rec->getType());
$recordType = $rec->getType();

// if record type is unknown
// use the type 'document' setting
if ($recordType == 'unknown') {
$recordType = 'document';
}

$databoxSubdefs = $rec->getDatabox()->get_subdef_structure()->getSubdefGroup($recordType);
if ($databoxSubdefs !== null) {
foreach ($databoxSubdefs as $sub) {
if ($sub->isTobuild()) {
Expand Down
3 changes: 3 additions & 0 deletions lib/Alchemy/Phrasea/Media/SubdefSubstituer.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public function substituteSubdef(\record_adapter $record, $name, MediaInterface
}

$type = $record->isStory() ? 'image' : $record->getType();

$type = ($type == 'unknown') ? 'document' : $type;

$databox_subdef = $record->getDatabox()->get_subdef_structure()->get_subdef($type, $name);

if ($this->isOldSubdefPresent($record, $name)) {
Expand Down
6 changes: 6 additions & 0 deletions lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ public function getDoctypeIcon(RecordInterface $record)
$src = '/assets/common/images/icons/icon_flash.png';
$title = $this->app['translator']->trans('flash');
break;
case 'unknown':
if ($record->getMimeType() == 'application/zip') {
$src = '/assets/common/images/icons/substitution/application_zip.png';
$title = $this->app['translator']->trans('zip');
}
break;
}

return sprintf('<img src="%s" title="%s" />', $src, $title);
Expand Down
8 changes: 7 additions & 1 deletion lib/classes/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,14 @@ public function has_access_to_subdef(RecordInterface $record, $subdef_name)

$databox = $this->app->findDataboxById($record->getDataboxId());
try {
$recordType = $record->getType();

if ($recordType == 'unknown') {
$recordType = 'document';
}

$subdef_class = $databox->get_subdef_structure()
->get_subdef($record->getType(), $subdef_name)
->get_subdef($recordType, $subdef_name)
->get_class();
} catch (\Exception $e) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/classes/record/exportElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function get_actions($userOwner)
$subdefs = [];

foreach ($this->app->findDataboxById($sbas_id)->get_subdef_structure() as $subdef_type => $subdefs_obj) {
if ($subdef_type == $this->getType()) {
if ($subdef_type == $this->getType() || ($this->getType() == 'unknown') && $subdef_type == 'document') {
$subdefs = $subdefs_obj;
break;
}
Expand Down
84 changes: 39 additions & 45 deletions templates/web/prod/actions/Tools/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -150,53 +150,47 @@
{% if substituables|length > 0 %} {# substituables is empty if multiple records #}
{% for record in records %}
<div id="substitution" class="tabBox">
{% for substituable in substituables %}
{% set d = (substituable == "document") ? true : false %}
<div id="substitution-hd">
<form
name="formchgHD"
action="{{ path(d ? 'prod_tools_hd_substitution' : 'prod_tools_thumbnail_substitution') }}"
enctype="multipart/form-data"
method="post"
target="uploadHdsub">

{% if "unknown" == record.get_type() %}
<i class="fa fa-exclamation-triangle icon-white"
aria-hidden="true"></i>{{ "Substitution is not possible for this kind of record" | trans }}
{% else %}
{% for substituable in substituables %}
{% set d = (substituable == "document") ? true : false %}
<div id="substitution-hd">
<form
name="formchgHD"
action="{{ path(d ? 'prod_tools_hd_substitution' : 'prod_tools_thumbnail_substitution') }}"
enctype="multipart/form-data"
method="post"
target="uploadHdsub">

<fieldset style='border:1px solid #999;padding:20px;'>
<legend>&nbsp;
<b>{% trans with {'%sd%' : substituable} %}substitution of %sd%{% endtrans %}</b>&nbsp
</legend>
<div>
{% if d %}
<input id='new-hd-file' name="newHD" type="file"/>
<br/>
<label for="CCFNALP" class="checkbox">
<input type="checkbox" name="ccfilename" id="CCFNALP" value="1">
{{ "mettre a jour le nom original de fichier apres substitution" | trans }}
</label>
<input type="hidden" name="prodToolsHDSubstitution_token" value="{{ app['session'].get('prodToolsHDSubstitution_token') }}">
{% else %}
<input id='new-sd-file' name="newThumb" type="file"/>
<input type="hidden" name="prodToolsThumbSubstitution_token" value="{{ app['session'].get('prodToolsThumbSubstitution_token') }}">
{% endif %}
<input type="hidden" name="subdef" value="{{ substituable|e }}"/>
<input type="hidden" name="sbas_id" value="{{ record.get_sbas_id() }}"/>
<input type="hidden" name="record_id" value="{{ record.get_record_id() }}"/>
<div class="load"></div>
<div class='resultAction'></div>
</div>
</fieldset>
<div style='text-align:right;padding-top:10px;'>
<button class="iframe_submiter btn btn-inverse">{{ "validate" | trans }}</button>
<button class="action_cancel btn btn-inverse">{{ "cancel" | trans }}</button>
<fieldset style='border:1px solid #999;padding:20px;'>
<legend>&nbsp;
<b>{% trans with {'%sd%' : substituable} %}substitution of %sd%{% endtrans %}</b>&nbsp
</legend>
<div>
{% if d %}
<input id='new-hd-file' name="newHD" type="file"/>
<br/>
<label for="CCFNALP" class="checkbox">
<input type="checkbox" name="ccfilename" id="CCFNALP" value="1">
{{ "mettre a jour le nom original de fichier apres substitution" | trans }}
</label>
<input type="hidden" name="prodToolsHDSubstitution_token" value="{{ app['session'].get('prodToolsHDSubstitution_token') }}">
{% else %}
<input id='new-sd-file' name="newThumb" type="file"/>
<input type="hidden" name="prodToolsThumbSubstitution_token" value="{{ app['session'].get('prodToolsThumbSubstitution_token') }}">
{% endif %}
<input type="hidden" name="subdef" value="{{ substituable|e }}"/>
<input type="hidden" name="sbas_id" value="{{ record.get_sbas_id() }}"/>
<input type="hidden" name="record_id" value="{{ record.get_record_id() }}"/>
<div class="load"></div>
<div class='resultAction'></div>
</div>
</form>
</div>
{% endfor %}
{% endif %}
</fieldset>
<div style='text-align:right;padding-top:10px;'>
<button class="iframe_submiter btn btn-inverse">{{ "validate" | trans }}</button>
<button class="action_cancel btn btn-inverse">{{ "cancel" | trans }}</button>
</div>
</form>
</div>
{% endfor %}
</div>
{% endfor %}
{% endif %}
Expand Down
Loading