Commit 83a34286 authored by Jacques Erasmus's avatar Jacques Erasmus

Merge branch '333776-update-blob-to-use-canpushcode' into 'master'

Update to use correct push code permission

See merge request gitlab-org/gitlab!65090
parents c37b441f 93f9c146
......@@ -65,6 +65,9 @@ export default {
isLoadingLegacyViewer: false,
activeViewerType: SIMPLE_BLOB_VIEWER,
project: {
userPermissions: {
pushCode: false,
},
repository: {
blobs: {
nodes: [
......@@ -86,7 +89,6 @@ export default {
canLock: false,
isLocked: false,
lockLink: '',
canModifyBlob: true,
forkPath: '',
simpleViewer: {},
richViewer: null,
......@@ -168,7 +170,7 @@ export default {
:path="path"
:name="blobInfo.name"
:replace-path="blobInfo.replacePath"
:can-push-code="blobInfo.canModifyBlob"
:can-push-code="project.userPermissions.pushCode"
/>
</template>
</blob-header>
......
query getBlobInfo($projectPath: ID!, $filePath: String!) {
project(fullPath: $projectPath) {
userPermissions {
pushCode
}
repository {
blobs(paths: [$filePath]) {
nodes {
......@@ -15,7 +18,6 @@ query getBlobInfo($projectPath: ID!, $filePath: String!) {
storedExternally
rawPath
replacePath
canModifyBlob
simpleViewer {
fileType
tooLarge
......
......@@ -37,7 +37,6 @@ const simpleMockData = {
canLock: true,
isLocked: false,
lockLink: 'some_file.js/lock',
canModifyBlob: true,
forkPath: 'some_file.js/fork',
simpleViewer: {
fileType: 'text',
......@@ -56,16 +55,26 @@ const richMockData = {
renderError: null,
},
};
const userPermissionsMockData = {
userPermissions: {
pushCode: true,
},
};
const localVue = createLocalVue();
const mockAxios = new MockAdapter(axios);
const createComponentWithApollo = (mockData) => {
const createComponentWithApollo = (mockData, mockPermissionData = true) => {
localVue.use(VueApollo);
const mockResolver = jest
.fn()
.mockResolvedValue({ data: { project: { repository: { blobs: { nodes: [mockData] } } } } });
const mockResolver = jest.fn().mockResolvedValue({
data: {
project: {
userPermissions: { pushCode: mockPermissionData },
repository: { blobs: { nodes: [mockData] } },
},
},
});
const fakeApollo = createMockApollo([[blobInfoQuery, mockResolver]]);
......@@ -276,13 +285,16 @@ describe('Blob content viewer component', () => {
});
describe('BlobButtonGroup', () => {
const { name, path } = simpleMockData;
const { name, path, replacePath } = simpleMockData;
const {
userPermissions: { pushCode },
} = userPermissionsMockData;
it('renders component', async () => {
window.gon.current_user_id = 1;
fullFactory({
mockData: { blobInfo: simpleMockData },
mockData: { blobInfo: simpleMockData, project: userPermissionsMockData },
stubs: {
BlobContent: true,
BlobButtonGroup: true,
......@@ -294,6 +306,8 @@ describe('Blob content viewer component', () => {
expect(findBlobButtonGroup().props()).toMatchObject({
name,
path,
replacePath,
canPushCode: pushCode,
});
});
......
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