Skip to content

Commit

Permalink
allow updating of membership roles via memberships controller (#4335)
Browse files Browse the repository at this point in the history
* allow updating of membership roles

* update spacing and " to ' found by hound sniffs
  • Loading branch information
yuenmichelle1 authored May 20, 2024
1 parent 2bc2583 commit 7375ca8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/memberships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Api::V1::MembershipsController < Api::ApiController
resource_actions :index, :show, :create, :update, :deactivate
schema_type :strong_params

allowed_params :update, :state
allowed_params :update, :state, roles: []

def create
resources = resource_class.transaction(requires_new: true) do
Expand Down
17 changes: 17 additions & 0 deletions spec/controllers/api/v1/memberships_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@
end

it_behaves_like "is updatable"

context 'when updating roles as group_admin' do
let(:other_user) { create(:user) }
let(:other_user_group) { create(:user_group, admin: authorized_user, private: true) }
let(:other_user_membership) { create(:membership, user: other_user, user_group: other_user_group, roles: ['group_member']) }

it 'allows update of membership roles' do
default_request user_id: authorized_user.id, scopes: scopes
params = {
memberships: { roles: ['group_admin'] },
id: other_user_membership.id
}

put :update, params: params
expect(other_user_membership.reload.roles).to eq(['group_admin'])
end
end
end

describe "#create" do
Expand Down

0 comments on commit 7375ca8

Please sign in to comment.