Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the user to list and see themselves even without rbac_user_show #1230

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions app/controllers/api/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@ class UsersController < BaseController
include Subcollections::CustomButtonEvents
include Subcollections::Tags

skip_before_action :validate_api_action, :only => :update
skip_before_action :validate_api_action, :only => [:index, :show, :update]

def index # rubocop:disable Lint/UselessMethodDefinition
# Rails style guide and Rubocop suggest this method to be lexically redefined since we are skipping validate_api_action
# See https://rails.rubystyle.guide/#lexically-scoped-action-filter
# https://docs.rubocop.org/rubocop-rails/cops_rails.html#railslexicallyscopedactionfilter
super
end

def show
validate_api_action unless target_is_api_user?
super
end

def update
aname = @req.action
if aname == "edit" && !api_user_role_allows?(aname) && update_target_is_api_user?
if aname == "edit" && !api_user_role_allows?(aname) && target_is_api_user?
if (Array(@req.resource.try(:keys)) - EDITABLE_ATTRS).present?
raise BadRequestError,
"Cannot update attributes other than #{EDITABLE_ATTRS.join(', ')} for the authenticated user"
Expand Down Expand Up @@ -90,7 +102,7 @@ def target_user(id, type)
end
end

def update_target_is_api_user?
def target_is_api_user?
User.current_user.id == @req.collection_id.to_i
end

Expand Down
16 changes: 12 additions & 4 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4562,7 +4562,9 @@
:identifier: tp_delete
:users:
:description: Users
:identifier: rbac_user
:identifier:
- rbac_user
- my_settings_view
:options:
- :collection
- :custom_actions
Expand All @@ -4575,10 +4577,14 @@
:collection_actions:
:get:
- :name: read
:identifier: rbac_user_show_list
:identifier:
- rbac_user_show_list
- my_settings_view
:post:
- :name: query
:identifier: rbac_user_show_list
:identifier:
- rbac_user_show_list
- my_settings_view
- :name: create
:identifier: rbac_user_add
- :name: edit
Expand All @@ -4593,7 +4599,9 @@
:resource_actions:
:get:
- :name: read
:identifier: rbac_user_show
:identifier:
- rbac_user_show
- my_settings_view
:post:
- :name: edit
:identifier: rbac_user_edit
Expand Down
Loading