Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

feature: contributors allowed to delete repositories/tags #1696

Merged
merged 1 commit into from
Feb 27, 2018

Conversation

vitoravelino
Copy link
Contributor

@vitoravelino vitoravelino commented Feb 21, 2018

Summary

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

  • Implementation
  • New API endpoints
  • Usage of API endpoints in the client-side
  • Testing

Fixes #1273

@vitoravelino
Copy link
Contributor Author

The solution is already in place but I'm going to take the opportunity to migrate these endpoints to the API and use it in the client-side.

@mssola mssola self-requested a review February 22, 2018 12:41
@vitoravelino vitoravelino changed the title wip: feature: contributors allowed to delete repositories/tags feature: contributors allowed to delete repositories/tags Feb 26, 2018
@vitoravelino
Copy link
Contributor Author

@mssola This is ready to be reviewed. I'm gonna open an issue for the documentation part of this. I'll work on that whenever I finish my other tasks.

Copy link
Collaborator

@mssola mssola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general. The Travis failure is most probably that you haven't signed off your commit (-s flag) 😉

Tag.where(digest: dig).find_each do |tag|
tags_destroyed &&= tag&.delete_by!(actor)
end
tags_destroyed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In tags_destroyed &&= tag&.delete_by!(actor) you may have removed tags from a previous iteration, even if this one fails. Thus, you should rename tags_destroyed to success.


delete_enabled = APP_CONFIG.enabled?("delete")
is_owner = @repository.namespace.team.owners.exists?(user.id)
can_contributor_delete = APP_CONFIG["delete"]["contributors"] &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to: APP_CONFIG.enabled?("delete.contributors") as you are doing in the tag policy. Moreover, maybe it would be a good change to DRY this part and create a method like this:

def allow_destroy_for?(user, repository)
  delete_enabled         = APP_CONFIG.enabled?("delete")
  is_owner               = repository.namespace.team.owners.exists?(user.id)
  can_contributor_delete = APP_CONFIG.enabled?("delete.contributors") &&
                             @repository.namespace.team.contributors.exists?(user.id)
  delete_enabled && (user.admin? || is_owner || can_contributor_delete)
end

Note that the tag policy basically does tag.repository, so the repository is the only object needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to: APP_CONFIG.enabled?("delete.contributors") as you are doing in the tag policy.

The tag policy was actually a leftover since it doesn't work. The enabled? function works only with the enabled child attribute. In this case we have contributors being a child of delete and the value goes directly to it and not to a enabled child. I should actually fix the tag policy file.

I double checked and by using enabled? on delete.contributors, it always return true. I think that if enabled child attribute does not exist it should return false, no?

destroy_service = ::Repositories::DestroyService.new(current_user)
destroyed = destroy_service.execute(repository)

error!({ "errors" => destroy_service.error }, 422, header) unless destroyed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On success a delete request should return a 204 status code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember that in the other PR about managing team member (still pending btw, but I need to re-review and rebase before asking another review) I was having an issue by writing just the unless? For some reason this is working now. Maybe gem version has been updated? Response seems fine as you can see below:

Request URL:http://localhost:3000/api/v1/repositories/12
Request Method:DELETE
Status Code:204 No Content

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. As long as the tests works I'm fine then 👍

service = ::Tags::DestroyService.new(current_user)
destroyed = service.execute(tag)

error!({ "errors" => service.error }, 422, header) unless destroyed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in the repository.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. 😄

@vitoravelino
Copy link
Contributor Author

The Travis failure is most probably that you haven't signed off your commit (-s flag)

I'm just signing the commits via GPG (-S) but not showing the signature (-s). I'll configure my gitconfig to explicitly add the signature.

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]>
@vitoravelino
Copy link
Contributor Author

GREEN! 😄

@mssola mssola merged commit 5533a5b into SUSE:master Feb 27, 2018
@mssola
Copy link
Collaborator

mssola commented Feb 27, 2018

Thanks a lot! 👍

@vitoravelino vitoravelino deleted the improve-delete-config branch April 20, 2018 13:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants