diff --git a/app/controllers/storage_location_repository_rows_controller.rb b/app/controllers/storage_location_repository_rows_controller.rb index 2f7309611..8aa723387 100644 --- a/app/controllers/storage_location_repository_rows_controller.rb +++ b/app/controllers/storage_location_repository_rows_controller.rb @@ -123,7 +123,7 @@ class StorageLocationRepositoryRowsController < ApplicationController end 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 def log_activity(type_of, message_items = {}) diff --git a/app/controllers/storage_locations_controller.rb b/app/controllers/storage_locations_controller.rb index 5c9dc9a62..965d766a0 100644 --- a/app/controllers/storage_locations_controller.rb +++ b/app/controllers/storage_locations_controller.rb @@ -197,6 +197,7 @@ class StorageLocationsController < ApplicationController def load_storage_location @storage_location = StorageLocation.find(storage_location_params[:id]) + @parent_location = @storage_location.parent render_404 unless can_read_storage_location?(@storage_location) end @@ -205,6 +206,8 @@ class StorageLocationsController < ApplicationController end def check_create_permissions + render_403 if @parent_location && !can_manage_storage_location?(@parent_location.team) + if storage_location_params[:container] render_403 unless can_create_storage_location_containers?(current_team) else diff --git a/app/javascript/vue/storage_locations/modals/move_tree.vue b/app/javascript/vue/storage_locations/modals/move_tree.vue index 7972a8b41..dfc872ec7 100644 --- a/app/javascript/vue/storage_locations/modals/move_tree.vue +++ b/app/javascript/vue/storage_locations/modals/move_tree.vue @@ -58,7 +58,7 @@ export default { } }, 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; } } }; diff --git a/app/javascript/vue/storage_locations/table.vue b/app/javascript/vue/storage_locations/table.vue index 34fb86c42..e13803ff0 100644 --- a/app/javascript/vue/storage_locations/table.vue +++ b/app/javascript/vue/storage_locations/table.vue @@ -91,7 +91,11 @@ export default { }, directUploadUrl: { type: String - } + }, + canCreateLocation: Boolean, + canCreateContainer: Boolean, + canManageParent: Boolean, + hasParent: Boolean }, data() { return { @@ -161,7 +165,7 @@ export default { }, toolbarActions() { const left = []; - if (this.createLocationUrl) { + if (this.canCreateLocation && (this.canManageParent || !this.hasParent)) { left.push({ name: 'create_location', 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({ name: 'create_container', icon: 'sn-icon sn-icon-item', diff --git a/app/permissions/storage_location.rb b/app/permissions/storage_location.rb index 58128d9cf..ec2595db4 100644 --- a/app/permissions/storage_location.rb +++ b/app/permissions/storage_location.rb @@ -31,6 +31,10 @@ Canaid::Permissions.register_for(StorageLocation) do ) 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| user.current_team == storage_location.team && storage_location.root? && diff --git a/app/views/storage_locations/index.html.erb b/app/views/storage_locations/index.html.erb index a87d4abfd..110898cbf 100644 --- a/app/views/storage_locations/index.html.erb +++ b/app/views/storage_locations/index.html.erb @@ -12,10 +12,14 @@