update permissions for shared locations [SCI-11118]

This commit is contained in:
Anton 2024-10-01 11:55:44 +02:00
parent 85f0b28e6d
commit 14dea69717
7 changed files with 23 additions and 8 deletions

View file

@ -123,7 +123,7 @@ class StorageLocationRepositoryRowsController < ApplicationController
end end
def check_manage_permissions def check_manage_permissions
render_403 unless can_manage_storage_location?(@storage_location) render_403 unless can_create_storage_location_repository_rows?(@storage_location)
end end
def log_activity(type_of, message_items = {}) def log_activity(type_of, message_items = {})

View file

@ -197,6 +197,7 @@ class StorageLocationsController < ApplicationController
def load_storage_location def load_storage_location
@storage_location = StorageLocation.find(storage_location_params[:id]) @storage_location = StorageLocation.find(storage_location_params[:id])
@parent_location = @storage_location.parent
render_404 unless can_read_storage_location?(@storage_location) render_404 unless can_read_storage_location?(@storage_location)
end end
@ -205,6 +206,8 @@ class StorageLocationsController < ApplicationController
end end
def check_create_permissions def check_create_permissions
render_403 if @parent_location && !can_manage_storage_location?(@parent_location.team)
if storage_location_params[:container] if storage_location_params[:container]
render_403 unless can_create_storage_location_containers?(current_team) render_403 unless can_create_storage_location_containers?(current_team)
else else

View file

@ -58,7 +58,7 @@ export default {
} }
}, },
managePermission(loc) { managePermission(loc) {
return loc.storage_location.parent_id ? this.canManage : loc.can_manage; return (loc.storage_location.parent_id ? this.canManage : loc.can_manage) || loc.storage_location.container;
} }
} }
}; };

View file

@ -91,7 +91,11 @@ export default {
}, },
directUploadUrl: { directUploadUrl: {
type: String type: String
} },
canCreateLocation: Boolean,
canCreateContainer: Boolean,
canManageParent: Boolean,
hasParent: Boolean
}, },
data() { data() {
return { return {
@ -161,7 +165,7 @@ export default {
}, },
toolbarActions() { toolbarActions() {
const left = []; const left = [];
if (this.createLocationUrl) { if (this.canCreateLocation && (this.canManageParent || !this.hasParent)) {
left.push({ left.push({
name: 'create_location', name: 'create_location',
icon: 'sn-icon sn-icon-new-task', icon: 'sn-icon sn-icon-new-task',
@ -172,7 +176,7 @@ export default {
}); });
} }
if (this.createLocationInstanceUrl) { if (this.canCreateContainer && (this.canManageParent || !this.hasParent)) {
left.push({ left.push({
name: 'create_container', name: 'create_container',
icon: 'sn-icon sn-icon-item', icon: 'sn-icon sn-icon-item',

View file

@ -31,6 +31,10 @@ Canaid::Permissions.register_for(StorageLocation) do
) )
end end
can :create_storage_location_repository_rows do |user, storage_location|
can_read_storage_location?(user, storage_location)
end
can :share_storage_location do |user, storage_location| can :share_storage_location do |user, storage_location|
user.current_team == storage_location.team && user.current_team == storage_location.team &&
storage_location.root? && storage_location.root? &&

View file

@ -12,10 +12,14 @@
<div id="storageLocationsTable" class="fixed-content-body"> <div id="storageLocationsTable" class="fixed-content-body">
<storage-locations <storage-locations
actions-url="<%= actions_toolbar_storage_locations_path(current_team) %>" actions-url="<%= actions_toolbar_storage_locations_path(current_team) %>"
:can-create-location="<%= can_create_storage_locations?(current_team) %>"
:can-create-container="<%= can_create_storage_location_containers?(current_team) %>"
:can-manage-parent="<%= can_manage_storage_location?(@parent_location) if @parent_location %>"
:has-parent="<%= @parent_location.present? %>"
data-source="<%= storage_locations_path(format: :json, parent_id: params[:parent_id]) %>" data-source="<%= storage_locations_path(format: :json, parent_id: params[:parent_id]) %>"
direct-upload-url="<%= rails_direct_uploads_url %>" direct-upload-url="<%= rails_direct_uploads_url %>"
create-location-url="<%= storage_locations_path(parent_id: params[:parent_id]) if can_create_storage_locations?(current_team) %>" create-location-url="<%= storage_locations_path(parent_id: params[:parent_id]) %>"
create-location-instance-url="<%= storage_locations_path(parent_id: params[:parent_id]) if can_create_storage_location_containers?(current_team) %>" create-location-instance-url="<%= storage_locations_path(parent_id: params[:parent_id]) %>"
/> />
</div> </div>
</div> </div>

View file

@ -14,7 +14,7 @@
ref="container" ref="container"
actions-url="<%= actions_toolbar_storage_location_storage_location_repository_rows_path(@storage_location) %>" actions-url="<%= actions_toolbar_storage_location_storage_location_repository_rows_path(@storage_location) %>"
data-source="<%= storage_location_storage_location_repository_rows_path(@storage_location) %>" data-source="<%= storage_location_storage_location_repository_rows_path(@storage_location) %>"
:can-manage="<%= can_manage_storage_location?(@storage_location) %>" :can-manage="<%= can_create_storage_location_repository_rows?(@storage_location) %>"
:with-grid="<%= @storage_location.with_grid? %>" :with-grid="<%= @storage_location.with_grid? %>"
:grid-size="<%= @storage_location.grid_size.to_json %>" :grid-size="<%= @storage_location.grid_size.to_json %>"
:container-id="<%= @storage_location.id %>" :container-id="<%= @storage_location.id %>"