forked from hicknhack-software/redmine_time_tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.rb
146 lines (129 loc) · 8.83 KB
/
init.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# encoding: utf-8
Rails.logger.info 'Starting Time Tracker plugin for RedMine'
ActiveSupport::Dependencies.autoload_paths << File.join(File.dirname(__FILE__), 'app/concerns')
require 'redmine'
require 'tt_user_patch'
require 'tt_project_patch'
require 'tt_issue_patch'
require 'tt_time_entry_patch'
require 'tt_main_menu'
require 'tt_context_menus_controller_patch'
# workaround helping rails to find the helper-methods
require File.join(File.dirname(__FILE__), 'app/helpers/application_helper.rb')
# TODO rails 3.2 has assets-directories as sub-dirs in app, lib and vendor => maybe we should organize our assets that way!
require_dependency 'tt_time_tracker_hooks'
Redmine::Plugin.register :redmine_time_tracker do
name 'Redmine Time Tracker plugin'
url 'https://github.com/hicknhack-software/redmine_time_tracker'
author 'HicknHack Software GmbH'
author_url 'http://www.hicknhack-software.com'
description 'Keep track of all the time. Associate it at your will. Create and print custom reports.'
version '0.7.0'
requires_redmine :version_or_higher => '2.3.1'
#settings :default => {:refresh_rate => '60', :status_transitions => {}}, :partial => 'settings/time_tracker'
settings :default => {:report_title => 'Report', :report_logo_url => '', :report_logo_width => '150'}, :partial => 'settings/time_tracker'
Redmine::AccessControl.map do |map|
map.project_module :redmine_timetracker_plugin do
# start/stop trackers, view own timeLogs, partially edit own timeLogs (issue, comments)
map.permission :tt_log_time, {:time_logs => [:actions, :get_list_entry, :show_edit],
:tt_completer => [:get_issue, :get_issue_id, :get_issue_subject],
:tt_info => [:index],
:tt_overview => [:index],
:time_trackers => [:start, :stop, :update]},
:require => :loggedin
# all from :tt_log_time + completely edit own timeLogs
map.permission :tt_edit_own_time_logs, {:time_logs => [:actions, :delete, :get_list_entry, :show_edit],
:tt_completer => [:get_issue, :get_issue_id, :get_issue_subject],
:tt_logs_list => [:index],
:tt_info => [:index],
:tt_overview => [:index],
:time_trackers => [:delete, :start, :stop, :update]},
:require => :loggedin
# all from :tt_edit_own_time_logs + completely edit foreign timeLogs
map.permission :tt_edit_time_logs, {:time_logs => [:actions, :delete, :get_list_entry, :show_edit],
:tt_completer => [:get_issue, :get_issue_id, :get_issue_subject],
:tt_date_shifter => [:get_next_time_span, :get_prev_time_span],
:tt_logs_list => [:index],
:tt_info => [:index],
:tt_overview => [:index],
:time_trackers => [:delete, :start, :stop, :update]},
:require => :loggedin
# view only reports-page (view all foreign timeBookings)
map.permission :tt_view_bookings, {:time_bookings => [:get_list_entry],
:tt_date_shifter => [:get_next_time_span, :get_prev_time_span],
:tt_reporting => [:index, :print_report]},
:require => :loggedin
# book time, view own timeBookings, partially edit own timeBookings (issue, comments, project)
map.permission :tt_book_time, {:time_bookings => [:actions, :get_list_entry, :show_edit, :update],
:time_logs => [:show_booking],
:tt_bookings_list => [:index],
:tt_completer => [:get_issue, :get_issue_id, :get_issue_subject],
:tt_date_shifter => [:get_next_time_span, :get_prev_time_span],
:tt_info => [:index],
:tt_overview => [:index],
:tt_reporting => [:index, :print_report]},
:require => :loggedin
# all from :tt_book_time + completely edit own timBookings
map.permission :tt_edit_own_bookings, {:time_bookings => [:actions, :delete, :get_list_entry, :show_edit, :update],
:time_logs => [:show_booking],
:tt_bookings_list => [:index],
:tt_completer => [:get_issue, :get_issue_id, :get_issue_subject],
:tt_date_shifter => [:get_next_time_span, :get_prev_time_span],
:tt_info => [:index],
:tt_overview => [:index],
:tt_reporting => [:index, :print_report]},
:require => :loggedin
# all from :tt_edit_own_bookings + completely edit foreign timeBookings
map.permission :tt_edit_bookings, {:time_bookings => [:actions, :delete, :get_list_entry, :show_edit, :update],
:time_logs => [:show_booking],
:tt_bookings_list => [:index],
:tt_completer => [:get_issue, :get_issue_id, :get_issue_subject],
:tt_date_shifter => [:get_next_time_span, :get_prev_time_span],
:tt_info => [:index],
:tt_overview => [:index],
:tt_reporting => [:index, :print_report]},
:require => :loggedin
# only admin can
# :time_logs_queries => [:edit, :show, :update, :create, :destroy],
# :time_bookings_queries => [:edit, :show, :update, :create, :destroy],
end
end
def permission_checker(permission_list)
proc {
flag = false
permission_list.each { |permission|
flag ||= User.current.allowed_to_globally?(permission, {})
}
flag
}
end
# setup an menu entry into the redmine top-menu on the upper left corner
menu :top_menu, :time_tracker_main_menu, {:controller => 'tt_menu_switcher', :action => 'index'}, :caption => :time_tracker_label_main_menu,
# if the user has one or more of the permissions declared within this Plug-In, he should see the "TimeTracker"-Menu
:if => permission_checker([:tt_log_time, :tt_edit_own_time_logs, :tt_edit_time_logs, :tt_view_bookings, :tt_book_time, :tt_edit_own_bookings, :tt_edit_bookings])
Redmine::MenuManager.map :timetracker_menu do |menu|
menu.push :time_tracker_menu_tab_overview, {:controller => 'tt_overview', :action => 'index'}, :caption => :time_tracker_label_menu_tab_overview,
:if => permission_checker([:tt_log_time, :tt_edit_own_time_logs, :tt_edit_time_logs, :tt_book_time, :tt_edit_own_bookings, :tt_edit_bookings])
menu.push :time_tracker_menu_tab_bookings_list, {:controller => 'tt_bookings_list', :action => 'index'}, :caption => :time_tracker_label_menu_tab_bookings_list,
:if => permission_checker([:tt_book_time, :tt_edit_own_bookings, :tt_edit_bookings])
menu.push :time_tracker_menu_tab_logs_list, {:controller => 'tt_logs_list', :action => 'index'}, :caption => :time_tracker_label_menu_tab_logs_list,
:if => permission_checker([:tt_edit_own_time_logs, :tt_edit_time_logs])
menu.push :time_tracker_menu_tab_active_trackers, {:controller => 'tt_info', :action => 'index'}, :caption => :time_tracker_label_menu_tab_active_trackers,
:if => permission_checker([:tt_log_time, :tt_edit_own_time_logs, :tt_edit_time_logs, :tt_book_time, :tt_edit_own_bookings, :tt_edit_bookings])
menu.push :time_tracker_menu_tab_reporting, {:controller => 'tt_reporting', :action => 'index'}, :caption => :time_tracker_label_menu_tab_reports,
:if => permission_checker([:tt_view_bookings, :tt_book_time, :tt_edit_own_bookings, :tt_edit_bookings])
end
end
# Helper access from the model
class TTHelper
# TODO check for Singleton. seems not be used if included like this:
# code is original from redmine_time_tracker-plugin
include Singleton
include TimeTrackersHelper
end
# to call helper methods from the model use help.<helper_method>
# in the controllers, the TimeTrackerHelper was included separately, so all methods can be called without any prefix
# that is necessary to make variables like params[] available to the helper-methods
def help
TTHelper.instance
end