Commit 3f12ba02 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '218567-add-mr-author-compliance-dashboard' into 'master'

Add the MR author to MR's list on the compliance dashboard

See merge request gitlab-org/gitlab!35206
parents 19277ed8 7d4f3393
<script> <script>
import { sprintf, s__ } from '~/locale'; import { sprintf, s__ } from '~/locale';
import { GlTooltipDirective } from '@gitlab/ui'; import { GlAvatar, GlAvatarLink, GlTooltipDirective } from '@gitlab/ui';
import CiIcon from '~/vue_shared/components/ci_icon.vue'; import CiIcon from '~/vue_shared/components/ci_icon.vue';
import timeagoMixin from '~/vue_shared/mixins/timeago'; import timeagoMixin from '~/vue_shared/mixins/timeago';
import Approvers from './approvers.vue'; import Approvers from './approvers.vue';
...@@ -12,6 +12,8 @@ export default { ...@@ -12,6 +12,8 @@ export default {
components: { components: {
CiIcon, CiIcon,
Approvers, Approvers,
GlAvatar,
GlAvatarLink,
}, },
mixins: [timeagoMixin], mixins: [timeagoMixin],
props: { props: {
...@@ -43,6 +45,9 @@ export default { ...@@ -43,6 +45,9 @@ export default {
return this.tooltipTitle(this.mergeRequest.merged_at); return this.tooltipTitle(this.mergeRequest.merged_at);
}, },
}, },
strings: {
createdBy: s__('ComplianceDashboard|created by:'),
},
}; };
</script> </script>
...@@ -58,6 +63,26 @@ export default { ...@@ -58,6 +63,26 @@ export default {
<span class="gl-text-gray-700"> <span class="gl-text-gray-700">
{{ mergeRequest.issuable_reference }} {{ mergeRequest.issuable_reference }}
</span> </span>
<span class="issuable-authored gl-text-gray-700 d-inline-flex align-items-center">
- {{ $options.strings.createdBy }}
<gl-avatar-link
:key="mergeRequest.author.id"
:title="mergeRequest.author.name"
:href="mergeRequest.author.web_url"
:data-user-id="mergeRequest.author.id"
:data-name="mergeRequest.author.name"
class="d-inline-flex align-items-center ml-2 author-link js-user-link"
>
<gl-avatar
:src="mergeRequest.author.avatar_url"
:entity-id="mergeRequest.author.id"
:entity-name="mergeRequest.author.name"
:size="16"
class="mr-1"
/>
<span>{{ mergeRequest.author.name }}</span>
</gl-avatar-link>
</span>
</div> </div>
<div class="issuable-meta"> <div class="issuable-meta">
......
...@@ -62,6 +62,7 @@ class MergeRequestsComplianceFinder < MergeRequestsFinder ...@@ -62,6 +62,7 @@ class MergeRequestsComplianceFinder < MergeRequestsFinder
def preloads def preloads
[ [
:author,
:approved_by_users, :approved_by_users,
:metrics, :metrics,
source_project: :route, source_project: :route,
......
...@@ -16,6 +16,7 @@ class MergeRequestComplianceEntity < Grape::Entity ...@@ -16,6 +16,7 @@ class MergeRequestComplianceEntity < Grape::Entity
merge_request.to_reference(merge_request.project.group) merge_request.to_reference(merge_request.project.group)
end end
expose :author, using: API::Entities::UserBasic
expose :approved_by_users, using: API::Entities::UserBasic expose :approved_by_users, using: API::Entities::UserBasic
expose :pipeline_status, if: -> (*) { can_read_pipeline? }, with: DetailedStatusEntity expose :pipeline_status, if: -> (*) { can_read_pipeline? }, with: DetailedStatusEntity
......
---
title: Add the MR author to MR's list on the compliance dashboard
merge_request: 35206
author:
type: added
...@@ -29,6 +29,35 @@ exports[`MergeRequest component when there is a merge request matches the snapsh ...@@ -29,6 +29,35 @@ exports[`MergeRequest component when there is a merge request matches the snapsh
!1 !1
</span> </span>
<span
class="issuable-authored gl-text-gray-700 d-inline-flex align-items-center"
>
- created by:
<gl-avatar-link-stub
class="d-inline-flex align-items-center ml-2 author-link js-user-link"
data-name="User 1"
data-user-id="1"
href="http://localhost:3000/user-1"
title="User 1"
>
<gl-avatar-stub
alt="avatar"
class="mr-1"
entityid="1"
entityname="User 1"
shape="circle"
size="16"
src="https://1"
/>
<span>
User 1
</span>
</gl-avatar-link-stub>
</span>
</div> </div>
<div <div
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlAvatarLink } from '@gitlab/ui';
import MergeRequest from 'ee/compliance_dashboard/components/merge_request.vue'; import MergeRequest from 'ee/compliance_dashboard/components/merge_request.vue';
import { createMergeRequest, createPipelineStatus } from '../mock_data'; import { createMergeRequest, createPipelineStatus } from '../mock_data';
...@@ -10,6 +11,7 @@ describe('MergeRequest component', () => { ...@@ -10,6 +11,7 @@ describe('MergeRequest component', () => {
const findCiLink = () => wrapper.find('.controls').find('a'); const findCiLink = () => wrapper.find('.controls').find('a');
const findInfo = () => wrapper.find('.issuable-main-info'); const findInfo = () => wrapper.find('.issuable-main-info');
const findTime = () => wrapper.find('time'); const findTime = () => wrapper.find('time');
const findAuthorAvatarLink = () => wrapper.find('.issuable-authored').find(GlAvatarLink);
const createComponent = mergeRequest => { const createComponent = mergeRequest => {
return shallowMount(MergeRequest, { return shallowMount(MergeRequest, {
...@@ -56,6 +58,10 @@ describe('MergeRequest component', () => { ...@@ -56,6 +58,10 @@ describe('MergeRequest component', () => {
).toEqual(mergeRequest.issuable_reference); ).toEqual(mergeRequest.issuable_reference);
}); });
it('renders the author name', () => {
expect(findAuthorAvatarLink().text()).toEqual(mergeRequest.author.name);
});
it('renders the "merged at" time', () => { it('renders the "merged at" time', () => {
expect(findTime().text()).toEqual('merged 2 days ago'); expect(findTime().text()).toEqual('merged 2 days ago');
}); });
......
...@@ -4,6 +4,15 @@ const twoDaysAgo = () => { ...@@ -4,6 +4,15 @@ const twoDaysAgo = () => {
return date.toISOString(); return date.toISOString();
}; };
const createUser = id => ({
id,
avatar_url: `https://${id}`,
name: `User ${id}`,
state: 'active',
username: `user-${id}`,
web_url: `http://localhost:3000/user-${id}`,
});
export const createMergeRequest = ({ id = 1, pipeline, approvers } = {}) => { export const createMergeRequest = ({ id = 1, pipeline, approvers } = {}) => {
const mergeRequest = { const mergeRequest = {
id, id,
...@@ -14,6 +23,9 @@ export const createMergeRequest = ({ id = 1, pipeline, approvers } = {}) => { ...@@ -14,6 +23,9 @@ export const createMergeRequest = ({ id = 1, pipeline, approvers } = {}) => {
path: `/h5bp/html5-boilerplate/-/merge_requests/${id}`, path: `/h5bp/html5-boilerplate/-/merge_requests/${id}`,
title: `Merge request ${id}`, title: `Merge request ${id}`,
}; };
mergeRequest.author = createUser(id);
if (pipeline) { if (pipeline) {
mergeRequest.pipeline_status = pipeline; mergeRequest.pipeline_status = pipeline;
} }
...@@ -38,14 +50,7 @@ export const createPipelineStatus = status => ({ ...@@ -38,14 +50,7 @@ export const createPipelineStatus = status => ({
export const createApprovers = count => { export const createApprovers = count => {
return Array(count) return Array(count)
.fill() .fill()
.map((_, id) => ({ .map((_, id) => createUser(id));
id,
avatar_url: `https://${id}`,
name: `User ${id}`,
state: 'active',
username: `user-${id}`,
web_url: `http://localhost:3000/user-${id}`,
}));
}; };
export const createMergeRequests = ({ count = 1 } = {}) => { export const createMergeRequests = ({ count = 1 } = {}) => {
......
...@@ -17,11 +17,11 @@ RSpec.describe MergeRequestComplianceEntity do ...@@ -17,11 +17,11 @@ RSpec.describe MergeRequestComplianceEntity do
it 'includes merge request attributes for compliance' do it 'includes merge request attributes for compliance' do
expect(subject).to include( expect(subject).to include(
:id, :title, :merged_at, :milestone, :path, :issuable_reference, :approved_by_users :id, :title, :merged_at, :milestone, :path, :issuable_reference, :author, :approved_by_users
) )
end end
describe 'with a approver' do describe 'with an approver' do
let_it_be(:approver) { create(:user) } let_it_be(:approver) { create(:user) }
let!(:approval) { create :approval, merge_request: merge_request, user: approver } let!(:approval) { create :approval, merge_request: merge_request, user: approver }
......
...@@ -5888,6 +5888,9 @@ msgstr "" ...@@ -5888,6 +5888,9 @@ msgstr ""
msgid "Compliance frameworks" msgid "Compliance frameworks"
msgstr "" msgstr ""
msgid "ComplianceDashboard|created by:"
msgstr ""
msgid "ComplianceFramework|GDPR" msgid "ComplianceFramework|GDPR"
msgstr "" msgstr ""
......
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