ruby-on-railsredmineredmine-plugins

Redmine spent time tracking restriction


We recently installed Redmine in our organization.

I would like to know how to only allow a user to track spent time only for past 3 days.

e.g. If today is 21 May 2018 then a user can only track time for 18,19,20 & 21 May 2018. A user can not track time for 15th May 2018

There are any plugins on need to add validation in database script or something else.

Thanks in advance.


Solution

  • I added to our in-house Redmine plugin a validation to restrict TimeEntry#hours to 8 hours. The actual lines are just a standard ActiveRecord validation:

        base.class_eval do
          validate :revalidate_time_entry
        end
    

    ...

        def revalidate_time_entry
          if hours && hours >= 0 && hours < 1000  #  Dodge the original validation
            errors.add :hours, :invalid if hours > 8
          end
        end
    

    The base.class_eval is part of a patch on the TimeEntry class, in a plugin. Download nearly any Redmine plugin and read its ./lib/*/patches folder to learn how to patch. You need a validation on your spent_on field that it is > 3.days.ago.

    Here's an example of a Redmine plugin that patches TimeEntry and adds a validation:

    https://searchcode.com/file/11439509/tags/0.1/lib/cmi/time_entry_patch.rb

    Ask here if you get stuck on anything.