debian-mirror-gitlab/app/assets/javascripts/deploy_keys/components/key.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

222 lines
6.7 KiB
Vue
Raw Normal View History

2017-08-17 22:00:37 +05:30
<script>
2021-06-08 01:23:25 +05:30
import { GlIcon, GlLink, GlTooltipDirective, GlButton } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { head, tail } from 'lodash';
2018-10-15 14:42:47 +05:30
import { s__, sprintf } from '~/locale';
import timeagoMixin from '~/vue_shared/mixins/timeago';
2017-08-17 22:00:37 +05:30
2022-10-11 01:57:18 +05:30
import ActionBtn from './action_btn.vue';
2018-10-15 14:42:47 +05:30
export default {
components: {
2022-10-11 01:57:18 +05:30
ActionBtn,
2021-06-08 01:23:25 +05:30
GlButton,
2020-11-24 15:15:51 +05:30
GlIcon,
2021-06-08 01:23:25 +05:30
GlLink,
2018-10-15 14:42:47 +05:30
},
directives: {
2021-01-29 00:20:46 +05:30
GlTooltip: GlTooltipDirective,
2018-10-15 14:42:47 +05:30
},
mixins: [timeagoMixin],
props: {
deployKey: {
type: Object,
required: true,
},
store: {
type: Object,
required: true,
},
endpoint: {
type: String,
required: true,
},
projectId: {
type: String,
required: false,
default: null,
},
},
data() {
return {
projectsExpanded: false,
};
},
computed: {
editDeployKeyPath() {
return `${this.endpoint}/${this.deployKey.id}/edit`;
},
projects() {
const projects = [...this.deployKey.deploy_keys_projects];
if (this.projectId !== null) {
2020-04-08 14:13:33 +05:30
const indexOfCurrentProject = projects.findIndex(
2021-03-08 18:12:59 +05:30
(project) =>
2018-10-15 14:42:47 +05:30
project &&
project.project &&
project.project.id &&
project.project.id.toString() === this.projectId,
);
if (indexOfCurrentProject > -1) {
const currentProject = projects.splice(indexOfCurrentProject, 1);
currentProject[0].project.full_name = s__('DeployKeys|Current project');
return currentProject.concat(projects);
}
}
return projects;
},
firstProject() {
2020-04-08 14:13:33 +05:30
return head(this.projects);
2018-10-15 14:42:47 +05:30
},
restProjects() {
2020-04-08 14:13:33 +05:30
return tail(this.projects);
2018-10-15 14:42:47 +05:30
},
restProjectsTooltip() {
return sprintf(s__('DeployKeys|Expand %{count} other projects'), {
count: this.restProjects.length,
});
},
restProjectsLabel() {
return sprintf(s__('DeployKeys|+%{count} others'), { count: this.restProjects.length });
},
isEnabled() {
return this.store.isEnabled(this.deployKey.id);
},
isRemovable() {
return (
this.store.isEnabled(this.deployKey.id) &&
this.deployKey.destroyed_when_orphaned &&
this.deployKey.almost_orphaned
);
},
isExpandable() {
return !this.projectsExpanded && this.restProjects.length > 1;
},
isExpanded() {
return this.projectsExpanded || this.restProjects.length === 1;
},
},
methods: {
projectTooltipTitle(project) {
return project.can_push
2021-03-11 19:13:27 +05:30
? s__('DeployKeys|Grant write permissions to this key')
2018-10-15 14:42:47 +05:30
: s__('DeployKeys|Read access only');
},
toggleExpanded() {
this.projectsExpanded = !this.projectsExpanded;
},
},
};
2017-08-17 22:00:37 +05:30
</script>
<template>
2018-10-15 14:42:47 +05:30
<div class="gl-responsive-table-row deploy-key">
<div class="table-section section-40">
2019-02-15 15:39:39 +05:30
<div role="rowheader" class="table-mobile-header">{{ s__('DeployKeys|Deploy key') }}</div>
2021-06-08 01:23:25 +05:30
<div class="table-mobile-content" data-qa-selector="key_container">
<strong class="title" data-qa-selector="key_title_content"> {{ deployKey.title }} </strong>
2022-08-13 15:12:31 +05:30
<dl>
<dt>{{ __('SHA256') }}</dt>
<dd class="fingerprint" data-qa-selector="key_sha256_fingerprint_content">
{{ deployKey.fingerprint_sha256 }}
</dd>
<template v-if="deployKey.fingerprint">
<dt>
{{ __('MD5') }}
</dt>
<dd class="fingerprint" data-qa-selector="key_md5_fingerprint_content">
{{ deployKey.fingerprint }}
</dd>
</template>
</dl>
2018-10-15 14:42:47 +05:30
</div>
2017-08-17 22:00:37 +05:30
</div>
2018-10-15 14:42:47 +05:30
<div class="table-section section-30 section-wrap">
2019-02-15 15:39:39 +05:30
<div role="rowheader" class="table-mobile-header">{{ s__('DeployKeys|Project usage') }}</div>
2018-10-15 14:42:47 +05:30
<div class="table-mobile-content deploy-project-list">
<template v-if="projects.length > 0">
2021-06-08 01:23:25 +05:30
<gl-link
2021-01-29 00:20:46 +05:30
v-gl-tooltip
2018-11-08 19:23:39 +05:30
:title="projectTooltipTitle(firstProject)"
class="label deploy-project-label"
2018-10-15 14:42:47 +05:30
>
2019-02-15 15:39:39 +05:30
<span> {{ firstProject.project.full_name }} </span>
2020-11-24 15:15:51 +05:30
<gl-icon :name="firstProject.can_push ? 'lock-open' : 'lock'" />
2021-06-08 01:23:25 +05:30
</gl-link>
<gl-link
2018-10-15 14:42:47 +05:30
v-if="isExpandable"
2021-01-29 00:20:46 +05:30
v-gl-tooltip
2018-11-08 19:23:39 +05:30
:title="restProjectsTooltip"
2018-10-15 14:42:47 +05:30
class="label deploy-project-label"
@click="toggleExpanded"
>
<span>{{ restProjectsLabel }}</span>
2021-06-08 01:23:25 +05:30
</gl-link>
<gl-link
2018-10-15 14:42:47 +05:30
v-for="deployKeysProject in restProjects"
2018-11-08 19:23:39 +05:30
v-else-if="isExpanded"
2018-10-15 14:42:47 +05:30
:key="deployKeysProject.project.full_path"
2021-01-29 00:20:46 +05:30
v-gl-tooltip
2018-10-15 14:42:47 +05:30
:href="deployKeysProject.project.full_path"
:title="projectTooltipTitle(deployKeysProject)"
2018-11-08 19:23:39 +05:30
class="label deploy-project-label"
2018-10-15 14:42:47 +05:30
>
2019-02-15 15:39:39 +05:30
<span> {{ deployKeysProject.project.full_name }} </span>
2020-11-24 15:15:51 +05:30
<gl-icon :name="deployKeysProject.can_push ? 'lock-open' : 'lock'" />
2021-06-08 01:23:25 +05:30
</gl-link>
2018-10-15 14:42:47 +05:30
</template>
2019-02-15 15:39:39 +05:30
<span v-else class="text-secondary">{{ __('None') }}</span>
2017-08-17 22:00:37 +05:30
</div>
</div>
2018-10-15 14:42:47 +05:30
<div class="table-section section-15 text-right">
2019-02-15 15:39:39 +05:30
<div role="rowheader" class="table-mobile-header">{{ __('Created') }}</div>
2018-10-15 14:42:47 +05:30
<div class="table-mobile-content text-secondary key-created-at">
2021-01-29 00:20:46 +05:30
<span v-gl-tooltip :title="tooltipTitle(deployKey.created_at)">
2020-11-24 15:15:51 +05:30
<gl-icon name="calendar" /> <span>{{ timeFormatted(deployKey.created_at) }}</span>
2018-10-15 14:42:47 +05:30
</span>
</div>
2017-08-17 22:00:37 +05:30
</div>
2018-10-15 14:42:47 +05:30
<div class="table-section section-15 table-button-footer deploy-key-actions">
<div class="btn-group table-action-buttons">
2021-06-08 01:23:25 +05:30
<action-btn v-if="!isEnabled" :deploy-key="deployKey" type="enable" category="secondary">
2018-10-15 14:42:47 +05:30
{{ __('Enable') }}
</action-btn>
2021-06-08 01:23:25 +05:30
<gl-button
2018-10-15 14:42:47 +05:30
v-if="deployKey.can_edit"
2021-01-29 00:20:46 +05:30
v-gl-tooltip
2018-10-15 14:42:47 +05:30
:href="editDeployKeyPath"
:title="__('Edit')"
2021-06-08 01:23:25 +05:30
:aria-label="__('Edit')"
2018-10-15 14:42:47 +05:30
data-container="body"
2021-06-08 01:23:25 +05:30
icon="pencil"
category="secondary"
/>
2018-10-15 14:42:47 +05:30
<action-btn
v-if="isRemovable"
2021-01-29 00:20:46 +05:30
v-gl-tooltip
2018-10-15 14:42:47 +05:30
:deploy-key="deployKey"
2018-11-08 19:23:39 +05:30
:title="__('Remove')"
2021-06-08 01:23:25 +05:30
:aria-label="__('Remove')"
category="primary"
variant="danger"
icon="remove"
2018-10-15 14:42:47 +05:30
type="remove"
data-container="body"
2021-06-08 01:23:25 +05:30
/>
2018-10-15 14:42:47 +05:30
<action-btn
v-else-if="isEnabled"
2021-01-29 00:20:46 +05:30
v-gl-tooltip
2018-10-15 14:42:47 +05:30
:deploy-key="deployKey"
2018-11-08 19:23:39 +05:30
:title="__('Disable')"
2021-06-08 01:23:25 +05:30
:aria-label="__('Disable')"
2018-10-15 14:42:47 +05:30
type="disable"
data-container="body"
2021-06-08 01:23:25 +05:30
icon="cancel"
category="primary"
variant="danger"
/>
2018-10-15 14:42:47 +05:30
</div>
2017-08-17 22:00:37 +05:30
</div>
</div>
</template>