#3178: including permissions for create_ and update_with_relationship

pull/6827/head
Jens Ulferts 14 years ago
parent bf3430004d
commit a21e3b5a68
  1. 13
      app/models/impediment.rb
  2. 12
      spec/models/impediment_spec.rb

@ -5,8 +5,15 @@ class Impediment < Task
after_save :update_blocks_list
safe_attributes "blocks", #change to blocks_ids once ui can be manipulated
:if => lambda {|impediment, user|
(impediment.new_record? && user.allowed_to?(:create_impediments, impediment.project)) ||
user.allowed_to?(:update_impediments, impediment.project)
}
def self.create_with_relationships(params, user_id, project_id)
task = new
task.author_id = user_id
task.project_id = project_id
task.tracker_id = Task.tracker
@ -14,8 +21,6 @@ class Impediment < Task
task.safe_attributes = params
task.remaining_hours = 0 if IssueStatus.find(params[:status_id]).is_closed?
task.blocks_ids = params[:blocks]
if task.save
task.move_after params[:prev]
end
@ -42,6 +47,10 @@ class Impediment < Task
super(since, project_id, true)
end
def blocks=(ids)
self.blocks_ids = ids
end
def blocks_ids=(ids)
@blocks_ids_list = [ids] if ids.is_a?(Integer)
@blocks_ids_list = ids.split(/\D+/).map{|id| id.to_i} if ids.is_a?(String)

@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Impediment do
let(:user) { @user ||= Factory.create(:user) }
let(:role) { @role ||= Factory.create(:role, :permissions => [:edit_issues]) }
let(:role) { @role ||= Factory.create(:role) }
let(:tracker_feature) { @tracker_feature ||= Factory.create(:tracker_feature) }
let(:tracker_task) { @tracker_task ||= Factory.create(:tracker_task) }
let(:issue_priority) { @issue_priority ||= Factory.create(:priority, :is_default => true) }
@ -40,8 +40,7 @@ describe Impediment do
:priority => issue_priority,
:project => project,
:tracker => tracker_task,
:status => issue_status1,
:blocks_ids => feature.id.to_s)}
:status => issue_status1)}
before(:each) do
Setting.plugin_redmine_backlogs = {:points_burn_direction => "down",
@ -61,6 +60,8 @@ describe Impediment do
describe :create_with_relationships do
before(:each) do
@impediment_subject = "Impediment A"
role.permissions = [:create_impediments]
role.save
end
shared_examples_for "impediment creation" do
@ -146,9 +147,14 @@ describe Impediment do
describe "instance methods" do
describe :update_with_relationships do
before(:each) do
role.permissions = [:update_impediments]
role.save
feature.fixed_version = version
feature.save
@impediment = impediment
@impediment.blocks_ids = feature.id.to_s
@impediment.save
end

Loading…
Cancel
Save