@@ -86,8 +86,8 class ApplicationController < ActionController::Base | |||
|
86 | 86 | # admin is always authorized |
|
87 | 87 | return true if self.logged_in_user.admin? |
|
88 | 88 | # if not admin, check membership permission |
|
89 | @user_membership ||= Member.find(:first, :conditions => ["user_id=? and project_id=?", self.logged_in_user.id, @project.id]) | |
|
90 |
if @user_membership and Permission.allowed_to_role( "%s/%s" % [ ctrl, action ], @user_membership |
|
|
89 | @user_membership ||= logged_in_user.role_for_project(@project) | |
|
90 | if @user_membership and Permission.allowed_to_role( "%s/%s" % [ ctrl, action ], @user_membership ) | |
|
91 | 91 | return true |
|
92 | 92 | end |
|
93 | 93 | render :nothing => true, :status => 403 |
@@ -84,7 +84,7 private | |||
|
84 | 84 | # project feed |
|
85 | 85 | # check if project is public or if the user is a member |
|
86 | 86 | @project = Project.find(params[:project_id]) |
|
87 |
render(:nothing => true, :status => 403) and return false unless @project.is_public? || (@user && @user.role_for_project(@project |
|
|
87 | render(:nothing => true, :status => 403) and return false unless @project.is_public? || (@user && @user.role_for_project(@project)) | |
|
88 | 88 | scope = ["#{Project.table_name}.id=?", params[:project_id].to_i] |
|
89 | 89 | else |
|
90 | 90 | # global feed |
@@ -25,7 +25,7 class IssuesController < ApplicationController | |||
|
25 | 25 | include IfpdfHelper |
|
26 | 26 | |
|
27 | 27 | def show |
|
28 |
@status_options = |
|
|
28 | @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user | |
|
29 | 29 | @custom_values = @issue.custom_values.find(:all, :include => :custom_field) |
|
30 | 30 | @journals_count = @issue.journals.count |
|
31 | 31 | @journals = @issue.journals.find(:all, :include => [:user, :details], :limit => 15, :order => "#{Journal.table_name}.created_on desc") |
@@ -67,9 +67,6 class IssuesController < ApplicationController | |||
|
67 | 67 | def add_note |
|
68 | 68 | unless params[:notes].empty? |
|
69 | 69 | journal = @issue.init_journal(self.logged_in_user, params[:notes]) |
|
70 | #@history = @issue.histories.build(params[:history]) | |
|
71 | #@history.author_id = self.logged_in_user.id if self.logged_in_user | |
|
72 | #@history.status = @issue.status | |
|
73 | 70 | if @issue.save |
|
74 | 71 | flash[:notice] = l(:notice_successful_update) |
|
75 | 72 | Mailer.deliver_issue_edit(journal) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
@@ -82,17 +79,10 class IssuesController < ApplicationController | |||
|
82 | 79 | end |
|
83 | 80 | |
|
84 | 81 | def change_status |
|
85 | #@history = @issue.histories.build(params[:history]) | |
|
86 | @status_options = ([@issue.status] + @issue.status.workflows.find(:all, :order => 'position', :include => :new_status, :conditions => ["role_id=? and tracker_id=?", self.logged_in_user.role_for_project(@project.id), @issue.tracker.id]).collect{ |w| w.new_status }) if self.logged_in_user | |
|
82 | @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user | |
|
87 | 83 | @new_status = IssueStatus.find(params[:new_status_id]) |
|
88 | 84 | if params[:confirm] |
|
89 | 85 | begin |
|
90 | #@history.author_id = self.logged_in_user.id if self.logged_in_user | |
|
91 | #@issue.status = @history.status | |
|
92 | #@issue.fixed_version_id = (params[:issue][:fixed_version_id]) | |
|
93 | #@issue.assigned_to_id = (params[:issue][:assigned_to_id]) | |
|
94 | #@issue.done_ratio = (params[:issue][:done_ratio]) | |
|
95 | #@issue.lock_version = (params[:issue][:lock_version]) | |
|
96 | 86 | journal = @issue.init_journal(self.logged_in_user, params[:notes]) |
|
97 | 87 | @issue.status = @new_status |
|
98 | 88 | if @issue.update_attributes(params[:issue]) |
@@ -215,8 +215,7 class ProjectsController < ApplicationController | |||
|
215 | 215 | |
|
216 | 216 | default_status = IssueStatus.default |
|
217 | 217 | @issue = Issue.new(:project => @project, :tracker => @tracker, :status => default_status) |
|
218 | @allowed_statuses = [default_status] + default_status.workflows.find(:all, :order => 'position', :include => :new_status, :conditions => ["role_id=? and tracker_id=?", self.logged_in_user.role_for_project(@project.id), @issue.tracker.id]).collect{ |w| w.new_status } | |
|
219 | ||
|
218 | @allowed_statuses = default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user | |
|
220 | 219 | if request.get? |
|
221 | 220 | @issue.start_date = Date.today |
|
222 | 221 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } |
@@ -349,7 +348,7 class ProjectsController < ApplicationController | |||
|
349 | 348 | redirect_to :action => 'list_issues', :id => @project and return unless @issues |
|
350 | 349 | @projects = [] |
|
351 | 350 | # find projects to which the user is allowed to move the issue |
|
352 |
@logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role |
|
|
351 | @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role)} | |
|
353 | 352 | # issue can be moved to any tracker |
|
354 | 353 | @trackers = Tracker.find(:all) |
|
355 | 354 | if request.post? and params[:new_project_id] and params[:new_tracker_id] |
@@ -34,7 +34,7 module ApplicationHelper | |||
|
34 | 34 | return true |
|
35 | 35 | end |
|
36 | 36 | # check if user is authorized |
|
37 |
if @logged_in_user and (@logged_in_user.admin? or Permission.allowed_to_role( "%s/%s" % [ controller, action ], @logged_in_user.role_for_project(@project |
|
|
37 | if @logged_in_user and (@logged_in_user.admin? or Permission.allowed_to_role( "%s/%s" % [ controller, action ], @logged_in_user.role_for_project(@project) ) ) | |
|
38 | 38 | return true |
|
39 | 39 | end |
|
40 | 40 | return false |
@@ -36,12 +36,19 class IssueStatus < ActiveRecord::Base | |||
|
36 | 36 | end |
|
37 | 37 | |
|
38 | 38 | # Returns an array of all statuses the given role can switch to |
|
39 | # Uses association cache when called more than one time | |
|
39 | 40 | def new_statuses_allowed_to(role, tracker) |
|
40 | statuses = [] | |
|
41 | for workflow in self.workflows | |
|
42 | statuses << workflow.new_status if workflow.role_id == role.id and workflow.tracker_id == tracker.id | |
|
43 | end unless role.nil? or tracker.nil? | |
|
44 | statuses | |
|
41 | new_statuses = [self] + workflows.select {|w| w.role_id == role.id && w.tracker_id == tracker.id}.collect{|w| w.new_status} | |
|
42 | new_statuses.sort{|x, y| x.position <=> y.position } | |
|
43 | end | |
|
44 | ||
|
45 | # Same thing as above but uses a database query | |
|
46 | # More efficient than the previous method if called just once | |
|
47 | def find_new_statuses_allowed_to(role, tracker) | |
|
48 | new_statuses = [self] + workflows.find(:all, | |
|
49 | :include => :new_status, | |
|
50 | :conditions => ["role_id=? and tracker_id=?", role.id, tracker.id]).collect{ |w| w.new_status } | |
|
51 | new_statuses.sort{|x, y| x.position <=> y.position } | |
|
45 | 52 | end |
|
46 | 53 | |
|
47 | 54 | private |
@@ -57,7 +57,7 class Permission < ActiveRecord::Base | |||
|
57 | 57 | find(:all, :include => :roles).each {|p| perms.store "#{p.controller}/#{p.action}", p.roles.collect {|r| r.id } } |
|
58 | 58 | perms |
|
59 | 59 | end |
|
60 |
allowed_to_public(action) or (@@cached_perms_for_roles[action] |
|
|
60 | allowed_to_public(action) or (role && @@cached_perms_for_roles[action] && @@cached_perms_for_roles[action].include?(role.id)) | |
|
61 | 61 | end |
|
62 | 62 | |
|
63 | 63 | def self.allowed_to_role_expired |
@@ -124,14 +124,8 class User < ActiveRecord::Base | |||
|
124 | 124 | User.hash_password(clear_password) == self.hashed_password |
|
125 | 125 | end |
|
126 | 126 | |
|
127 |
def role_for_project(project |
|
|
128 | @role_for_projects ||= | |
|
129 | begin | |
|
130 | roles = {} | |
|
131 | self.memberships.each { |m| roles.store m.project_id, m.role_id } | |
|
132 | roles | |
|
133 | end | |
|
134 | @role_for_projects[project_id] | |
|
127 | def role_for_project(project) | |
|
128 | memberships.detect {|m| m.project_id == project.id} | |
|
135 | 129 | end |
|
136 | 130 | |
|
137 | 131 | def pref |
General Comments 0
You need to be logged in to leave comments.
Login now