Project

General

Profile

Actions

Feature #13244

open

Restrict log time for old days

Added by Pavel Potcheptsov almost 12 years ago. Updated 6 days ago.

Status:
Reopened
Priority:
Normal
Assignee:
-
Category:
Time tracking
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:

Description

For example any user have to log his spent time today or tomorrow.
If he try to log time for period more than yesterday - it should be not possible.
There are kind of users that sometimes log their time for period weeks ago and this is bad.
Is there any suggestion how to prevent such things.


Files

time_entry.patch (460 Bytes) time_entry.patch Pavel Potcheptsov, 2013-11-14 14:29
time_entry.diff (1.42 KB) time_entry.diff Pavel Potcheptsov, 2016-08-30 10:30
issue_13244.patch (8.78 KB) issue_13244.patch Ashwin Date, 2019-11-27 08:43
issue_13244.patch (8.78 KB) issue_13244.patch Ashwin Date, 2019-11-27 08:58
clipboard-202408131924-kdik4.png (84.6 KB) clipboard-202408131924-kdik4.png Go MAEDA, 2024-08-13 12:24
clipboard-202408131925-appd3.png (63.9 KB) clipboard-202408131925-appd3.png Go MAEDA, 2024-08-13 12:25
13244.patch (3.84 KB) 13244.patch Go MAEDA, 2024-08-13 12:27
0001-Setting-to-restrict-adding-editing-deleting-log-time.patch (7.81 KB) 0001-Setting-to-restrict-adding-editing-deleting-log-time.patch Marius BĂLTEANU, 2024-08-13 21:37
clipboard-202412091647-xgjdu.png (12.3 KB) clipboard-202412091647-xgjdu.png Jens Krämer, 2024-12-09 09:47
0001-project-setting-to-deny-time-logging-on-closed-issue.patch (10.4 KB) 0001-project-setting-to-deny-time-logging-on-closed-issue.patch Jens Krämer, 2024-12-09 09:48
0001-Rework patch-from-13244.patch (4.68 KB) 0001-Rework patch-from-13244.patch Marius BĂLTEANU, 2024-12-11 23:35

Related issues

Related to Redmine - Feature #3322: Setting to restrict spent times on future datesClosedGo MAEDA2009-05-08

Actions
Related to Redmine - Feature #28308: validation at date of spent timeNew

Actions
Related to Redmine - Feature #13596: Allow time logging only for open issuesNewMarius BĂLTEANU

Actions
Has duplicate Redmine - Feature #31984: Permission to add timelogs in pastClosed

Actions
Actions #1

Updated by Jan Niggemann (redmine.org team member) almost 12 years ago

We need it the other way round and have to be able to log time for weeks ago...
It would need to be configurable.

Actions #2

Updated by Filou Centrinov almost 12 years ago

+1 Good idea restricting log time. But I would restrict only for closed issues: #13596

Actions #3

Updated by Filou Centrinov over 11 years ago

  • Related to Feature #13596: Allow time logging only for open issues added
Actions #4

Updated by Pavel Potcheptsov about 11 years ago

someone has been successful in this?

Actions #5

Updated by Pavel Potcheptsov about 11 years ago

Actions #6

Updated by Go MAEDA over 8 years ago

  • Status changed from Resolved to New
Actions #7

Updated by Go MAEDA over 8 years ago

  • Has duplicate Defect #14840: Time logging shouldn't be possible for the future periods added
Actions #8

Updated by Go MAEDA over 8 years ago

  • Has duplicate Feature #3322: Setting to restrict spent times on future dates added
Actions #9

Updated by Go MAEDA over 8 years ago

  • Has duplicate deleted (Feature #3322: Setting to restrict spent times on future dates)
Actions #10

Updated by Go MAEDA over 8 years ago

  • Is duplicate of Feature #3322: Setting to restrict spent times on future dates added
Actions #11

Updated by Go MAEDA over 8 years ago

  • Has duplicate deleted (Defect #14840: Time logging shouldn't be possible for the future periods)
Actions #12

Updated by Go MAEDA over 8 years ago

  • Status changed from New to Closed
  • Resolution set to Duplicate

Closing as a duplicate of #3322.

Actions #13

Updated by Toshi MARUYAMA over 8 years ago

  • Related to deleted (Feature #13596: Allow time logging only for open issues)
Actions #14

Updated by Toshi MARUYAMA over 8 years ago

  • Related to Feature #13596: Allow time logging only for open issues added
Actions #15

Updated by Toshi MARUYAMA over 8 years ago

  • Related to deleted (Feature #13596: Allow time logging only for open issues)
Actions #16

Updated by Pavel Potcheptsov over 8 years ago

Last line in diff gives ability to restrict log time for specified number of days and exclude specific users from this restriction.

Actions #17

Updated by Toshi MARUYAMA over 8 years ago

Pavel Potcheptsov wrote:

Last line in diff gives ability to restrict log time for specified number of days and exclude specific users from this restriction.

I have noted at #3322#note-11 because this issue is closed as duplicate.

Actions #18

Updated by Kirill Marchuk over 7 years ago

Why is this considered a duplicate ? This is a totally legitimate and self-standing use case: for some projects, I want to have a strict discipline in regards with spent time logging. So I want to be sure that the users on this project are allowed to log time ONLY for today AND X working days before (where X most probably equals to 1)

Does anyone know of a plugin that would allow for such functionality? Or might it be included in Redmine itself ?

Actions #19

Updated by Pavel Potcheptsov over 7 years ago

  • Status changed from Closed to Reopened

Kirill Marchuk wrote:

Why is this considered a duplicate?

Agree.

Does anyone know of a plugin that would allow for such functionality? Or might it be included in Redmine itself ?

At least current patch allow this for all projects.
There might be some general system wide setting for this and dedicated per each project setting.

Actions #20

Updated by Kirill Marchuk over 7 years ago

any chances this will be merged into redmine [soon] ?

Actions #21

Updated by Kirill Marchuk over 7 years ago

hello, anyone ? does Redmine have a community ?

Actions #22

Updated by Kirill Marchuk over 7 years ago

pavel ochman, may be you can change "resolution" for this issue ?

Actions #23

Updated by Pavel Potcheptsov over 7 years ago

No I can't.

Actions #24

Updated by Kirill Marchuk over 7 years ago

is there anyone alive here ? why are patches ignored ? Man spent his time and effort into it, he deserves at least a reaction !!!

Actions #25

Updated by Kirill Marchuk over 7 years ago

well, I've seen the patch finally ))

this is NOT something that's possible to merge into upstream. just a couple of hard-coded validation checks.

Proper implementation would require a per-project setting of:
  • is time logging restricted for this project at all
  • how many days in the past are allowed to log time on (0 is minimum, which means you can only log time on today)

if this sounds bad, please leave your comments

Actions #26

Updated by Toshi MARUYAMA over 7 years ago

  • Is duplicate of deleted (Feature #3322: Setting to restrict spent times on future dates)
Actions #27

Updated by Toshi MARUYAMA over 7 years ago

  • Related to Feature #3322: Setting to restrict spent times on future dates added
Actions #28

Updated by Go MAEDA over 6 years ago

Actions #29

Updated by Guillermo ML over 5 years ago

If anyone is interested a coworker made this plugin: https://github.com/cerxal/estatisticas
It does a lot of things, but it includes a field called Numero máximo de dias sin incurrir horas = Maximum number of days to log spent time so users can only log time X days ago, if you try to log X+1 days ago it will raise an error.
We are using it in 3.4.4 (also in 3.3.1). Don't know if it will work in other versions.
Maybe you can use part of the source code to do your own dedicate plugin.

Actions #30

Updated by Pavel Potcheptsov over 5 years ago

Thanks you for information.
Do you know if there an option to exclude certain users from that restriction?

Actions #31

Updated by Guillermo ML over 5 years ago

Pavel Potcheptsov wrote:

Do you know if there an option to exclude certain users from that restriction?

No, it applies to all users on all projects.

Actions #32

Updated by Jan K. over 5 years ago

We would like to have this functionality as well. IO agree with Kirill and Pavel. Important feature.

We have the same problem In our use case. Users should log their time max 1-3 days back butthey do it just to fiil the time. I'd like to restrict it. If they do not log the time properly, they should have a problem which can solve only someone with higher privilegy.

Actions #33

Updated by Mischa The Evil over 5 years ago

  • Has duplicate Feature #31984: Permission to add timelogs in past added
Actions #34

Updated by Aleksandar Pavic over 5 years ago

+1 see my comments from #31984

Actions #35

Updated by Ashwin Date about 5 years ago

I have created a patch based on the master git branch for this feature. This patch allows

1. Global configuration in the "Time Tracking" tab in the settings that allows setting how many days in the past time logs can be added. Default is 999 days
2. Once the configuration is set, the date of the time log cannot be older than x days in the past. x is the value configured in the above setting.

Patch attached.

Actions #36

Updated by Ashwin Date about 5 years ago

Corrected spelling for "time logs"

Actions #37

Updated by Mitrajit Samanta over 4 years ago

Ashwin Date wrote:

Corrected spelling for "time logs"

Hi Aswin, please tell me how to use this patch in Redmine.

Actions #38

Updated by Pavel Potcheptsov over 4 years ago

Ashwin Date wrote:

I have created a patch based on the master git branch for this feature.

Hi there.
Your path works great however I didn't make any changes in app/controllers/issues_controller.rb. Can you describe what is the purpose of that changes?

Do you know how to implement changes so that to add setting to choose users who is excluded from past time log restriction?

For now I have to use this line with hardcoded users IDs:

errors.add :spent_on, :invalid if \
(days_diff.to_i  > Setting.timelog_max_days_before.to_i) && \
([10,20,30,110].exclude? User.current.id)

Actions #39

Updated by Some Proton almost 4 years ago

i use

 errors.add :spent_on,  "is too early" if (spent_on < Date.today - 5.day)
   end

successfully, but like to restrict time logs to the current month, u should not be able to log time in any other month except the current month. so u can only log the time in march, as soon as its 1st of march. im no ruby or redmine coder, can someone help me with this?

Actions #40

Updated by Sergey Neustruev 10 months ago

Pavel Potcheptsov wrote in #note-38:

Ashwin Date wrote:

I have created a patch based on the master git branch for this feature.

Hi there.
Your path works great however I didn't make any changes in app/controllers/issues_controller.rb. Can you describe what is the purpose of that changes?

Greetings!
I warn you right away, I'm still not well versed in Ruby and Redmine, but I needed to fix the patch that was in this branch.

Do you know how to implement changes so that to add setting to choose users who is excluded from past time log restriction?
For now I have to use this line with hardcoded users IDs:

The corrections were made so that one of the groups could be granted the rights to change. The group can be replenished separately with redmine funds without having to get into the code.
app/models/time_entry.rb

      days_diff = (Date.today - spent_on)
      time_group_name = Setting.timelog_groups_exclude
      time_group = Group.find_by_lastname(time_group_name)
      time_group_id = time_group.id if time_group
      time_users_list = time_group.users if time_group
      time_user_array = []                                                                                  
      time_users_list.each do |user|
        user_id = user.id
        time_user_array.push(user.id)
      end
      errors.add :spent_on, :invalid if \                                                                   
      (days_diff.to_i  > Setting.timelog_max_days_before.to_i) && \
      (time_user_array.exclude? User.current.id)                                                                
      time_user_array.clear

app/views/settings/_timelog.html.erb

<p><%= setting_select :timelog_groups_exсlude, Group.where(["type IN (?)",['User','Group']]).order("users.lastname ASC").each {|u| [u.name.to_s, u.id]}, :blank => :label_none, :label => :setting_timelog_groups_exclude %></p>

config/locales/en-GB.yml

setting_timelog_groups_exclude: Users group for exclude

config/settings.yml

timelog_groups_exclude:
default: ''

<If you think that something needs to be fixed, write.

Actions #41

Updated by Sergey Neustruev 10 months ago

app/models/time_entry.rb

     days_diff = (Date.today - spent_on).to_i
      time_group = Group.find_by_lastname(Setting.timelog_groups_exclude)
      users_in_group = time_group.users.map(&:id) if time_group
      if days_diff > Setting.timelog_max_days_before.to_i && !users_in_group.include?(User.current.id) && !(User.current.admin?)
        errors.add :spent_on, :invalid
      end

Actions #42

Updated by Eser Esen 5 months ago

Hi,

i would like to block adding or changing time entries at all if, for example, then spent_on is on last month, and number of day in current month is like >= 5. Only allow admins to do so, no seetings needed.

Im not really sure where exactly to put it on the time_entry.rb file, could someone explain? Is it the "validate_time_entry" method?

Actions #43

Updated by Pavel Potcheptsov 5 months ago

Eser Esen wrote in #note-42:

Hi,

i would like to block adding or changing time entries at all if, for example, then spent_on is on last month, and number of day in current month is like >= 5. Only allow admins to do so, no seetings needed.

Well you can follow my original patch and do something like that, i.e. throw error if current day is more then 05 in current month and spent time is in the past month and hardcode users's id to exclude from this condition:

errors.add :spent_on,  "is too early" if (spent_on <= Date.today.prev_month.end_of_month && Date.today.day >= 5) && ([admin_id1,admin_id2].exclude? User.current.id)
Actions #44

Updated by Go MAEDA 4 months ago

I wrote a new patch similar to issue_13244.patch by Ashwin Date.

You can restrict users from logging time on past dates by configuring the "Accept time logs within the past N days" setting ("Administration" > "Settings" > "Time tracking").
The default value of this setting is 36525 days (approximately 100 years), which effectively means the restriction is virtually unlimited unless specifically configured.

Actions #45

Updated by Pavel Potcheptsov 4 months ago

Wow!
Although I'm not an active user of Remine anymore still glad the project has such a valuable contributors.

Actions #46

Updated by Marius BĂLTEANU 4 months ago

Several years ago, I developed a similar patch using a different approach. It included:
  • A setting to lock dates older than N days.
  • A permission to allow adding, editing, or deleting time entries on locked dates.

I can update the existing patch or merge both solutions if you believe the permission would be beneficial.

I'm attaching the patch only for inspection because it needs some updates in order to cleanly apply on the current trunk.

Actions #47

Updated by Jens Krämer 13 days ago

Upon user request, we have developed a very simple solution at Planio, which allows to disable time logging on closed issues on a per-project basis (in the project settings / issue tracking tab):

Actions #48

Updated by Marius BĂLTEANU 12 days ago

  • Related to Feature #13596: Allow time logging only for open issues added
Actions #49

Updated by Marius BĂLTEANU 10 days ago

Jens Krämer wrote in #note-47:

Upon user request, we have developed a very simple solution at Planio, which allows to disable time logging on closed issues on a per-project basis (in the project settings / issue tracking tab):

[..]

Thanks for the patch! I'm not sure at which version is Plan.io right now, but in standard Redmine, we already have 2 global settings similar to this one:
  • Accept time logs with 0 hours
  • Accept time logs on future dates

I fully agree that having the option to override some settings at the project level is very useful. Until that feature is available, I prefer to add this setting next to the existing ones. I've posted a new patch based on your work in #13596. Let's continue the discussion there.

Actions #50

Updated by Marius BĂLTEANU 10 days ago

Go MAEDA wrote in #note-44:

I wrote a new patch similar to issue_13244.patch by Ashwin Date.

You can restrict users from logging time on past dates by configuring the "Accept time logs within the past N days" setting ("Administration" > "Settings" > "Time tracking").
The default value of this setting is 36525 days (approximately 100 years), which effectively means the restriction is virtually unlimited unless specifically configured.

[..]

Go MAEDA, I've reworked a little bit your patch in order to be in the same direction with the similar settings that we already have. What do you think?

Actions #51

Updated by Go MAEDA 10 days ago

Marius BĂLTEANU wrote in #note-50:

Go MAEDA, I've reworked a little bit your patch in order to be in the same direction with the similar settings that we already have. What do you think?

Thank you for taking care of this.

I think that with Planio's new "Time tracking on closed issues" setting, the additional setting to restrict time entries for past dates that I proposed may not be necessary. This new setting seems sufficient to cover many use cases, and adding a restriction for past dates on top of this might increase complexity. Adding too many settings could make it cumbersome for users to manage configurations effectively.

Actions #52

Updated by Jens Krämer 6 days ago

Marius BĂLTEANU wrote in #note-49:

I fully agree that having the option to override some settings at the project level is very useful. Until that feature is available, I prefer to add this setting next to the existing ones. I've posted a new patch based on your work in #13596. Let's continue the discussion there.

Thank you Marius, that makes sense. I guess #4015 is what you mean regarding project level setting overrides?

Actions #53

Updated by Marius BĂLTEANU 6 days ago

Jens Krämer wrote in #note-52:

Marius BĂLTEANU wrote in #note-49:

I fully agree that having the option to override some settings at the project level is very useful. Until that feature is available, I prefer to add this setting next to the existing ones. I've posted a new patch based on your work in #13596. Let's continue the discussion there.

Thank you Marius, that makes sense. I guess #4015 is what you mean regarding project level setting overrides?

Yes, that is the ticket.

Actions

Also available in: Atom PDF