This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: contributors allowed to delete repositories/tags
With the variety usage of Portus, the need of giving contributors more responsibilities arose. So far only admin were able to delete repositories and tags if the capability were enabled. This patch extends the feature to also allow contributors to be able delete resources. We also took the opportunity to migrate and add two endpoints [0] [1] the API regarding this topic. Users are now able to invoke the API to perform those actions if they want to. [0] DELETE /api/v1/repositories/:id [1] DELETE /api/v1/tags/:id Signed-off-by: Vítor Avelino <[email protected]>
- Loading branch information
1 parent
4bba5e1
commit 53ce896
Showing
31 changed files
with
592 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/assets/javascripts/modules/repositories/components/delete-tag-action.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,39 @@ | ||
const ALERT_ELEMENT = '#float-alert'; | ||
const TEXT_ALERT_ELEMENT = '#float-alert p'; | ||
const HIDE_TIMEOUT = 5000; | ||
const STORAGE_KEY = 'portus.alerts.schedule'; | ||
|
||
function $show(text, autohide = true) { | ||
const storage = window.localStorage; | ||
|
||
const $show = (text, autohide = true, timeout = HIDE_TIMEOUT) => { | ||
$(TEXT_ALERT_ELEMENT).html(text); | ||
$(ALERT_ELEMENT).fadeIn(); | ||
|
||
if (autohide) { | ||
setTimeout(() => $(ALERT_ELEMENT).fadeOut(), HIDE_TIMEOUT); | ||
setTimeout(() => $(ALERT_ELEMENT).fadeOut(), timeout); | ||
} | ||
} | ||
}; | ||
|
||
const scheduledMessages = () => JSON.parse(storage.getItem(STORAGE_KEY)) || []; | ||
const storeMessages = messages => storage.setItem(STORAGE_KEY, JSON.stringify(messages)); | ||
|
||
// the idea is to simulate the alert that is showed after a redirect | ||
// e.g.: something happened that requires a page reload/redirect and | ||
// we need to show this info to the user. | ||
const $schedule = (text) => { | ||
const messages = scheduledMessages(); | ||
messages.push(text); | ||
storeMessages(messages); | ||
}; | ||
|
||
const $process = () => { | ||
const messages = scheduledMessages(); | ||
messages.forEach(m => $show(m, false)); | ||
storage.clear(STORAGE_KEY); | ||
}; | ||
|
||
export default { | ||
$show, | ||
$schedule, | ||
$process, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class TagsController < ApplicationController | ||
include Deletable | ||
|
||
def show | ||
@tag = Tag.find(params[:id]) | ||
authorize @tag | ||
|
||
@names = Tag.where(digest: @tag.digest).sort.map(&:name) | ||
@vulnerabilities = @tag.fetch_vulnerabilities | ||
end | ||
|
||
# Removes all tags that match the digest of the tag with the given ID. | ||
# Moreover, it will also remove the image if it's left empty after removing | ||
# the tags. | ||
def destroy | ||
tag = Tag.find(params[:id]) | ||
authorize tag | ||
|
||
# And now remove the tag by the digest. If the repository containing said | ||
# tags becomes empty after that, remove it too. | ||
repo = tag.repository | ||
if tag.delete_by_digest!(current_user) | ||
if repo.tags.empty? | ||
repo.delete_by!(current_user) | ||
flash[:notice] = "Repository removed with all its tags" | ||
end | ||
head :ok | ||
else | ||
head :internal_server_error | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.