diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 376607973..212b23aca 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -28,7 +28,11 @@ class RepositoriesController < ApplicationController render 'repositories/index' end - def show; end + def show + @display_edit_button = can_create_repository_rows?(@repository) + @display_delete_button = can_delete_repository_rows?(@repository) + @display_duplicate_button = can_create_repository_rows?(@repository) + end def create_modal @repository = Repository.new diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index 6c6dc6944..ffab95602 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -12,8 +12,9 @@ class RepositoryRowsController < ApplicationController copy_records available_rows) before_action :check_create_permissions, only: :create + before_action :check_delete_permissions, only: :delete_records before_action :check_manage_permissions, - only: %i(edit update delete_records copy_records) + only: %i(edit update copy_records) def index @draw = params[:draw].to_i @@ -372,6 +373,10 @@ class RepositoryRowsController < ApplicationController render_403 unless can_manage_repository_rows?(@repository) end + def check_delete_permissions + render_403 unless can_delete_repository_rows?(@repository) + end + def record_params params.permit(:repository_row_name).to_h end diff --git a/app/permissions/repository.rb b/app/permissions/repository.rb index 05e018c89..47b78d9c8 100644 --- a/app/permissions/repository.rb +++ b/app/permissions/repository.rb @@ -30,6 +30,14 @@ Canaid::Permissions.register_for(Repository) do can_create_repository_rows?(user, repository) end + can :update_repository_rows do |user, repository| + can_manage_repository_rows?(user, repository) + end + + can :delete_repository_rows do |user, repository| + can_manage_repository_rows?(user, repository) + end + # repository: create field can :create_repository_columns do |user, repository| can_create_repository_rows?(user, repository) unless repository.shared_with?(user.current_team) diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index ef664aeb2..6a931cd9b 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -128,21 +128,29 @@ <% end %> <% if can_manage_repository_rows?(@repository) %> - - - + + <%if @display_edit_button %> + + <% end %> + + <%if @display_delete_button %> + + <% end %> + + <%if @display_duplicate_button %> + + <%end%> <% elsif @repository.shared_with?(current_team) %>

<%= t('repositories.index.view_only_permission_label') %>

<% end %>