Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worktime tracking for the organization level #19808

Merged
merged 11 commits into from
Feb 2, 2025

Conversation

kkovacs
Copy link
Contributor

@kkovacs kkovacs commented May 25, 2022

Dear Gitea team,

first of all, thanks for the great work you're doing with this project.

I'm planning to introduce Gitea at a client site, and noticed that while there is time recording, there are no project-manager-friendly reports to actually make use of that data, as were also mentioned by others in #4870 #8684 and #13531.

Since I had a little time last weekend, I had put together something that I hope to be a useful contribution to this great project (while of course useful for me too).

This PR adds a new "Worktime" tab to the Organisation level. There is a date range selector (by default set to the current month), and there are three possible views:

  • by repository,
  • by milestone, and
  • by team member.

Happy to receive any feedback!

There are several possible future improvements of course (predefined date ranges, charts, a member time sheet, matrix of repos/members, etc) but I hope that even in this relatively simple state this would be useful to lots of people.

Screen Shot 2022-05-25 at 22 12 58

Keep up the good work!

Kristof

@kkovacs kkovacs marked this pull request as draft May 25, 2022 21:19
@kkovacs kkovacs marked this pull request as ready for review May 25, 2022 21:38
@lunny lunny added this to the 1.18.0 milestone May 26, 2022
@lunny lunny added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label May 26, 2022
Copy link
Member

@lafriks lafriks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for PR! Looks beautiful :)

All queries must be rewritten using xorm query builder and need to add filter to calculate and show only data from repositories user has access to (with issue/pr rights?). We should have function that return such conditions imho

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 26, 2022
@kkovacs
Copy link
Contributor Author

kkovacs commented May 26, 2022

Thanks for PR! Looks beautiful :)

Thank you, lafriks :) 😊

All queries must be rewritten using xorm query builder

OK, if I must :) I'll do it when I'll have some time. Hopefully within a week.

and need to add filter to calculate and show only data from repositories user has access to (with issue/pr rights?). We should have function that return such conditions imho

Hmm, currently the whole functionality is restricted to organization "owners" (by checking ctx.Org.IsOwner in parseTimes), and (according to the help text) "Owners have full access to all repositories and have administrator access to the organization." This is why there is no separate rights checking in the query.

My thinking was that I would rather NOT let people see partial (invalid) data, since the risk that such invalid data gets sent out in an invoice etc by somebody who don't have full rights to see everything within an organization is too high.

So I'm double-checking with you: would you consider the current "limited to owners" restriction enough, or still want additional permission check in the query?

@Gusted
Copy link
Contributor

Gusted commented May 26, 2022

So I'm double-checking with you: would you consider the current "limited to owners" restriction enough, or still want additional permission check in the query?

The permission checking shouldn't be done by a helper helper, this should rather be done at router-level. So in this case you want to move the three lines in web.go to the group that starts from line 640, which already includes the owner checking.

@lafriks
Copy link
Member

lafriks commented May 26, 2022

As @Gusted said it's in the wrong place and that's why I did not notice that it's only for owner team members.

Yes you understand correctly owner users will have full access to all org repositories.

If we leave it that only owners have access to this than it does not need that check in queries.

My use case would be that owner would be either lead developer of the team or devops team. Project manager who would be interested in this tab usually have read rights to all repos (and write rights to issues) thus he would not see this. But that's totally I don't mind seeing done in the future as other PR to improve this feature.

@kkovacs
Copy link
Contributor Author

kkovacs commented May 26, 2022

Thanks for the laser-precise advice, @Gusted, will do!

I totally see your point @lafriks. If (as you say) it's OK to deal with the more precise permissions in a future PR, then for simplicity's sake I'd rather leave this particular PR as "owner-only" (but change it of course as per Gusted's recommendation).

I will push later!

@kkovacs kkovacs marked this pull request as draft May 26, 2022 21:22
@kkovacs kkovacs force-pushed the feature/worktime-for-org branch from 28cde92 to 44669f4 Compare May 26, 2022 21:44
routers/web/org/times.go Outdated Show resolved Hide resolved
@kkovacs kkovacs marked this pull request as ready for review May 26, 2022 22:05
routers/web/org/times.go Outdated Show resolved Hide resolved
routers/web/org/times.go Outdated Show resolved Hide resolved
@kkovacs
Copy link
Contributor Author

kkovacs commented Jun 5, 2022

Just two small questions:

  1. I'd made the requested changes. Should I request a re-review, or is it enough that they are in the "resolved" state?
  2. I've been looking at how you guys implement tests, and I think I could add tests to this functionality if I do some related refactoring for testability. Should I just add the new commits to this PR, or should this be a separate PR later?

Thanks in advance!

@lunny
Copy link
Member

lunny commented Jun 6, 2022

Just two small questions:

  1. I'd made the requested changes. Should I request a re-review, or is it enough that they are in the "resolved" state?
  2. I've been looking at how you guys implement tests, and I think I could add tests to this functionality if I do some related refactoring for testability. Should I just add the new commits to this PR, or should this be a separate PR later?

Thanks in advance!

Since this PR sent after v1.17 feature freezed, let's wait to merge after v1.17 release. Of course, I think we can re-review it at any time when maintainers have free time.

@kkovacs kkovacs requested a review from lafriks June 6, 2022 10:16
@kkovacs
Copy link
Contributor Author

kkovacs commented Jun 6, 2022

Thanks, I'll be requesting re-review then. (Github is a bit confusing for me regarding the right etiquette and the request UI)

@kkovacs kkovacs requested a review from Gusted June 6, 2022 10:19
@kkovacs
Copy link
Contributor Author

kkovacs commented Jun 13, 2022

Dear @lafriks and @Gusted, I just couldn't bear not having tests on the correctness of the queries, so I refactored a bit and added tests. Hope you don't mind.

P.s.: The build failed with "https://registry-1.docker.io/v2/woodpeckerci/plugin-codecov/manifests/next-alpine": received unexpected HTTP status: 500 Internal Server Error, which sounds like a docker registry issue? Can the build be restarted?

P.s.2: I think Github erroneously keeps "1 change requested" on this ticket, because the change was done – maybe it was confused by the rebase at the same time?

Anyway, I will leave this PR alone for now -- feel free to review (all change requests were completed) and to merge at the right time!

Copy link
Contributor

@Gusted Gusted left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure you have translated words and use the correct keys for those. The HTML part of this PR really need some tidying up to do.

modules/util/sec_to_hour.go Outdated Show resolved Hide resolved
routers/web/org/times.go Outdated Show resolved Hide resolved
routers/web/org/times.go Outdated Show resolved Hide resolved
routers/web/org/times.go Outdated Show resolved Hide resolved
routers/web/org/times.go Outdated Show resolved Hide resolved
templates/org/times/daterange.tmpl Outdated Show resolved Hide resolved
templates/org/times/daterange.tmpl Outdated Show resolved Hide resolved
templates/org/times/daterange.tmpl Outdated Show resolved Hide resolved
templates/org/times/submenu.tmpl Outdated Show resolved Hide resolved
templates/org/times/submenu.tmpl Outdated Show resolved Hide resolved
@kkovacs
Copy link
Contributor Author

kkovacs commented Jun 27, 2022

Thanks for the detailed review - I haven't disappeared, I'll do the requested changes when I have some time!

@kkovacs
Copy link
Contributor Author

kkovacs commented Jul 6, 2022

Dear @Gusted, I've finally got around to make the changes you requested.

It's not completely clear to me whether it should be me or you who "resolve" the conversations, so I erred on the side of "resolving" the trivial ones, and leaving open the ones where you might want to see the responses.

One particular thing: please review my use of context.OrgAssignment for the m.Group in routers.

@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (main@3c6c150). Click here to learn what that means.
The diff coverage is 46.20%.

@@           Coverage Diff           @@
##             main   #19808   +/-   ##
=======================================
  Coverage        ?   46.91%           
=======================================
  Files           ?      975           
  Lines           ?   135113           
  Branches        ?        0           
=======================================
  Hits            ?    63394           
  Misses          ?    63960           
  Partials        ?     7759           
Impacted Files Coverage Δ
modules/templates/helper.go 45.86% <0.00%> (ø)
routers/web/org/times.go 39.13% <39.13%> (ø)
modules/util/sec_to_hour.go 100.00% <100.00%> (ø)
routers/web/web.go 86.61% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3c6c150...3805fba. Read the comment docs.

@kkovacs kkovacs requested a review from Gusted July 7, 2022 14:51
routers/web/org/times.go Outdated Show resolved Hide resolved
routers/web/org/times.go Outdated Show resolved Hide resolved
routers/web/org/times.go Outdated Show resolved Hide resolved
routers/web/org/times.go Outdated Show resolved Hide resolved
routers/web/web.go Outdated Show resolved Hide resolved
templates/org/menu.tmpl Outdated Show resolved Hide resolved
@kkovacs kkovacs marked this pull request as draft August 10, 2022 18:28
@kkovacs kkovacs force-pushed the feature/worktime-for-org branch 2 times, most recently from 9f70fae to eef5842 Compare August 11, 2022 14:25
@GiteaBot GiteaBot added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Jan 4, 2025
@wxiaoguang wxiaoguang self-assigned this Jan 4, 2025
# Conflicts:
#	modules/templates/helper.go
#	options/locale/locale_en-US.ini
#	templates/org/menu.tmpl
#	web_src/js/index.js
@pull-request-size pull-request-size bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Feb 2, 2025
@github-actions github-actions bot added modifies/translation modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files labels Feb 2, 2025
@wxiaoguang wxiaoguang force-pushed the feature/worktime-for-org branch from 3f70d1c to 855f45d Compare February 2, 2025 12:52
@wxiaoguang
Copy link
Contributor

Made some changes, and the UI is kept as before

image


image


image

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 2, 2025
@wxiaoguang wxiaoguang force-pushed the feature/worktime-for-org branch 2 times, most recently from 42af2dd to 01e0c94 Compare February 2, 2025 13:47
@wxiaoguang wxiaoguang changed the title Worktime tracking for the organization level. Worktime tracking for the organization level Feb 2, 2025
@wxiaoguang wxiaoguang force-pushed the feature/worktime-for-org branch from 01e0c94 to 45a1e64 Compare February 2, 2025 14:09
@wxiaoguang wxiaoguang force-pushed the feature/worktime-for-org branch from 45a1e64 to 7843cbb Compare February 2, 2025 14:18
@wxiaoguang
Copy link
Contributor

After fixing some problems (mismatched HTML tags, different SQL syntaxes), I think it is good enough now.

CI passes.

@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 2, 2025
@lunny lunny merged commit 34692a2 into go-gitea:main Feb 2, 2025
26 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 2, 2025
zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 3, 2025
* giteaofficial/main: (53 commits)
  [skip ci] Updated licenses and gitignores
  Correct bot label `vertical-align` (go-gitea#33477)
  chore: fix some trivial problems and TODOs (go-gitea#33473)
  Worktime tracking for the organization level (go-gitea#19808)
  Skip deletion error for action artifacts (go-gitea#33476)
  Update .changelog file to add performance label group (go-gitea#33472)
  actions view: move loading of task attributes etc... into own func (go-gitea#31494)
  [skip ci] Updated translations via Crowdin
  Update feishu icon (go-gitea#33470)
  Inclusion of rename organization api (go-gitea#33303)
  [skip ci] Updated translations via Crowdin
  Hide/disable unusable UI elements when a repository is archived (go-gitea#33459)
  Fix SSH LFS memory usage (go-gitea#33455)
  Revert empty lfs ref name (go-gitea#33454)
  Update `@github/text-expander-element`, adapt type imports (go-gitea#33449)
  Support choose email when creating a commit via web UI (more) (go-gitea#33445)
  Fix issue sidebar dropdown keyboard support (go-gitea#33447)
  Fix "redirect link" handling (go-gitea#33440)
  Refactor repository transfer (go-gitea#33211)
  Enable two more strict options in tsconfig (go-gitea#33438)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/translation size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.