diff options
author | Go MAEDA <maeda@farend.jp> | 2019-08-27 10:44:39 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2019-08-27 10:44:39 +0000 |
commit | c37d1b43a42502399a446108bf40d72d1ab60bef (patch) | |
tree | bf74eb1a9a333f64cffbdf42f99bebfdf10baa9b /app | |
parent | ce831ae5e4acfd6c1d36809aedeb54d23f264288 (diff) | |
download | redmine-c37d1b43a42502399a446108bf40d72d1ab60bef.tar.gz redmine-c37d1b43a42502399a446108bf40d72d1ab60bef.zip |
Reject version custom field values not visible for the user (#31954, #23997).
Patch by Marius BALTEANU.
git-svn-id: http://svn.redmine.org/redmine/trunk@18402 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/models/version.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/models/version.rb b/app/models/version.rb index e538f21b3..b5765f4b8 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -163,11 +163,39 @@ class Version < ActiveRecord::Base 'custom_field_values', 'custom_fields' + def safe_attributes=(attrs, user=User.current) + if attrs.respond_to?(:to_unsafe_hash) + attrs = attrs.to_unsafe_hash + end + + return unless attrs.is_a?(Hash) + attrs = attrs.deep_dup + + # Reject custom fields values not visible by the user + if attrs['custom_field_values'].present? + editable_custom_field_ids = editable_custom_field_values(user).map {|v| v.custom_field_id.to_s} + attrs['custom_field_values'].reject! {|k, v| !editable_custom_field_ids.include?(k.to_s)} + end + + # Reject custom fields not visible by the user + if attrs['custom_fields'].present? + editable_custom_field_ids = editable_custom_field_values(user).map {|v| v.custom_field_id.to_s} + attrs['custom_fields'].reject! {|c| !editable_custom_field_ids.include?(c['id'].to_s)} + end + + super(attrs, user) + end + # Returns true if +user+ or current user is allowed to view the version def visible?(user=User.current) user.allowed_to?(:view_issues, self.project) end + # Returns the custom_field_values that can be edited by the given user + def editable_custom_field_values(user=nil) + visible_custom_field_values(user) + end + def visible_custom_field_values(user = nil) user ||= User.current custom_field_values.select do |value| |