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 updating of membership roles via memberships controller #4335

Merged
merged 2 commits into from
May 20, 2024
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
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
Loading