-
-
Notifications
You must be signed in to change notification settings - Fork 924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Policy change: Permadelete on yank #923
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dc9ce8a
Unyank now responds to anything with 410 Gone
qrush 7a90cfc
Remove Version#unyank
qrush 743226f
Skip checking permissions. Any request to unyank now responds with gone:
qrush 91ad924
Delete .gem file on yank api
arthurnn 7061f5e
Add deletions table, create when yanking
qrush d2801da
Move api/v1/rubygems#yank, #unyank to api/v1/deletions#create, #destroy
qrush 8a2b338
Push logic for deleting gems out of Version#yank! and into Deletion
qrush 2785b42
Remove gemspec file when delete gem
arthurnn dc0a268
Dont show download link when gem deleted
arthurnn 8f92801
Change show page on yanked gems
arthurnn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
class Api::BaseController < ApplicationController | ||
skip_before_action :require_ssl | ||
|
||
private | ||
|
||
def find_rubygem_by_name | ||
@url = params[:url] | ||
@gem_name = params[:gem_name] | ||
@rubygem = Rubygem.find_by_name(@gem_name) | ||
if @rubygem.nil? && @gem_name != WebHook::GLOBAL_PATTERN | ||
render :text => "This gem could not be found", | ||
:status => :not_found | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class Api::V1::DeletionsController < Api::BaseController | ||
skip_before_action :verify_authenticity_token, only: [:create, :destroy] | ||
|
||
before_action :authenticate_with_api_key, only: [:create, :destroy] | ||
before_action :verify_authenticated_user, only: [:create, :destroy] | ||
before_action :find_rubygem_by_name, only: [:create, :destroy] | ||
before_action :validate_gem_and_version, only: [:create] | ||
|
||
def create | ||
@deletion = current_user.deletions.build(version: @version) | ||
if @deletion.save | ||
StatsD.increment 'yank.success' | ||
render text: "Successfully deleted gem: #{@version.to_title}" | ||
else | ||
StatsD.increment 'yank.failure' | ||
render text: "The version #{params[:version]} has already been deleted.", status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
render text: "Unyanking of gems is no longer supported.", status: :gone | ||
end | ||
|
||
private | ||
|
||
def validate_gem_and_version | ||
if [email protected]? | ||
render text: "This gem does not exist.", status: :not_found | ||
elsif [email protected]_by?(current_user) | ||
render text: "You do not have permission to delete this gem.", status: :forbidden | ||
else | ||
begin | ||
slug = params[:platform].blank? ? params[:version] : "#{params[:version]}-#{params[:platform]}" | ||
@version = Version.find_from_slug!(@rubygem, slug) | ||
rescue ActiveRecord::RecordNotFound | ||
render text: "The version #{params[:version]} does not exist.", status: :not_found | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
class Api::V1::RubygemsController < Api::BaseController | ||
skip_before_action :verify_authenticity_token, :only => [:create, :yank, :unyank] | ||
skip_before_action :verify_authenticity_token, :only => [:create] | ||
|
||
before_action :authenticate_with_api_key, :only => [:index, :create, :yank, :unyank] | ||
before_action :verify_authenticated_user, :only => [:index, :create, :yank, :unyank] | ||
before_action :authenticate_with_api_key, :only => [:index, :create] | ||
before_action :verify_authenticated_user, :only => [:index, :create] | ||
before_action :find_rubygem, :only => [:show] | ||
before_action :find_rubygem_by_name, :only => [:yank, :unyank] | ||
before_action :validate_gem_and_version, :only => [:yank, :unyank] | ||
|
||
def index | ||
@rubygems = current_user.rubygems.with_versions | ||
|
@@ -32,26 +30,6 @@ def create | |
render :text => gemcutter.message, :status => gemcutter.code | ||
end | ||
|
||
def yank | ||
if @version.indexed? | ||
@version.yank! | ||
StatsD.increment 'yank.success' | ||
render :text => "Successfully yanked gem: #{@version.to_title}" | ||
else | ||
StatsD.increment 'yank.failure' | ||
render :text => "The version #{params[:version]} has already been yanked.", :status => :unprocessable_entity | ||
end | ||
end | ||
|
||
def unyank | ||
if [email protected]? | ||
@version.unyank! | ||
render :text => "Successfully unyanked gem: #{@version.to_title}" | ||
else | ||
render :text => "The version #{params[:version]} is already indexed.", :status => :unprocessable_entity | ||
end | ||
end | ||
|
||
def reverse_dependencies | ||
names = Rubygem.reverse_dependencies(params[:id]).pluck(:name) | ||
|
||
|
@@ -60,21 +38,4 @@ def reverse_dependencies | |
format.yaml { render yaml: names, yamlish: true } | ||
end | ||
end | ||
|
||
private | ||
|
||
def validate_gem_and_version | ||
if [email protected]? | ||
render :text => "This gem does not exist.", :status => :not_found | ||
elsif [email protected]_by?(current_user) | ||
render :text => "You do not have permission to yank this gem.", :status => :forbidden | ||
else | ||
begin | ||
slug = params[:platform].blank? ? params[:version] : "#{params[:version]}-#{params[:platform]}" | ||
@version = Version.find_from_slug!(@rubygem, slug) | ||
rescue ActiveRecord::RecordNotFound | ||
render :text => "The version #{params[:version]} does not exist.", :status => :not_found | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class Deletion < ActiveRecord::Base | ||
belongs_to :user | ||
|
||
validates :user, :rubygem, :number, presence: true | ||
validates :version, presence: true | ||
validate :version_is_indexed | ||
|
||
before_validation :record_metadata | ||
after_create :remove_from_index | ||
after_commit :remove_from_storage | ||
|
||
attr_accessor :version | ||
|
||
private | ||
|
||
def version_is_indexed | ||
errors.add(:number, "is already deleted") unless @version.indexed? | ||
end | ||
|
||
def rubygem_name | ||
@version.rubygem.name | ||
end | ||
|
||
def record_metadata | ||
self.rubygem = rubygem_name | ||
self.number = @version.number | ||
self.platform = @version.platform | ||
end | ||
|
||
def remove_from_index | ||
@version.update!(indexed: false) | ||
Redis.current.lrem(Rubygem.versions_key(rubygem_name), 1, @version.full_name) | ||
end | ||
|
||
def remove_from_storage | ||
RubygemFs.instance.remove("gems/#{@version.full_name}.gem") | ||
RubygemFs.instance.remove("quick/Marshal.4.8/#{@version.full_name}.gemspec.rz") | ||
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
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateDeletions < ActiveRecord::Migration | ||
def change | ||
create_table :deletions do |t| | ||
t.belongs_to :user, index: true | ||
t.string :rubygem | ||
t.string :number | ||
t.string :platform | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we log the username instead of the user_id. In case we delete the user, we still want to keep the Deletion entry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Username can change. There's not a
dependent
relationship onhas_many :deletions
so these records will stay in the DB.