Commit deb809c4 authored by Dmytro Zaporozhets (DZ)'s avatar Dmytro Zaporozhets (DZ)

Merge branch 'peterhegman/update-group-members-json' into 'master'

Update group members JSON

See merge request gitlab-org/gitlab!42416
parents a20a8552 ff19f8cf
......@@ -14,7 +14,7 @@ module Groups::GroupMembersHelper
end
def linked_groups_data_json(group_links)
GroupGroupLinkSerializer.new.represent(group_links).to_json
GroupGroupLinkSerializer.new.represent(group_links, { current_user: current_user }).to_json
end
def members_data_json(group, members)
......@@ -47,10 +47,10 @@ module Groups::GroupMembersHelper
}
}.merge(member_created_by_data(member.created_by))
if user.present?
data[:user] = member_user_data(user)
else
if member.invite?
data[:invite] = member_invite_data(member)
elsif user.present?
data[:user] = member_user_data(user)
end
data
......@@ -77,6 +77,17 @@ module Groups::GroupMembersHelper
avatar_url: avatar_icon_for_user(user, AVATAR_SIZE),
blocked: user.blocked?,
two_factor_enabled: user.two_factor_enabled?
}.merge(member_user_status_data(user.status))
end
def member_user_status_data(status)
return {} unless status.present?
{
status: {
emoji: status.emoji,
message_html: status.message_html
}
}
end
......
# frozen_string_literal: true
class GroupGroupLinkEntity < Grape::Entity
include RequestAwareEntity
expose :id
expose :created_at
expose :expires_at do |group_link|
group_link.expires_at&.to_time
end
expose :can_update do |group_link|
can_manage?(group_link)
end
expose :can_remove do |group_link|
can_manage?(group_link)
end
expose :access_level do
expose :human_access, as: :string_value
expose :group_access, as: :integer_value
......@@ -23,4 +33,14 @@ class GroupGroupLinkEntity < Grape::Entity
expose :shared_with_group, merge: true, using: GroupBasicEntity
end
private
def current_user
options[:current_user]
end
def can_manage?(group_link)
can?(current_user, :admin_group_member, group_link.shared_group)
end
end
{
"type": "object",
"required": ["id", "created_at", "expires_at", "access_level"],
"required": ["id", "created_at", "expires_at", "can_update", "can_remove", "access_level"],
"properties": {
"id": { "type": "integer" },
"created_at": { "type": "date-time" },
"expires_at": { "type": ["date-time", "null"] },
"can_update": { "type": "boolean" },
"can_remove": { "type": "boolean" },
"access_level": {
"type": "object",
"required": ["integer_value", "string_value"],
......
......@@ -62,7 +62,18 @@
"avatar_url": { "type": ["string", "null"] },
"web_url": { "type": "string" },
"blocked": { "type": "boolean" },
"two_factor_enabled": { "type": "boolean" }
"two_factor_enabled": { "type": "boolean" },
"status": {
"type": "object",
"required": [
"emoji",
"message_html"
],
"properties": {
"emoji": { "type": "string" },
"message_html": { "type": "string" }
}
}
}
},
"invite": {
......
......@@ -5,6 +5,8 @@ require "spec_helper"
RSpec.describe Groups::GroupMembersHelper do
include MembersPresentation
let_it_be(:current_user) { create(:user) }
describe '.group_member_select_options' do
let(:group) { create(:group) }
......@@ -20,6 +22,10 @@ RSpec.describe Groups::GroupMembersHelper do
describe '#linked_groups_data_json' do
include_context 'group_group_link'
before do
allow(helper).to receive(:current_user).and_return(current_user)
end
it 'matches json schema' do
json = helper.linked_groups_data_json(shared_group.shared_with_group_links)
......@@ -28,7 +34,6 @@ RSpec.describe Groups::GroupMembersHelper do
end
describe '#members_data_json' do
let(:current_user) { create(:user) }
let(:group) { create(:group) }
before do
......@@ -48,6 +53,14 @@ RSpec.describe Groups::GroupMembersHelper do
let(:group_member) { create(:group_member, group: group, created_by: current_user) }
it_behaves_like 'group_members.json'
context 'with user status set' do
let(:user) { create(:user) }
let!(:status) { create(:user_status, user: user) }
let(:group_member) { create(:group_member, group: group, user: user, created_by: current_user) }
it_behaves_like 'group_members.json'
end
end
context 'for an invited group member' do
......
......@@ -5,9 +5,27 @@ require 'spec_helper'
RSpec.describe GroupGroupLinkEntity do
include_context 'group_group_link'
subject(:json) { described_class.new(group_group_link).to_json }
let_it_be(:current_user) { create(:user) }
let(:entity) { described_class.new(group_group_link) }
before do
allow(entity).to receive(:current_user).and_return(current_user)
end
it 'matches json schema' do
expect(json).to match_schema('entities/group_group_link')
expect(entity.to_json).to match_schema('entities/group_group_link')
end
context 'a user with :admin_group_member permissions' do
before do
allow(entity).to receive(:can?).with(current_user, :admin_group_member, shared_group).and_return(true)
end
it 'sets `can_update` and `can_remove` to `true`' do
json = entity.as_json
expect(json[:can_update]).to be true
expect(json[:can_remove]).to be true
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