Skip to content

Commit d482e17

Browse files
authored
Merge pull request #3132 from DMPRoadmap/dcc_bug_710-Error_using_unassign_users_from_a_Department_using_API_V0
DCC BUG #710 - Fix for "Error using unassign_users from a Department …
2 parents 3e2e2e7 + f08aeb6 commit d482e17

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

app/controllers/api/v0/departments_controller.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,24 @@ def assign_users
4747
raise Pundit::NotAuthorizedError unless Api::V0::DepartmentsPolicy.new(@user, @department).assign_users?
4848

4949
assign_users_to(@department.id)
50-
redirect_to users_api_v0_departments_path
50+
51+
# Added "status: :see_other" to redirect_to (as we require rediect to be a GET).
52+
# See https://makandracards.com/makandra/38347-redirecting-responses-for-patch-or-delete-will-not-redirect-with-get
53+
redirect_to users_api_v0_departments_path, status: :see_other
5154
end
5255

5356
##
5457
# Remove departments from the list of users
5558
def unassign_users
56-
raise Pudndit::NotAuthorizedError unless Api::V0::DepartmentsPolicy.new(@user, @department).assign_users?
59+
@department = Department.find(params[:id])
60+
61+
raise Pundit::NotAuthorizedError unless Api::V0::DepartmentsPolicy.new(@user, @department).assign_users?
5762

5863
assign_users_to(nil)
59-
redirect_to users_api_v0_departments_path
64+
65+
# Added "status: :see_other" to redirect_to (as we require rediect to be a GET).
66+
# See https://makandracards.com/makandra/38347-redirecting-responses-for-patch-or-delete-will-not-redirect-with-get
67+
redirect_to users_api_v0_departments_path, status: :see_other
6068
end
6169

6270
private

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@
162162
resources :departments, only: %i[create index] do
163163
collection do
164164
get :users
165-
patch :unassign_users
166165
end
167166
member do
167+
patch :unassign_users
168168
patch :assign_users
169169
end
170170
end

0 commit comments

Comments
 (0)