Commit 3900a7e2 authored by Vijay Hawoldar's avatar Vijay Hawoldar

Expose a `removable` attribute for BillableMembers

When returning BillableMember entities, the frontend will need
to know if each one is removable or not
parent 97f0109c
...@@ -289,7 +289,8 @@ Example response: ...@@ -289,7 +289,8 @@ Example response:
"avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon", "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",
"web_url": "http://192.168.1.8:3000/root", "web_url": "http://192.168.1.8:3000/root",
"last_activity_on": "2021-01-27", "last_activity_on": "2021-01-27",
"membership_type": "group_member" "membership_type": "group_member",
"removable": true
}, },
{ {
"id": 2, "id": 2,
...@@ -300,7 +301,8 @@ Example response: ...@@ -300,7 +301,8 @@ Example response:
"web_url": "http://192.168.1.8:3000/root", "web_url": "http://192.168.1.8:3000/root",
"email": "john@example.com", "email": "john@example.com",
"last_activity_on": "2021-01-25", "last_activity_on": "2021-01-25",
"membership_type": "group_member" "membership_type": "group_member",
"removable": true
}, },
{ {
"id": 3, "id": 3,
...@@ -310,7 +312,8 @@ Example response: ...@@ -310,7 +312,8 @@ Example response:
"avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon", "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",
"web_url": "http://192.168.1.8:3000/root", "web_url": "http://192.168.1.8:3000/root",
"last_activity_on": "2021-01-20", "last_activity_on": "2021-01-20",
"membership_type": "group_invite" "membership_type": "group_invite",
"removable": false
} }
] ]
``` ```
......
---
title: Expose whether a BillableMember is removable
merge_request: 61566
author:
type: changed
...@@ -7,6 +7,7 @@ module EE ...@@ -7,6 +7,7 @@ module EE
expose :public_email, as: :email expose :public_email, as: :email
expose :last_activity_on expose :last_activity_on
expose :membership_type expose :membership_type
expose :removable
private private
...@@ -17,6 +18,10 @@ module EE ...@@ -17,6 +18,10 @@ module EE
return 'project_invite' if user_in_array?(:shared_project_user_ids) return 'project_invite' if user_in_array?(:shared_project_user_ids)
end end
def removable
user_in_array?(:group_member_user_ids) || user_in_array?(:project_member_user_ids)
end
def user_in_array?(name) def user_in_array?(name)
options.fetch(name, []).include?(object.id) options.fetch(name, []).include?(object.id)
end end
......
...@@ -47,18 +47,22 @@ RSpec.describe ::EE::API::Entities::BillableMember do ...@@ -47,18 +47,22 @@ RSpec.describe ::EE::API::Entities::BillableMember do
context 'with different group membership types' do context 'with different group membership types' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
where(:user_ids, :expected_value) do where(:user_ids, :membership_type, :removable) do
:group_member_user_ids | 'group_member' :group_member_user_ids | 'group_member' | true
:project_member_user_ids | 'project_member' :project_member_user_ids | 'project_member' | true
:shared_group_user_ids | 'group_invite' :shared_group_user_ids | 'group_invite' | false
:shared_project_user_ids | 'project_invite' :shared_project_user_ids | 'project_invite' | false
end end
with_them do with_them do
let(:options) { super().merge(user_ids => [member.id]) } let(:options) { super().merge(user_ids => [member.id]) }
it 'returns the expected value' do it 'returns the expected membership_type value' do
expect(entity_representation[:membership_type]).to eq expected_value expect(entity_representation[:membership_type]).to eq membership_type
end
it 'returns the expected removable value' do
expect(entity_representation[:removable]).to eq removable
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment