##// END OF EJS Templates
Declare safe attributes for User and Projects models....
Jean-Philippe Lang -
r4378:a4d7a99c22d9
parent child
Show More
@@ -53,7 +53,7 class MyController < ApplicationController
53 @user = User.current
53 @user = User.current
54 @pref = @user.pref
54 @pref = @user.pref
55 if request.post?
55 if request.post?
56 @user.attributes = params[:user]
56 @user.safe_attributes = params[:user]
57 @user.mail_notification = params[:notification_option] || 'only_my_events'
57 @user.mail_notification = params[:notification_option] || 'only_my_events'
58 @user.pref.attributes = params[:pref]
58 @user.pref.attributes = params[:pref]
59 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
59 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
@@ -72,7 +72,8 class ProjectsController < ApplicationController
72 def create
72 def create
73 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
73 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
74 @trackers = Tracker.all
74 @trackers = Tracker.all
75 @project = Project.new(params[:project])
75 @project = Project.new
76 @project.safe_attributes = params[:project]
76
77
77 @project.enabled_module_names = params[:enabled_modules] if params[:enabled_modules]
78 @project.enabled_module_names = params[:enabled_modules] if params[:enabled_modules]
78 if validate_parent_id && @project.save
79 if validate_parent_id && @project.save
@@ -115,7 +116,8 class ProjectsController < ApplicationController
115 end
116 end
116 else
117 else
117 Mailer.with_deliveries(params[:notifications] == '1') do
118 Mailer.with_deliveries(params[:notifications] == '1') do
118 @project = Project.new(params[:project])
119 @project = Project.new
120 @project.safe_attributes = params[:project]
119 @project.enabled_module_names = params[:enabled_modules]
121 @project.enabled_module_names = params[:enabled_modules]
120 if validate_parent_id && @project.copy(@source_project, :only => params[:only])
122 if validate_parent_id && @project.copy(@source_project, :only => params[:only])
121 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
123 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
@@ -181,7 +183,7 class ProjectsController < ApplicationController
181 end
183 end
182
184
183 def update
185 def update
184 @project.attributes = params[:project]
186 @project.safe_attributes = params[:project]
185 if validate_parent_id && @project.save
187 if validate_parent_id && @project.save
186 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
188 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
187 respond_to do |format|
189 respond_to do |format|
@@ -97,7 +97,8 class UsersController < ApplicationController
97 @notification_options = User::MAIL_NOTIFICATION_OPTIONS
97 @notification_options = User::MAIL_NOTIFICATION_OPTIONS
98 @notification_option = Setting.default_notification_option
98 @notification_option = Setting.default_notification_option
99
99
100 @user = User.new(params[:user])
100 @user = User.new
101 @user.safe_attributes = params[:user]
101 @user.admin = params[:user][:admin] || false
102 @user.admin = params[:user][:admin] || false
102 @user.login = params[:user][:login]
103 @user.login = params[:user][:login]
103 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
104 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
@@ -155,7 +156,7 class UsersController < ApplicationController
155 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
156 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
156 end
157 end
157 @user.group_ids = params[:user][:group_ids] if params[:user][:group_ids]
158 @user.group_ids = params[:user][:group_ids] if params[:user][:group_ids]
158 @user.attributes = params[:user]
159 @user.safe_attributes = params[:user]
159 # Was the account actived ? (do it before User#save clears the change)
160 # Was the account actived ? (do it before User#save clears the change)
160 was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
161 was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
161 # TODO: Similar to My#account
162 # TODO: Similar to My#account
@@ -16,6 +16,8
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class Project < ActiveRecord::Base
18 class Project < ActiveRecord::Base
19 include Redmine::SafeAttributes
20
19 # Project statuses
21 # Project statuses
20 STATUS_ACTIVE = 1
22 STATUS_ACTIVE = 1
21 STATUS_ARCHIVED = 9
23 STATUS_ARCHIVED = 9
@@ -520,6 +522,15 class Project < ActiveRecord::Base
520 def enabled_module_names
522 def enabled_module_names
521 enabled_modules.collect(&:name)
523 enabled_modules.collect(&:name)
522 end
524 end
525
526 safe_attributes 'name',
527 'description',
528 'homepage',
529 'is_public',
530 'identifier',
531 'custom_field_values',
532 'custom_fields',
533 'tracker_ids'
523
534
524 # Returns an array of projects that are in this project's hierarchy
535 # Returns an array of projects that are in this project's hierarchy
525 #
536 #
@@ -18,7 +18,8
18 require "digest/sha1"
18 require "digest/sha1"
19
19
20 class User < Principal
20 class User < Principal
21
21 include Redmine::SafeAttributes
22
22 # Account statuses
23 # Account statuses
23 STATUS_ANONYMOUS = 0
24 STATUS_ANONYMOUS = 0
24 STATUS_ACTIVE = 1
25 STATUS_ACTIVE = 1
@@ -390,6 +391,20 class User < Principal
390 def allowed_to_globally?(action, options)
391 def allowed_to_globally?(action, options)
391 allowed_to?(action, nil, options.reverse_merge(:global => true))
392 allowed_to?(action, nil, options.reverse_merge(:global => true))
392 end
393 end
394
395 safe_attributes 'login',
396 'firstname',
397 'lastname',
398 'mail',
399 'mail_notification',
400 'language',
401 'custom_field_values',
402 'custom_fields',
403 'identity_url'
404
405 safe_attributes 'status',
406 'auth_source_id',
407 :if => lambda {|user, current_user| current_user.admin?}
393
408
394 # Utility method to help check if a user should be notified about an
409 # Utility method to help check if a user should be notified about an
395 # event.
410 # event.
@@ -144,19 +144,27 class ProjectsControllerTest < ActionController::TestCase
144 end
144 end
145
145
146 should "create a new project" do
146 should "create a new project" do
147 post :create, :project => { :name => "blog",
147 post :create,
148 :description => "weblog",
148 :project => {
149 :identifier => "blog",
149 :name => "blog",
150 :is_public => 1,
150 :description => "weblog",
151 :custom_field_values => { '3' => 'Beta' }
151 :homepage => 'http://weblog',
152 }
152 :identifier => "blog",
153 :is_public => 1,
154 :custom_field_values => { '3' => 'Beta' },
155 :tracker_ids => ['1', '3']
156 }
153 assert_redirected_to '/projects/blog/settings'
157 assert_redirected_to '/projects/blog/settings'
154
158
155 project = Project.find_by_name('blog')
159 project = Project.find_by_name('blog')
156 assert_kind_of Project, project
160 assert_kind_of Project, project
161 assert project.active?
157 assert_equal 'weblog', project.description
162 assert_equal 'weblog', project.description
163 assert_equal 'http://weblog', project.homepage
158 assert_equal true, project.is_public?
164 assert_equal true, project.is_public?
159 assert_nil project.parent
165 assert_nil project.parent
166 assert_equal 'Beta', project.custom_value_for(3).value
167 assert_equal [1, 3], project.trackers.map(&:id).sort
160 end
168 end
161
169
162 should "create a new subproject" do
170 should "create a new subproject" do
General Comments 0
You need to be logged in to leave comments. Login now