#51: some refactoring
This commit is contained in:
parent
2bc580500d
commit
8b6a0eab0f
|
@ -41,10 +41,7 @@ class Projects::IssuesController < Projects::BaseController
|
|||
@assignee_uname = params[:assignee_uname]
|
||||
@issue.user_id = current_user.id
|
||||
|
||||
unless can?(:write, @project)
|
||||
@issue.assignee_id = nil
|
||||
@issue.labelings = []
|
||||
end
|
||||
@issue.can_write_project = can?(:write, @project)
|
||||
if @issue.save
|
||||
@issue.subscribe_creator(current_user.id)
|
||||
flash[:notice] = I18n.t("flash.issue.saved")
|
||||
|
@ -60,11 +57,9 @@ class Projects::IssuesController < Projects::BaseController
|
|||
end
|
||||
|
||||
def update
|
||||
unless can?(:write, @project)
|
||||
[:labelings, :labelings_attributes, :assignee_id].each{ |k| params[:issue].delete k }
|
||||
params.delete :update_labels
|
||||
end
|
||||
@issue.labelings.destroy_all if params[:update_labels]
|
||||
can_write_project = can?(:write, @project)
|
||||
@issue.can_write_project = can_write_project
|
||||
@issue.labelings.destroy_all if can_write_project && params[:update_labels]
|
||||
if params[:issue] && status = params[:issue][:status]
|
||||
@issue.set_close(current_user) if status == 'closed'
|
||||
@issue.set_open if status == 'open'
|
||||
|
|
|
@ -43,6 +43,7 @@ class Projects::PullRequestsController < Projects::BaseController
|
|||
@pull.from_project_owner_uname = @pull.from_project.owner.uname
|
||||
@pull.from_project_name = @pull.from_project.name
|
||||
|
||||
@pull.issue.can_write_project = can?(:write, @project)
|
||||
if @pull.valid? # FIXME more clean/clever logics
|
||||
@pull.save # set pull id
|
||||
@pull.check(false) # don't make event transaction
|
||||
|
@ -67,6 +68,7 @@ class Projects::PullRequestsController < Projects::BaseController
|
|||
end
|
||||
|
||||
def update
|
||||
@pull.issue.can_write_project = can?(:write, @project)
|
||||
if (action = params[:pull_request_action]) && %w(close reopen).include?(params[:pull_request_action])
|
||||
if @pull.send("can_#{action}?")
|
||||
@pull.set_user_and_time current_user
|
||||
|
|
|
@ -13,6 +13,7 @@ class Issue < ActiveRecord::Base
|
|||
has_many :labels, :through => :labelings, :uniq => true
|
||||
has_one :pull_request, :dependent => :destroy
|
||||
|
||||
before_validation :sanitize_params_for_current_user
|
||||
validates :title, :body, :project_id, :presence => true
|
||||
|
||||
after_create :set_serial_id
|
||||
|
@ -21,6 +22,7 @@ class Issue < ActiveRecord::Base
|
|||
|
||||
attr_accessible :labelings_attributes, :title, :body, :assignee_id
|
||||
accepts_nested_attributes_for :labelings, :allow_destroy => true
|
||||
attr_accessor :can_write_project
|
||||
|
||||
scope :opened, where(:status => 'open')
|
||||
scope :closed, where(:status => 'closed')
|
||||
|
@ -69,6 +71,17 @@ class Issue < ActiveRecord::Base
|
|||
|
||||
protected
|
||||
|
||||
def sanitize_params_for_current_user
|
||||
return true if can_write_project
|
||||
if persisted?
|
||||
self.assignee_id = self.assignee_id
|
||||
self.labelings = self.labelings
|
||||
else
|
||||
self.assignee_id = nil
|
||||
self.labelings = []
|
||||
end
|
||||
end
|
||||
|
||||
def set_serial_id
|
||||
self.serial_id = self.project.issues.count
|
||||
self.save!
|
||||
|
|
Loading…
Reference in New Issue