Skip to content

Commit

Permalink
EZP-29311: Implement permissions for Change main Location in Location…
Browse files Browse the repository at this point in the history
…s tab
  • Loading branch information
mikadamczyk committed Jun 19, 2018
1 parent 7969d63 commit d62ca41
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
42 changes: 31 additions & 11 deletions src/bundle/Resources/views/content/tab/locations/tab.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

<section>
{{ form(form_content_location_add, {'action': path('ezplatform.location.add')}) }}
{% include '@ezdesign/parts/table_header.html.twig' with { headerText: 'tab.locations.content_locations'|trans()|desc('Content locations'), tools: tab.table_header_tools(form_content_location_add, form_content_location_remove) } %}
{% include '@ezdesign/parts/table_header.html.twig' with {
headerText: 'tab.locations.content_locations'|trans()|desc('Content locations'),
tools: tab.table_header_tools(form_content_location_add, form_content_location_remove)
} %}
{{ form_start(form_content_location_remove, {
'action': path('ezplatform.location.remove'),
'attr': { 'class': 'ez-toggle-btn-state', 'data-toggle-button-id': '#delete-locations' }
Expand Down Expand Up @@ -42,13 +45,23 @@
<svg class="ez-icon ez-icon-view-hide">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#view-hide"></use>
</svg>
<input class="ez-checkbox-icon__checkbox" {{ not location.hidden ? 'checked' }} type="checkbox" name="updateVisibility" value="{{ location.id }}">
<input
class="ez-checkbox-icon__checkbox"
{{ not location.hidden ? 'checked' }}
type="checkbox"
name="updateVisibility"
value="{{ location.id }}">
</label>
{% endif %}
</td>
<td class="align-middle"></td>
<td class="align-middle">
<input {{ location.main ? 'checked' }} type="radio" name="updateMainLocation" value="{{ location.id }}">
<input
type="radio"
{{ location.main ? 'checked' }}
{{ not location.canEdit ? 'disabled' }}
name="updateMainLocation"
value="{{ location.id }}">
</td>
</tr>
{% endfor %}
Expand All @@ -64,20 +77,27 @@

{% include '@ezdesign/content/tab/locations/panel_swap.html.twig' with {'form': form_content_location_swap} %}

{% macro table_header_tools(form_add, form_remove) %}
<button data-udw-config="{{ ez_udw_config('single', {}) }}" class="btn btn-primary btn--udw-add" title="{{ 'tab.locations.action.add'|trans|desc('Add Location') }}">
{% macro table_header_tools(form_add, form_remove, can_add) %}
<button
data-udw-config="{{ ez_udw_config('single', {}) }}"
class="btn btn-primary btn--udw-add"
title="{{ 'tab.locations.action.add'|trans|desc('Add Location') }}">
<svg class="ez-icon ez-icon-create">
<use xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#create"></use>
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#create"></use>
</svg>
</button>

{% set modal_data_target = 'delete-content-types-modal' %}
<button id="delete-locations" type="button" class="btn btn-danger" disabled data-toggle="modal"
data-target="#{{ modal_data_target }}" title="{{ 'tab.locations.action.delete'|trans|desc('Delete Location') }}">
<button
id="delete-locations"
type="button"
class="btn btn-danger"
disabled
data-toggle="modal"
data-target="#{{ modal_data_target }}"
title="{{ 'tab.locations.action.delete'|trans|desc('Delete Location') }}">
<svg class="ez-icon ez-icon-trash">
<use xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#trash"></use>
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#trash"></use>
</svg>
</button>
{% include '@ezdesign/bulk_delete_confirmation_modal.html.twig' with {
Expand Down
17 changes: 17 additions & 0 deletions src/lib/UI/Value/Content/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class Location extends CoreLocation
*/
protected $userCanRemove;

/**
* User can edit.
*
* @var bool
*/
protected $userCanEdit;

/**
* @param APILocation $location
* @param array $properties
Expand All @@ -70,4 +77,14 @@ public function canDelete(): bool
{
return !$this->main && $this->userCanManage && $this->userCanRemove;
}

/**
* Can edit location.
*
* @return bool
*/
public function canEdit(): bool
{
return $this->userCanEdit;
}
}
3 changes: 3 additions & 0 deletions src/lib/UI/Value/ValueFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ public function createLocation(Location $location): UIValue\Content\Location
'userCanRemove' => $this->permissionResolver->canUser(
'content', 'remove', $location->getContentInfo(), [$location]
),
'userCanEdit' => $this->permissionResolver->canUser(
'content', 'edit', $location->getContentInfo(), [$location]
),
'main' => $location->getContentInfo()->mainLocationId === $location->id,
]);
}
Expand Down

0 comments on commit d62ca41

Please sign in to comment.