Skip to content
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
14 changes: 11 additions & 3 deletions app/controllers/api/v0/departments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,24 @@ def assign_users
raise Pundit::NotAuthorizedError unless Api::V0::DepartmentsPolicy.new(@user, @department).assign_users?

assign_users_to(@department.id)
redirect_to users_api_v0_departments_path

# Added "status: :see_other" to redirect_to (as we require rediect to be a GET).
# See https://makandracards.com/makandra/38347-redirecting-responses-for-patch-or-delete-will-not-redirect-with-get
redirect_to users_api_v0_departments_path, status: :see_other
end

##
# Remove departments from the list of users
def unassign_users
raise Pudndit::NotAuthorizedError unless Api::V0::DepartmentsPolicy.new(@user, @department).assign_users?
@department = Department.find(params[:id])

raise Pundit::NotAuthorizedError unless Api::V0::DepartmentsPolicy.new(@user, @department).assign_users?

assign_users_to(nil)
redirect_to users_api_v0_departments_path

# Added "status: :see_other" to redirect_to (as we require rediect to be a GET).
# See https://makandracards.com/makandra/38347-redirecting-responses-for-patch-or-delete-will-not-redirect-with-get
redirect_to users_api_v0_departments_path, status: :see_other
end

private
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@
resources :departments, only: %i[create index] do
collection do
get :users
patch :unassign_users
end
member do
patch :unassign_users
patch :assign_users
end
end
Expand Down