Commit c945674a authored by Magdalena Frankiewicz's avatar Magdalena Frankiewicz

Expose is_gitlab_employee depending on the flag

Expose the field only if the gitlab_employee_badge
flag is on and we are on gitlab.com
parent 5b7f4098
......@@ -5,7 +5,7 @@ module EE
extend ActiveSupport::Concern
prepended do
expose :gitlab_employee?, as: :is_gitlab_employee
expose :gitlab_employee?, as: :is_gitlab_employee, if: proc { ::Gitlab.com? && ::Feature.enabled?(:gitlab_employee_badge) }
end
end
end
......@@ -7,7 +7,7 @@ module EE
extend ActiveSupport::Concern
prepended do
expose :gitlab_employee?, as: :is_gitlab_employee
expose :gitlab_employee?, as: :is_gitlab_employee, if: proc { ::Gitlab.com? && ::Feature.enabled?(:gitlab_employee_badge) }
end
end
end
......
......@@ -7,7 +7,7 @@ module EE
extend ActiveSupport::Concern
prepended do
expose :gitlab_employee?, as: :is_gitlab_employee
expose :gitlab_employee?, as: :is_gitlab_employee, if: proc { ::Gitlab.com? && ::Feature.enabled?(:gitlab_employee_badge) }
end
end
end
......
......@@ -276,7 +276,7 @@ describe Projects::IssuesController do
note_json = json_response.first['notes'].first
expect(note_json['author']['is_gitlab_employee']).to be false
expect(note_json['author'].has_key?('is_gitlab_employee')).to be false
end
end
......@@ -303,7 +303,13 @@ describe Projects::IssuesController do
context 'when user is not a gitlab employee' do
let(:email) { 'test@example.com' }
it_behaves_like 'non inclusion of gitlab employee badge'
it 'shows is_gitlab_employee attribute as false' do
subject
note_json = json_response.first['notes'].first
expect(note_json['author']['is_gitlab_employee']).to be false
end
context 'when feature flag is disabled' do
before do
......@@ -333,15 +339,46 @@ describe Projects::IssuesController do
end
context 'changing the assignee' do
it 'limits the attributes exposed on the assignee' do
assignee = create(:user)
let(:assignee) { create(:user) }
before do
project.add_developer(assignee)
sign_in(assignee)
end
context 'when the gitlab_employee_badge flag is off' do
it 'does not expose the is_gitlab_employee attribute on the assignee' do
stub_feature_flags(gitlab_employee_badge: false)
update_issue(issue_params: { assignee_ids: [assignee.id] })
update_issue(issue_params: { assignee_ids: [assignee.id] })
expect(json_response['assignees'].first.keys)
.to match_array(%w(id name username avatar_url state web_url is_gitlab_employee))
expect(json_response['assignees'].first.keys)
.to match_array(%w(id name username avatar_url state web_url))
end
end
context 'when the gitlab_employee_badge flag is on but we are not on gitlab.com' do
it 'does not expose the is_gitlab_employee attribute on the assignee' do
stub_feature_flags(gitlab_employee_badge: true)
allow(Gitlab).to receive(:com?).and_return(false)
update_issue(issue_params: { assignee_ids: [assignee.id] })
expect(json_response['assignees'].first.keys)
.to match_array(%w(id name username avatar_url state web_url))
end
end
context 'when the gitlab_employee_badge flag is on and we are on gitlab.com' do
it 'exposes the is_gitlab_employee attribute on the assignee' do
stub_feature_flags(gitlab_employee_badge: true)
allow(Gitlab).to receive(:com?).and_return(true)
update_issue(issue_params: { assignee_ids: [assignee.id] })
expect(json_response['assignees'].first.keys)
.to match_array(%w(id name username avatar_url state web_url is_gitlab_employee))
end
end
end
end
......
......@@ -11,10 +11,7 @@
"properties": {
"is_gitlab_employee": { "type": "boolean"}
},
"additionalProperties": false,
"required": [
"is_gitlab_employee"
]
"additionalProperties": false
}
}
}
......
......@@ -20,8 +20,7 @@
"avatar_url",
"path",
"name",
"username",
"is_gitlab_employee"
"username"
]
}
]
......
......@@ -10,8 +10,7 @@
"web_url",
"path",
"name",
"username",
"is_gitlab_employee"
"username"
],
"properties" : {
"id": { "type": "integer" },
......
......@@ -15,7 +15,7 @@
"is_gitlab_employee": { "type": "boolean" }
},
"required" : [
"id", "name", "username", "state", "avatar_url", "web_url", "is_gitlab_employee"
"id", "name", "username", "state", "avatar_url", "web_url"
],
"additionalProperties": false
}
......
......@@ -8,9 +8,6 @@
"properties": {
"is_gitlab_employee": { "type": "boolean" }
},
"required" : [
"is_gitlab_employee"
],
"additionalProperties": false
}
}
......
......@@ -16,7 +16,7 @@
},
"required": [
"id", "name", "username", "state",
"web_url", "access_level", "expires_at", "avatar_url", "is_gitlab_employee"
"web_url", "access_level", "expires_at", "avatar_url"
]
}
}
......@@ -16,7 +16,7 @@
"is_gitlab_employee": { "type": "boolean" }
},
"required" : [
"id", "name", "username", "state", "avatar_url", "web_url", "is_gitlab_employee"
"id", "name", "username", "state", "avatar_url", "web_url"
],
"additionalProperties": false
}
......
......@@ -16,7 +16,7 @@
"is_gitlab_employee": { "type": "boolean" }
},
"required" : [
"id", "name", "username", "state", "avatar_url", "web_url", "is_gitlab_employee"
"id", "name", "username", "state", "avatar_url", "web_url"
],
"additionalProperties": false
}
......
......@@ -37,6 +37,37 @@ describe API::Members do
expect(response).to match_response_schema('public_api/v4/members', dir: 'ee')
end
context 'when the flag gitlab_employee_badge is on and we are on gitlab.com' do
it 'includes is_gitlab_employee in the response' do
stub_feature_flags(gitlab_employee_badge: true)
allow(Gitlab).to receive(:com?).and_return(true)
get api("/groups/#{group.to_param}/members", owner)
expect(json_response.first.keys).to include('is_gitlab_employee')
end
end
context 'when the flag gitlab_employee_badge is off' do
it 'does not include is_gitlab_employee in the response' do
stub_feature_flags(gitlab_employee_badge: false)
get api("/groups/#{group.to_param}/members", owner)
expect(json_response.first.keys).not_to include('is_gitlab_employee')
end
end
context 'when we are not on gitlab.com' do
it 'does not include is_gitlab_employee in the response' do
allow(Gitlab).to receive(:com?).and_return(false)
get api("/groups/#{group.to_param}/members", owner)
expect(json_response.first.keys).not_to include('is_gitlab_employee')
end
end
context 'when a group has SAML provider configured' do
let(:maintainer) { create(:user) }
......
......@@ -361,7 +361,38 @@ describe API::Projects do
first_user = json_response.first
expect(first_user['username']).to eq(user.username)
expect(first_user['name']).to eq(user.name)
expect(first_user.keys).to contain_exactly(*%w[name username id state avatar_url web_url is_gitlab_employee])
end
context 'when the gitlab_employee_badge flag is off' do
it 'does not expose the is_gitlab_employee attribute on the user' do
stub_feature_flags(gitlab_employee_badge: false)
get api("/projects/#{project.id}/users", current_user)
expect(json_response.first.keys).to contain_exactly(*%w[name username id state avatar_url web_url])
end
end
context 'when the gitlab_employee_badge flag is on but we are not on gitlab.com' do
it 'does not expose the is_gitlab_employee attribute on the user' do
stub_feature_flags(gitlab_employee_badge: true)
allow(Gitlab).to receive(:com?).and_return(false)
get api("/projects/#{project.id}/users", current_user)
expect(json_response.first.keys).to contain_exactly(*%w[name username id state avatar_url web_url])
end
end
context 'when the gitlab_employee_badge flag is on and we are on gitlab.com' do
it 'exposes the is_gitlab_employee attribute on the user' do
stub_feature_flags(gitlab_employee_badge: true)
allow(Gitlab).to receive(:com?).and_return(true)
get api("/projects/#{project.id}/users", current_user)
expect(json_response.first.keys).to contain_exactly(*%w[name username id state avatar_url web_url is_gitlab_employee])
end
end
end
......
......@@ -10,7 +10,29 @@ describe IssuableSidebarExtrasEntity do
subject { described_class.new(resource, request: request).as_json }
it 'exposes is_gitlab_employee field for assignees' do
expect(subject[:assignees].first).to include(:is_gitlab_employee)
context 'when the gitlab_employee_badge flag is off' do
it 'does not expose the is_gitlab_employee field for assignees' do
stub_feature_flags(gitlab_employee_badge: false)
expect(subject[:assignees].first).not_to include(:is_gitlab_employee)
end
end
context 'when the gitlab_employee_badge flag is on but we are not on gitlab.com' do
it 'does not expose the is_gitlab_employee field for assignees' do
stub_feature_flags(gitlab_employee_badge: true)
allow(Gitlab).to receive(:com?).and_return(false)
expect(subject[:assignees].first).not_to include(:is_gitlab_employee)
end
end
context 'when gitlab_employee_badge flag is on and we are on gitlab.com' do
it 'exposes is_gitlab_employee field for assignees' do
stub_feature_flags(gitlab_employee_badge: true)
allow(Gitlab).to receive(:com?).and_return(true)
expect(subject[:assignees].first).to include(:is_gitlab_employee)
end
end
end
......@@ -12,11 +12,39 @@ describe MergeRequestSidebarBasicEntity do
let(:entity) { described_class.new(merge_request, request: request).as_json }
describe '#current_user' do
it 'contains attributes related to the current user' do
expect(entity[:current_user].keys).to contain_exactly(
:id, :name, :username, :state, :avatar_url, :web_url, :todo,
:can_edit, :can_move, :can_admin_label, :can_merge, :is_gitlab_employee
)
context 'when the gitlab_employee_badge flag is off' do
it 'does not expose the is_gitlab_employee field for the current user' do
stub_feature_flags(gitlab_employee_badge: false)
expect(entity[:current_user].keys).to contain_exactly(
:id, :name, :username, :state, :avatar_url, :web_url, :todo,
:can_edit, :can_move, :can_admin_label, :can_merge
)
end
end
context 'when the gitlab_employee_badge flag is on but we are not on gitlab.com' do
it 'does not expose the is_gitlab_employee field for the current user' do
stub_feature_flags(gitlab_employee_badge: true)
allow(Gitlab).to receive(:com?).and_return(false)
expect(entity[:current_user].keys).to contain_exactly(
:id, :name, :username, :state, :avatar_url, :web_url, :todo,
:can_edit, :can_move, :can_admin_label, :can_merge
)
end
end
context 'when the gitlab_employee_badge flag is on and we are on gitlab.com' do
it 'exposes the is_gitlab_employee field for the current user' do
stub_feature_flags(gitlab_employee_badge: true)
allow(Gitlab).to receive(:com?).and_return(true)
expect(entity[:current_user].keys).to contain_exactly(
:id, :name, :username, :state, :avatar_url, :web_url, :todo,
:can_edit, :can_move, :can_admin_label, :can_merge, :is_gitlab_employee
)
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