OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Inject permission checks from controller
Aaron Contrerasb318231c202f
diff --git a/app/components/shares/counter_component.rb b/app/components/shares/counter_component.rbindex 5b22c7fa2b0..9bd01472efb 100644--- a/app/components/shares/counter_component.rb+++ b/app/components/shares/counter_component.rb@@ -33,19 +33,23 @@ module Sharesinclude ApplicationHelperinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpers- include Shares::Concerns::Authorization- def initialize(entity:, count:)+ def initialize(entity:,+ count:,+ sharing_manageable:)super@entity = entity@count = count+ @sharing_manageable = sharing_manageableendprivateattr_reader :entity, :count+ def sharing_manageable? = @sharing_manageable+def shared_with_anyone_else_other_than_myself?Member.of_entity(@entity).where.not(principal: User.current)diff --git a/app/components/shares/invite_user_form_component.html.erb b/app/components/shares/invite_user_form_component.html.erbindex 963065e9b2b..fa52ae08d80 100644--- a/app/components/shares/invite_user_form_component.html.erb+++ b/app/components/shares/invite_user_form_component.html.erb@@ -1,11 +1,11 @@<%=component_wrapper do- if sharing_manageable?+ if @sharing_manageableprimer_form_with(model: new_share,url: url_for([@entity, Member]),data: { controller: 'user-limit ' \- 'work-packages--share--user-selected',+ 'work-packages--share--user-selected','application-target': 'dynamic','user-limit-open-seats-value': OpenProject::Enterprise.open_seats_count,action: 'submit->work-packages--share--user-selected#ensureUsersSelected' }diff --git a/app/components/shares/invite_user_form_component.rb b/app/components/shares/invite_user_form_component.rbindex abaca7db068..48ae8e0715e 100644--- a/app/components/shares/invite_user_form_component.rb+++ b/app/components/shares/invite_user_form_component.rb@@ -31,14 +31,17 @@ module Sharesinclude ApplicationHelperinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpers- include Shares::Concerns::Authorization- def initialize(entity:, available_roles:, errors: nil)+ def initialize(entity:,+ available_roles:,+ sharing_manageable:,+ errors: nil)super@entity = entity- @errors = errors@available_roles = available_roles+ @sharing_manageable = sharing_manageable+ @errors = errorsenddef new_sharediff --git a/app/components/shares/modal_body_component.html.erb b/app/components/shares/modal_body_component.html.erbindex 3e8d3ad558c..2ac2d17c80d 100644--- a/app/components/shares/modal_body_component.html.erb+++ b/app/components/shares/modal_body_component.html.erb@@ -2,7 +2,10 @@component_wrapper(tag: 'turbo-frame') doflex_layout(data: { turbo: true }) do |modal_content|modal_content.with_row do- render(Shares::InviteUserFormComponent.new(entity: @entity, available_roles: @available_roles, errors: @errors))+ render(Shares::InviteUserFormComponent.new(entity: @entity,+ available_roles: @available_roles,+ sharing_manageable: @sharing_manageable,+ errors: @errors))endmodal_content.with_row(mt: 3,@@ -13,7 +16,9 @@border_box.with_header(color: :muted, data: { 'test-selector': 'op-share-wp-header' }) dogrid_layout('op-share-wp-modal-body--header', tag: :div, align_items: :center) do |header_grid|header_grid.with_area(:counter, tag: :div) do- render(Shares::CounterComponent.new(entity: @entity, count: @shares.size))+ render(Shares::CounterComponent.new(entity: @entity,+ count: @shares.size,+ sharing_manageable: @sharing_manageable))endheader_grid.with_area(:actions,@@ -70,7 +75,7 @@tag: :div,hidden: true, # Prevent flicker on initial renderdata: { 'work-packages--share--bulk-selection-target': 'bulkActions' }) do- if sharing_manageable?+ if @sharing_manageableconcat(render(Shares::BulkPermissionButtonComponent.new(entity: @entity, available_roles: @available_roles)))@@ -107,7 +112,10 @@endelse@shares.each do |share|- render(Shares::ShareRowComponent.new(share: share, available_roles: @available_roles, container: border_box))+ render(Shares::ShareRowComponent.new(share: share,+ available_roles: @available_roles,+ sharing_manageable: @sharing_manageable,+ container: border_box))endendenddiff --git a/app/components/shares/modal_body_component.rb b/app/components/shares/modal_body_component.rbindex 72cfc850351..064cdf4efad 100644--- a/app/components/shares/modal_body_component.rb+++ b/app/components/shares/modal_body_component.rb@@ -32,17 +32,25 @@ module Sharesinclude MemberHelperinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpers- include Shares::Concerns::Authorization- attr_reader :entity, :shares, :errors, :available_roles-- def initialize(entity:, shares:, available_roles:, errors: nil)+ attr_reader :entity,+ :shares,+ :available_roles,+ :sharing_manageable,+ :errors++ def initialize(entity:,+ shares:,+ available_roles:,+ sharing_manageable:,+ errors: nil)super@entity = entity@shares = shares- @errors = errors@available_roles = available_roles+ @sharing_manageable = sharing_manageable+ @errors = errorsenddef self.wrapper_keydiff --git a/app/components/shares/share_row_component.rb b/app/components/shares/share_row_component.rbindex bb981e146ef..3c6b094698e 100644--- a/app/components/shares/share_row_component.rb+++ b/app/components/shares/share_row_component.rb@@ -33,10 +33,10 @@ module Sharesinclude ApplicationHelperinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpers- include Shares::Concerns::Authorizationdef initialize(share:,available_roles:,+ sharing_manageable:,container: nil)super@@ -44,6 +44,7 @@ module Shares@entity = share.entity@principal = share.principal@available_roles = available_roles+ @sharing_manageable = sharing_manageable@container = containerend@@ -59,6 +60,8 @@ module Shares@share_editable ||= User.current != share.principal && sharing_manageable?end+ def sharing_manageable? = @sharing_manageable+def grid_css_classesif sharing_manageable?"op-share-wp-modal-body--user-row_manageable"diff --git a/app/components/shares/user_details_component.rb b/app/components/shares/user_details_component.rbindex 0003900998a..8f189f2b6db 100644--- a/app/components/shares/user_details_component.rb+++ b/app/components/shares/user_details_component.rb@@ -34,7 +34,7 @@ module Sharesinclude OpPrimer::ComponentHelpersdef initialize(share:,- manager_mode: User.current.allowed_in_project?(:share_work_packages, share.project),+ manager_mode:,invite_resent: false)superdiff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rbindex 78f6167c8bb..f3a89fab62a 100644--- a/app/controllers/shares_controller.rb+++ b/app/controllers/shares_controller.rb@@ -42,7 +42,12 @@ class SharesController < ApplicationControllerflash.now[:error] = query.errors.full_messagesend- render Shares::ModalBodyComponent.new(entity: @entity, shares: @shares, errors: @errors, available_roles:), layout: nil+ render Shares::ModalBodyComponent.new(entity: @entity,+ shares: @shares,+ errors: @errors,+ sharing_manageable: User.current.allowed_in_project?(:share_work_packages,+ @entity.project),+ available_roles:), layout: nilenddef create@@ -132,8 +137,8 @@ class SharesController < ApplicationControllerdef destroy_share(share)Shares::DeleteService- .new(user: current_user, model: share, contract_class: sharing_contract_scope::DeleteContract)- .call+ .new(user: current_user, model: share, contract_class: sharing_contract_scope::DeleteContract)+ .callenddef create_or_update_share(user_id, role_ids)@@ -151,6 +156,8 @@ class SharesController < ApplicationControllercomponent: Shares::ModalBodyComponent.new(entity: @entity,available_roles:,shares: @new_shares || load_shares,+ sharing_manageable: User.current.allowed_in_project?(:share_work_packages,+ @project),errors: @errors))@@ -159,18 +166,31 @@ class SharesController < ApplicationControllerdef respond_with_prepend_sharesreplace_via_turbo_stream(- component: Shares::InviteUserFormComponent.new(entity: @entity, available_roles:, errors: @errors)+ component: Shares::InviteUserFormComponent.new(entity: @entity,+ available_roles:,+ sharing_manageable: User.current.allowed_in_project?(:share_work_packages,+ @project),+ errors: @errors))update_via_turbo_stream(- component: Shares::CounterComponent.new(entity: @entity, count: current_visible_member_count)+ component: Shares::CounterComponent.new(entity: @entity,+ count: current_visible_member_count,+ sharing_manageable: User.current.allowed_in_project?(:share_work_packages,+ @project)))@new_shares.each do |share|prepend_via_turbo_stream(- component: Shares::ShareRowComponent.new(share:, available_roles:),+ component: Shares::ShareRowComponent.new(share:,+ available_roles:,+ sharing_manageable: User.current.allowed_in_project?(:share_work_packages,+ @project)),target_component: Shares::ModalBodyComponent.new(entity: @entity,available_roles:,+ sharing_manageable: User.current.allowed_in_project?(+ :share_work_packages, @project+ ),shares: load_shares,errors: @errors))@@ -182,6 +202,9 @@ class SharesController < ApplicationControllerdef respond_with_new_invite_formreplace_via_turbo_stream(component: Shares::InviteUserFormComponent.new(entity: @entity,available_roles:,+ sharing_manageable: User.current.allowed_in_project?(+ :share_work_packages, @project+ ),errors: @errors))respond_with_turbo_streams@@ -196,14 +219,26 @@ class SharesController < ApplicationControllerenddef respond_with_remove_share- remove_via_turbo_stream(component: Shares::ShareRowComponent.new(share: @share, available_roles:))- update_via_turbo_stream(component: Shares::CounterComponent.new(entity: @entity, count: current_visible_member_count))+ remove_via_turbo_stream(component: Shares::ShareRowComponent.new(share: @share,+ available_roles:,+ sharing_manageable: User.current.allowed_in_project?(+ :share_work_packages, @project+ )))+ update_via_turbo_stream(component: Shares::CounterComponent.new(entity: @entity,+ count: current_visible_member_count,+ sharing_manageable: User.current.allowed_in_project?(+ :share_work_packages, @project+ )))respond_with_turbo_streamsenddef respond_with_update_user_details- update_via_turbo_stream(component: Shares::UserDetailsComponent.new(share: @share, invite_resent: true))+ update_via_turbo_stream(component: Shares::UserDetailsComponent.new(share: @share,+ manager_mode: User.current.allowed_in_project?(+ :share_work_packages, @entity.project+ ),+ invite_resent: true))respond_with_turbo_streamsend@@ -223,12 +258,18 @@ class SharesController < ApplicationControllerdef respond_with_bulk_removed_shares@selected_shares.each do |share|remove_via_turbo_stream(- component: Shares::ShareRowComponent.new(share:, available_roles:)+ component: Shares::ShareRowComponent.new(share:,+ available_roles:,+ sharing_manageable: User.current.allowed_in_project?(:share_work_packages,+ @project)))endupdate_via_turbo_stream(- component: Shares::CounterComponent.new(entity: @entity, count: current_visible_member_count)+ component: Shares::CounterComponent.new(entity: @entity,+ count: current_visible_member_count,+ sharing_manageable: User.current.allowed_in_project?(:share_work_packages,+ @project)))respond_with_turbo_streams@@ -237,7 +278,7 @@ class SharesController < ApplicationControllerdef load_entity@entity = if params["work_package_id"]WorkPackage.visible.find(params["work_package_id"])- # TODO: Add support for other entities+ # TODO: Add support for other entitieselseraise ArgumentError, <<~ERRORNested the SharesController under an entity controller that is not yet configured to support sharing.