@@ -1,46 +1,52 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | module Redmine |
|
18 | module Redmine | |
19 | module Activity |
|
19 | module Activity | |
20 |
|
20 | |||
21 | mattr_accessor :available_event_types, :default_event_types, :providers |
|
21 | mattr_accessor :available_event_types, :default_event_types, :providers | |
22 |
|
22 | |||
23 | @@available_event_types = [] |
|
23 | @@available_event_types = [] | |
24 | @@default_event_types = [] |
|
24 | @@default_event_types = [] | |
25 | @@providers = Hash.new {|h,k| h[k]=[] } |
|
25 | @@providers = Hash.new {|h,k| h[k]=[] } | |
26 |
|
26 | |||
27 | class << self |
|
27 | class << self | |
28 | def map(&block) |
|
28 | def map(&block) | |
29 | yield self |
|
29 | yield self | |
30 | end |
|
30 | end | |
31 |
|
31 | |||
32 | # Registers an activity provider |
|
32 | # Registers an activity provider | |
33 | def register(event_type, options={}) |
|
33 | def register(event_type, options={}) | |
34 | options.assert_valid_keys(:class_name, :default) |
|
34 | options.assert_valid_keys(:class_name, :default) | |
35 |
|
35 | |||
36 | event_type = event_type.to_s |
|
36 | event_type = event_type.to_s | |
37 | providers = options[:class_name] || event_type.classify |
|
37 | providers = options[:class_name] || event_type.classify | |
38 | providers = ([] << providers) unless providers.is_a?(Array) |
|
38 | providers = ([] << providers) unless providers.is_a?(Array) | |
39 |
|
39 | |||
40 | @@available_event_types << event_type unless @@available_event_types.include?(event_type) |
|
40 | @@available_event_types << event_type unless @@available_event_types.include?(event_type) | |
41 | @@default_event_types << event_type unless options[:default] == false |
|
41 | @@default_event_types << event_type unless options[:default] == false | |
42 | @@providers[event_type] += providers |
|
42 | @@providers[event_type] += providers | |
43 | end |
|
43 | end | |
|
44 | ||||
|
45 | def delete(event_type) | |||
|
46 | @@available_event_types.delete event_type | |||
|
47 | @@default_event_types.delete event_type | |||
|
48 | @@providers.delete(event_type) | |||
|
49 | end | |||
44 | end |
|
50 | end | |
45 | end |
|
51 | end | |
46 | end |
|
52 | end |
@@ -1,95 +1,110 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | module Redmine |
|
18 | module Redmine | |
19 | module Activity |
|
19 | module Activity | |
20 | # Class used to retrieve activity events |
|
20 | # Class used to retrieve activity events | |
21 | class Fetcher |
|
21 | class Fetcher | |
22 | attr_reader :user, :project, :scope |
|
22 | attr_reader :user, :project, :scope | |
23 |
|
23 | |||
24 | # Needs to be unloaded in development mode |
|
|||
25 | @@constantized_providers = Hash.new {|h,k| h[k] = Redmine::Activity.providers[k].collect {|t| t.constantize } } |
|
|||
26 |
|
||||
27 | def initialize(user, options={}) |
|
24 | def initialize(user, options={}) | |
28 | options.assert_valid_keys(:project, :with_subprojects, :author) |
|
25 | options.assert_valid_keys(:project, :with_subprojects, :author) | |
29 | @user = user |
|
26 | @user = user | |
30 | @project = options[:project] |
|
27 | @project = options[:project] | |
31 | @options = options |
|
28 | @options = options | |
32 |
|
29 | |||
33 | @scope = event_types |
|
30 | @scope = event_types | |
34 | end |
|
31 | end | |
35 |
|
32 | |||
36 | # Returns an array of available event types |
|
33 | # Returns an array of available event types | |
37 | def event_types |
|
34 | def event_types | |
38 | return @event_types unless @event_types.nil? |
|
35 | return @event_types unless @event_types.nil? | |
39 |
|
36 | |||
40 | @event_types = Redmine::Activity.available_event_types |
|
37 | @event_types = Redmine::Activity.available_event_types | |
41 | @event_types = @event_types.select {|o| @project.self_and_descendants.detect {|p| @user.allowed_to?("view_#{o}".to_sym, p)}} if @project |
|
38 | if @project | |
|
39 | projects = @project.self_and_descendants | |||
|
40 | @event_types = @event_types.select do |event_type| | |||
|
41 | keep = false | |||
|
42 | constantized_providers(event_type).each do |provider| | |||
|
43 | options = provider.activity_provider_options[event_type] | |||
|
44 | permission = options[:permission] | |||
|
45 | unless options.key?(:permission) | |||
|
46 | permission ||= "view_#{event_type}".to_sym | |||
|
47 | end | |||
|
48 | if permission | |||
|
49 | keep |= projects.any? {|p| @user.allowed_to?(permission, p)} | |||
|
50 | else | |||
|
51 | keep = true | |||
|
52 | end | |||
|
53 | end | |||
|
54 | keep | |||
|
55 | end | |||
|
56 | end | |||
42 | @event_types |
|
57 | @event_types | |
43 | end |
|
58 | end | |
44 |
|
59 | |||
45 | # Yields to filter the activity scope |
|
60 | # Yields to filter the activity scope | |
46 | def scope_select(&block) |
|
61 | def scope_select(&block) | |
47 | @scope = @scope.select {|t| yield t } |
|
62 | @scope = @scope.select {|t| yield t } | |
48 | end |
|
63 | end | |
49 |
|
64 | |||
50 | # Sets the scope |
|
65 | # Sets the scope | |
51 | # Argument can be :all, :default or an array of event types |
|
66 | # Argument can be :all, :default or an array of event types | |
52 | def scope=(s) |
|
67 | def scope=(s) | |
53 | case s |
|
68 | case s | |
54 | when :all |
|
69 | when :all | |
55 | @scope = event_types |
|
70 | @scope = event_types | |
56 | when :default |
|
71 | when :default | |
57 | default_scope! |
|
72 | default_scope! | |
58 | else |
|
73 | else | |
59 | @scope = s & event_types |
|
74 | @scope = s & event_types | |
60 | end |
|
75 | end | |
61 | end |
|
76 | end | |
62 |
|
77 | |||
63 | # Resets the scope to the default scope |
|
78 | # Resets the scope to the default scope | |
64 | def default_scope! |
|
79 | def default_scope! | |
65 | @scope = Redmine::Activity.default_event_types |
|
80 | @scope = Redmine::Activity.default_event_types | |
66 | end |
|
81 | end | |
67 |
|
82 | |||
68 | # Returns an array of events for the given date range |
|
83 | # Returns an array of events for the given date range | |
69 | # sorted in reverse chronological order |
|
84 | # sorted in reverse chronological order | |
70 | def events(from = nil, to = nil, options={}) |
|
85 | def events(from = nil, to = nil, options={}) | |
71 | e = [] |
|
86 | e = [] | |
72 | @options[:limit] = options[:limit] |
|
87 | @options[:limit] = options[:limit] | |
73 |
|
88 | |||
74 | @scope.each do |event_type| |
|
89 | @scope.each do |event_type| | |
75 | constantized_providers(event_type).each do |provider| |
|
90 | constantized_providers(event_type).each do |provider| | |
76 | e += provider.find_events(event_type, @user, from, to, @options) |
|
91 | e += provider.find_events(event_type, @user, from, to, @options) | |
77 | end |
|
92 | end | |
78 | end |
|
93 | end | |
79 |
|
94 | |||
80 | e.sort! {|a,b| b.event_datetime <=> a.event_datetime} |
|
95 | e.sort! {|a,b| b.event_datetime <=> a.event_datetime} | |
81 |
|
96 | |||
82 | if options[:limit] |
|
97 | if options[:limit] | |
83 | e = e.slice(0, options[:limit]) |
|
98 | e = e.slice(0, options[:limit]) | |
84 | end |
|
99 | end | |
85 | e |
|
100 | e | |
86 | end |
|
101 | end | |
87 |
|
102 | |||
88 | private |
|
103 | private | |
89 |
|
104 | |||
90 | def constantized_providers(event_type) |
|
105 | def constantized_providers(event_type) | |
91 | @@constantized_providers[event_type] |
|
106 | Redmine::Activity.providers[event_type].map(&:constantize) | |
92 | end |
|
107 | end | |
93 | end |
|
108 | end | |
94 | end |
|
109 | end | |
95 | end |
|
110 | end |
@@ -1,129 +1,189 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class ActivityTest < ActiveSupport::TestCase |
|
20 | class ActivityTest < ActiveSupport::TestCase | |
21 | fixtures :projects, :versions, :attachments, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details, |
|
21 | fixtures :projects, :versions, :attachments, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details, | |
22 | :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages, :time_entries, |
|
22 | :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages, :time_entries, | |
23 | :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions |
|
23 | :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions | |
24 |
|
24 | |||
25 | def setup |
|
25 | def setup | |
26 | @project = Project.find(1) |
|
26 | @project = Project.find(1) | |
27 | end |
|
27 | end | |
28 |
|
28 | |||
29 | def test_activity_without_subprojects |
|
29 | def test_activity_without_subprojects | |
30 | events = find_events(User.anonymous, :project => @project) |
|
30 | events = find_events(User.anonymous, :project => @project) | |
31 | assert_not_nil events |
|
31 | assert_not_nil events | |
32 |
|
32 | |||
33 | assert events.include?(Issue.find(1)) |
|
33 | assert events.include?(Issue.find(1)) | |
34 | assert !events.include?(Issue.find(4)) |
|
34 | assert !events.include?(Issue.find(4)) | |
35 | # subproject issue |
|
35 | # subproject issue | |
36 | assert !events.include?(Issue.find(5)) |
|
36 | assert !events.include?(Issue.find(5)) | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
39 | def test_activity_with_subprojects |
|
39 | def test_activity_with_subprojects | |
40 | events = find_events(User.anonymous, :project => @project, :with_subprojects => 1) |
|
40 | events = find_events(User.anonymous, :project => @project, :with_subprojects => 1) | |
41 | assert_not_nil events |
|
41 | assert_not_nil events | |
42 |
|
42 | |||
43 | assert events.include?(Issue.find(1)) |
|
43 | assert events.include?(Issue.find(1)) | |
44 | # subproject issue |
|
44 | # subproject issue | |
45 | assert events.include?(Issue.find(5)) |
|
45 | assert events.include?(Issue.find(5)) | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | def test_global_activity_anonymous |
|
48 | def test_global_activity_anonymous | |
49 | events = find_events(User.anonymous) |
|
49 | events = find_events(User.anonymous) | |
50 | assert_not_nil events |
|
50 | assert_not_nil events | |
51 |
|
51 | |||
52 | assert events.include?(Issue.find(1)) |
|
52 | assert events.include?(Issue.find(1)) | |
53 | assert events.include?(Message.find(5)) |
|
53 | assert events.include?(Message.find(5)) | |
54 | # Issue of a private project |
|
54 | # Issue of a private project | |
55 | assert !events.include?(Issue.find(4)) |
|
55 | assert !events.include?(Issue.find(4)) | |
56 | # Private issue and comment |
|
56 | # Private issue and comment | |
57 | assert !events.include?(Issue.find(14)) |
|
57 | assert !events.include?(Issue.find(14)) | |
58 | assert !events.include?(Journal.find(5)) |
|
58 | assert !events.include?(Journal.find(5)) | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def test_global_activity_logged_user |
|
61 | def test_global_activity_logged_user | |
62 | events = find_events(User.find(2)) # manager |
|
62 | events = find_events(User.find(2)) # manager | |
63 | assert_not_nil events |
|
63 | assert_not_nil events | |
64 |
|
64 | |||
65 | assert events.include?(Issue.find(1)) |
|
65 | assert events.include?(Issue.find(1)) | |
66 | # Issue of a private project the user belongs to |
|
66 | # Issue of a private project the user belongs to | |
67 | assert events.include?(Issue.find(4)) |
|
67 | assert events.include?(Issue.find(4)) | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | def test_user_activity |
|
70 | def test_user_activity | |
71 | user = User.find(2) |
|
71 | user = User.find(2) | |
72 | events = Redmine::Activity::Fetcher.new(User.anonymous, :author => user).events(nil, nil, :limit => 10) |
|
72 | events = Redmine::Activity::Fetcher.new(User.anonymous, :author => user).events(nil, nil, :limit => 10) | |
73 |
|
73 | |||
74 | assert(events.size > 0) |
|
74 | assert(events.size > 0) | |
75 | assert(events.size <= 10) |
|
75 | assert(events.size <= 10) | |
76 | assert_nil(events.detect {|e| e.event_author != user}) |
|
76 | assert_nil(events.detect {|e| e.event_author != user}) | |
77 | end |
|
77 | end | |
78 |
|
78 | |||
79 | def test_files_activity |
|
79 | def test_files_activity | |
80 | f = Redmine::Activity::Fetcher.new(User.anonymous, :project => Project.find(1)) |
|
80 | f = Redmine::Activity::Fetcher.new(User.anonymous, :project => Project.find(1)) | |
81 | f.scope = ['files'] |
|
81 | f.scope = ['files'] | |
82 | events = f.events |
|
82 | events = f.events | |
83 |
|
83 | |||
84 | assert_kind_of Array, events |
|
84 | assert_kind_of Array, events | |
85 | assert events.include?(Attachment.find_by_container_type_and_container_id('Project', 1)) |
|
85 | assert events.include?(Attachment.find_by_container_type_and_container_id('Project', 1)) | |
86 | assert events.include?(Attachment.find_by_container_type_and_container_id('Version', 1)) |
|
86 | assert events.include?(Attachment.find_by_container_type_and_container_id('Version', 1)) | |
87 | assert_equal [Attachment], events.collect(&:class).uniq |
|
87 | assert_equal [Attachment], events.collect(&:class).uniq | |
88 | assert_equal %w(Project Version), events.collect(&:container_type).uniq.sort |
|
88 | assert_equal %w(Project Version), events.collect(&:container_type).uniq.sort | |
89 | end |
|
89 | end | |
90 |
|
90 | |||
91 | def test_event_group_for_issue |
|
91 | def test_event_group_for_issue | |
92 | issue = Issue.find(1) |
|
92 | issue = Issue.find(1) | |
93 | assert_equal issue, issue.event_group |
|
93 | assert_equal issue, issue.event_group | |
94 | end |
|
94 | end | |
95 |
|
95 | |||
96 | def test_event_group_for_journal |
|
96 | def test_event_group_for_journal | |
97 | issue = Issue.find(1) |
|
97 | issue = Issue.find(1) | |
98 | journal = issue.journals.first |
|
98 | journal = issue.journals.first | |
99 | assert_equal issue, journal.event_group |
|
99 | assert_equal issue, journal.event_group | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | def test_event_group_for_issue_time_entry |
|
102 | def test_event_group_for_issue_time_entry | |
103 | time = TimeEntry.where(:issue_id => 1).first |
|
103 | time = TimeEntry.where(:issue_id => 1).first | |
104 | assert_equal time.issue, time.event_group |
|
104 | assert_equal time.issue, time.event_group | |
105 | end |
|
105 | end | |
106 |
|
106 | |||
107 | def test_event_group_for_project_time_entry |
|
107 | def test_event_group_for_project_time_entry | |
108 | time = TimeEntry.where(:issue_id => nil).first |
|
108 | time = TimeEntry.where(:issue_id => nil).first | |
109 | assert_equal time, time.event_group |
|
109 | assert_equal time, time.event_group | |
110 | end |
|
110 | end | |
111 |
|
111 | |||
112 | def test_event_group_for_message |
|
112 | def test_event_group_for_message | |
113 | message = Message.find(1) |
|
113 | message = Message.find(1) | |
114 | reply = message.children.first |
|
114 | reply = message.children.first | |
115 | assert_equal message, message.event_group |
|
115 | assert_equal message, message.event_group | |
116 | assert_equal message, reply.event_group |
|
116 | assert_equal message, reply.event_group | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | def test_event_group_for_wiki_content_version |
|
119 | def test_event_group_for_wiki_content_version | |
120 | content = WikiContent::Version.find(1) |
|
120 | content = WikiContent::Version.find(1) | |
121 | assert_equal content.page, content.event_group |
|
121 | assert_equal content.page, content.event_group | |
122 | end |
|
122 | end | |
123 |
|
123 | |||
|
124 | class TestActivityProviderWithPermission | |||
|
125 | def self.activity_provider_options | |||
|
126 | {'test' => {:permission => :custom_permission}} | |||
|
127 | end | |||
|
128 | end | |||
|
129 | ||||
|
130 | class TestActivityProviderWithNilPermission | |||
|
131 | def self.activity_provider_options | |||
|
132 | {'test' => {:permission => nil}} | |||
|
133 | end | |||
|
134 | end | |||
|
135 | ||||
|
136 | class TestActivityProviderWithoutPermission | |||
|
137 | def self.activity_provider_options | |||
|
138 | {'test' => {}} | |||
|
139 | end | |||
|
140 | end | |||
|
141 | ||||
|
142 | class MockUser | |||
|
143 | def initialize(*permissions) | |||
|
144 | @permissions = permissions | |||
|
145 | end | |||
|
146 | ||||
|
147 | def allowed_to?(permission, *args) | |||
|
148 | @permissions.include?(permission) | |||
|
149 | end | |||
|
150 | end | |||
|
151 | ||||
|
152 | def test_event_types_should_consider_activity_provider_permission | |||
|
153 | Redmine::Activity.register 'test', :class_name => 'ActivityTest::TestActivityProviderWithPermission' | |||
|
154 | user = MockUser.new(:custom_permission) | |||
|
155 | f = Redmine::Activity::Fetcher.new(user, :project => Project.find(1)) | |||
|
156 | assert_include 'test', f.event_types | |||
|
157 | ensure | |||
|
158 | Redmine::Activity.delete 'test' | |||
|
159 | end | |||
|
160 | ||||
|
161 | def test_event_types_should_include_activity_provider_with_nil_permission | |||
|
162 | Redmine::Activity.register 'test', :class_name => 'ActivityTest::TestActivityProviderWithNilPermission' | |||
|
163 | user = MockUser.new() | |||
|
164 | f = Redmine::Activity::Fetcher.new(user, :project => Project.find(1)) | |||
|
165 | assert_include 'test', f.event_types | |||
|
166 | ensure | |||
|
167 | Redmine::Activity.delete 'test' | |||
|
168 | end | |||
|
169 | ||||
|
170 | def test_event_types_should_use_default_permission_for_activity_provider_without_permission | |||
|
171 | Redmine::Activity.register 'test', :class_name => 'ActivityTest::TestActivityProviderWithoutPermission' | |||
|
172 | ||||
|
173 | user = MockUser.new() | |||
|
174 | f = Redmine::Activity::Fetcher.new(user, :project => Project.find(1)) | |||
|
175 | assert_not_include 'test', f.event_types | |||
|
176 | ||||
|
177 | user = MockUser.new(:view_test) | |||
|
178 | f = Redmine::Activity::Fetcher.new(user, :project => Project.find(1)) | |||
|
179 | assert_include 'test', f.event_types | |||
|
180 | ensure | |||
|
181 | Redmine::Activity.delete 'test' | |||
|
182 | end | |||
|
183 | ||||
124 | private |
|
184 | private | |
125 |
|
185 | |||
126 | def find_events(user, options={}) |
|
186 | def find_events(user, options={}) | |
127 | Redmine::Activity::Fetcher.new(user, options).events(Date.today - 30, Date.today + 1) |
|
187 | Redmine::Activity::Fetcher.new(user, options).events(Date.today - 30, Date.today + 1) | |
128 | end |
|
188 | end | |
129 | end |
|
189 | end |
General Comments 0
You need to be logged in to leave comments.
Login now