Add warning modal when unsharing inventories from teams [SCI-11159]

This commit is contained in:
Martin Artnik 2024-10-09 11:13:19 +02:00
parent 920505d59c
commit 746ac08507
2 changed files with 50 additions and 6 deletions

View file

@ -54,8 +54,27 @@
v-if="shareRepository"
:object="shareRepository"
:globalShareEnabled="true"
:confirmationModal="$refs.shareConfirmationModal"
@close="shareRepository = null"
@share="updateTable" />
<ConfirmationModal
ref="shareConfirmationModal"
:title="i18n.t('repositories.index.modal_confirm_sharing.title')"
:description="`
<p>${i18n.t('repositories.index.modal_confirm_sharing.description_1')}</p>
<p><b>${i18n.t('repositories.index.modal_confirm_sharing.description_2')}</b></p>
`"
:confirmClass="'btn btn-danger'"
:confirmText="i18n.t('repositories.index.modal_confirm_sharing.confirm')"
:e2eAttributes="{
modalName: 'e2e-MD-confirmSharingChanges',
title: 'e2e-TX-confirmSharingChangesModal-title',
content: 'e2e-TX-confirmSharingChangesModal-content',
close: 'e2e-BT-confirmSharingChangesModal-close',
cancel: 'e2e-BT-confirmSharingChangesModal-cancel',
confirm: 'e2e-BT-confirmSharingChangesModal-delete'
}"
></ConfirmationModal>
</template>
<script>

View file

@ -77,27 +77,52 @@ export default {
name: 'ShareObjectModal',
props: {
object: Object,
globalShareEnabled: { type: Boolean, default: false }
globalShareEnabled: { type: Boolean, default: false },
confirmationModal: { type: Object }
},
mixins: [modalMixin],
data() {
return {
sharedWithAllRead: this.object.shared_read || this.object.shared_write,
sharedWithAllWrite: this.object.shared_write,
shareableTeams: [],
permission_changes: {}
initialState: {},
shareableTeams: []
};
},
mounted() {
this.getTeams();
this.initTeams();
},
computed: {
willUnshare() {
if (this.globalShareEnabled && !this.sharedWithAllRead && this.initialState.sharedWithAllRead) return true;
// true if any team would switch from shared to unshared, based on initial state
return this.shareableTeams.some((t) => {
return this.initialState.shareableTeams.find((it) => t.id === it.id).attributes.private_shared_with && !t.attributes.private_shared_with;
});
}
},
methods: {
getTeams() {
initTeams() {
axios.get(this.object.urls.shareable_teams).then((response) => {
this.initialState = {
shareableTeams: JSON.parse(JSON.stringify(response.data.data)), // object needs to be deep cloned to get rid of references
sharedWithAllRead: this.sharedWithAllRead,
sharedWithAllWrite: this.sharedWithAllWrite
};
this.shareableTeams = response.data.data;
});
},
submit() {
async submit() {
$(this.$refs.modal).hide();
if (this.confirmationModal ? !this.willUnshare || await this.confirmationModal.show() : true) {
this.doRequest();
} else {
$(this.$refs.modal).show();
}
},
doRequest() {
const data = {
select_all_teams: this.sharedWithAllRead,
select_all_write_permission: this.sharedWithAllWrite,