-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.rb
34 lines (29 loc) · 1.13 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
Redmine::Plugin.register :redmine_time_verification do
name 'Redmine Time Verification plugin'
author 'kubkowski'
description 'Simple plugin extending time verification method in TimeEntry model.'
version '0.0.2'
url 'https://github.com/kubkowski/redmine_time_verification'
settings :default => {'enabled' => true}, :partial => 'settings/time_verification'
end
require_dependency 'time_entry'
module TimeVerificationTimeEntry
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
alias_method_chain :validate_time_entry, :new_validation
end
end
module InstanceMethods
# Adds a new validation to time entry model.
def validate_time_entry_with_new_validation
validate_time_entry_without_new_validation
if Setting.plugin_redmine_time_verification['enabled']
errors.add :spent_on, "is too early" if (spent_on < Date.today - 1.day)
errors.add :hours, "is too many" if hours && hours >= 16
end
end
end
end
TimeEntry.send(:include, TimeVerificationTimeEntry)