Skip to content

Commit

Permalink
Fix usage of deprecated policy tagging endpoints
Browse files Browse the repository at this point in the history
Replaces usages of `/api/v1/policy/{uuid}/tag/{name}` endpoints with `/api/v1/tag/{name}/policy`, in accordance with DependencyTrack/dependency-track#3924.

Also fixes redundant toasts when removing or adding tags from/to policies.

Signed-off-by: nscuro <nscuro@protonmail.com>
  • Loading branch information
nscuro committed Jul 6, 2024
1 parent 56b3b5e commit 571bdd7
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/views/policy/PolicyList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,10 @@ export default {
});
},
deleteTagLimiter: function (tagName) {
let url = `${this.$api.BASE_URL}/${this.$api.URL_POLICY}/${this.policy.uuid}/tag/${tagName}`;
let url = `${this.$api.BASE_URL}/${this.$api.URL_TAG}/${encodeURIComponent(tagName)}/policy`;
this.axios
.delete(url)
.then((response) => {
.delete(url, { data: [this.policy.uuid] })
.then(() => {
let p = [];
for (let i = 0; i < this.tags.length; i++) {
if (this.tags[i].name !== tagName) {
Expand All @@ -318,9 +318,6 @@ export default {
}
this.tags = p;
this.$toastr.s(this.$t('message.updated'));
})
.catch((error) => {
this.$toastr.w(this.$t('condition.unsuccessful_action'));
});
},
updateProjectSelection: function (selections) {
Expand All @@ -347,19 +344,27 @@ export default {
},
updateTagSelection: function (selections) {
this.$root.$emit('bv::hide::modal', 'selectTagModal');
let promises = [];
for (let i = 0; i < selections.length; i++) {
let selection = selections[i];
let url = `${this.$api.BASE_URL}/${this.$api.URL_POLICY}/${this.policy.uuid}/tag/${selection.name}`;
this.axios
.post(url)
.then((response) => {
this.tags.push(selection);
this.$toastr.s(this.$t('message.updated'));
})
.catch((error) => {
this.$toastr.w(this.$t('condition.unsuccessful_action'));
});
let url = `${this.$api.BASE_URL}/${this.$api.URL_TAG}/${encodeURIComponent(selection.name)}/policy`;
promises.push(
this.axios
.post(url, [this.policy.uuid])
.then(() => Promise.resolve(selection.name)),
);
}
Promise.all(promises).then((addedTagNames) => {
for (const tagName of addedTagNames) {
if (!this.tags.some((tag) => tag.name === tagName)) {
this.tags.push({ name: tagName });
}
}
this.$toastr.s(this.$t('message.updated'));
});
},
updateIncludeChildren: function () {
let url = `${this.$api.BASE_URL}/${this.$api.URL_POLICY}`;
Expand Down

0 comments on commit 571bdd7

Please sign in to comment.