To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 02 / 020539cf91037b37b7739ed19a56c058529a8860.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (1.71 KB)
| 1 | 1296:038ba2d95de8 | Chris | # Redmine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
||
| 3 | # |
||
| 4 | # This program is free software; you can redistribute it and/or |
||
| 5 | # modify it under the terms of the GNU General Public License |
||
| 6 | # as published by the Free Software Foundation; either version 2 |
||
| 7 | # of the License, or (at your option) any later version. |
||
| 8 | # |
||
| 9 | # This program is distributed in the hope that it will be useful, |
||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 12 | # GNU General Public License for more details. |
||
| 13 | # |
||
| 14 | # You should have received a copy of the GNU General Public License |
||
| 15 | # along with this program; if not, write to the Free Software |
||
| 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||
| 17 | |||
| 18 | class WorkflowPermission < WorkflowRule |
||
| 19 | validates_inclusion_of :rule, :in => %w(readonly required) |
||
| 20 | validate :validate_field_name |
||
| 21 | |||
| 22 | # Replaces the workflow permissions for the given tracker and role |
||
| 23 | # |
||
| 24 | # Example: |
||
| 25 | # WorkflowPermission.replace_permissions role, tracker, {'due_date' => {'1' => 'readonly', '2' => 'required'}}
|
||
| 26 | def self.replace_permissions(tracker, role, permissions) |
||
| 27 | destroy_all(:tracker_id => tracker.id, :role_id => role.id) |
||
| 28 | |||
| 29 | permissions.each { |field, rule_by_status_id|
|
||
| 30 | rule_by_status_id.each { |status_id, rule|
|
||
| 31 | if rule.present? |
||
| 32 | WorkflowPermission.create(:role_id => role.id, :tracker_id => tracker.id, :old_status_id => status_id, :field_name => field, :rule => rule) |
||
| 33 | end |
||
| 34 | } |
||
| 35 | } |
||
| 36 | end |
||
| 37 | |||
| 38 | protected |
||
| 39 | |||
| 40 | def validate_field_name |
||
| 41 | unless Tracker::CORE_FIELDS_ALL.include?(field_name) || field_name.to_s.match(/^\d+$/) |
||
| 42 | errors.add :field_name, :invalid |
||
| 43 | end |
||
| 44 | end |
||
| 45 | end |