Content
View differences
Updated by Parimal Satyal about 4 years ago
**As an** OpenProject user
**I want to** log time for other users
**so that** I can take over the task if the user does not have access to the system.
### **Note**
For 12.2, on the front-end, we will only be:
* adding the new "user" field in the log time module
* except when coming from "My Time Spent",
* adding the the "logged by" column in time report table
* changing the buttons so that they read "Cancel" and "Save" (blue, on the right)
This also means that we are conserving the horizontal format (with text field labels to the left).
### **Acceptance criteria**
#### **Permissions**
* There is a separate permission to log time for another user 'Log time for other users'.
* The current permission is renamed to “Log own time.”
* **\[open\]** There are some naming inconsistencies with the permissions `"log_time", "edit_time_entries", "edit_own_time_entries"`. Should we make them more consistent?
#### **Log time modal (default)**
In the "log time" modal when coming from a work package: modal:
* There is a new select field called “User", with autocomplete, showing all project members
* This field is only visible for users who have the 'Log time for other users' permission.
* **\[closed\]** ~~**\[open\]** Do we have an existing word/string that is better than 'Resource' for this?~~
To remain consistent with the column in the cost report page, we will use the word "user".
* **\[open\]** Do we need the invite functionality on the bottom of the user list, as we have it for project assignees? Yes, we'll use the exact same component without modification.
* By default, this field shows the name of the person opening the modal (current user).
* There are two buttons in the action bar at the buttom:
* "Save" (primary, on the right side) (primary)
* "Cancel" "Cancel"
#### **Log time modal (from "My Time Spent")**
The modal can also be called from the "My Time Spent" widget on My Page.
* The "User" "user" field does not exist (this widget is to log "my time").
* All existing fields are conserved, including the There is an additional "work package" field.
* The current behaviour is conserved (search field with autocomplete).
* There are two buttons in the action bar at the buttom:
* "Save" (primary, on the right side)
* "Cancel"
#### Time/cost report table
* There is a new column "Logged by", showing who made the entry.
* This could be a third user who has "log time for other users" permission, or the user themself. themselves.
* It should be possible to filter/group by "Logged by".
* _Note: that the buttons "Save" and "Apply" are next two each other and do two different things is a but, but it will be addressed in a separate ticket. Conserve current implementation for now._
#### Edit logged time
A logged time can be edited.
* Clicking on the "edit" icon will show the same modal as the default log time modal:
* There is before, with an additional "User" field in comparison to what's there today.
* There are two buttons in button on the action bar at the buttom:
bar:
* "Save" (primary, ~~There is a delete button on the right side) left edge:~~
* "Cancel"
* The third delete button (which is currently there) is removed. ~~"Delete" (Outlined/Danger with left-icon:~~ _~~delete~~_~~)~~
### Visuals
_**Log time module with User field (when coming from a work package):**_ * _**updated visuals will be added very soon**_
<figure class="image op-uc-figure"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/32006/content"></div></figure>
_**Log time module without User field (when coming from the My Time Spent widget on My Page):**_
<figure class="image op-uc-figure" style="width:75%;"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/32007/content"></div></figure>
_**Logged time table with the "Logged by" column**_
<figure class="image op-uc-figure"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/32010/content"></div></figure>
_**Log time module in edit mode (both "User" and "Work package" fields are available):**_
<figure class="image op-uc-figure" style="width:75%;"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/32008/content"></div></figure>
All Figma screens available here:
[https://www.figma.com/file/xRFTkBJYxQJxwAf9fd3oM1/Log-time-for-others?node-id=0%3A1](https://www.figma.com/file/xRFTkBJYxQJxwAf9fd3oM1/Log-time-for-others?node-id=0%3A1)
### Technical details
**Rename "Log spent time" to "Log own time":**
* Create migration to replace the RolePermission#permission having "log\_time" with "log\_own\_time"
* Update translations
* Update the ocurrences of `:log_time` and `'log_time'` in the code with `:log_own_time`
**Add the new permission "Log time for other users":**
* Create migration to add `RolePermission#permission` "log\_time\_for\_others"
**Add a new field called logged\_by to the TimeEntry model:**
* Create a migration adding `logged_by_id` foreign key to the `TimeEntry` model, referencing the `User` model.
* Add belongs to relation, ie `belongs_to :logged_by, class_name: 'User'`
**Validations:**
* Add attribute `:user_id` to the `TimeEntries::BaseContract` to enable writing the user\_id.
* Add new validation to the `TimeEntries::CreateContract` and check whether the user is allowed to add time for others
* If not allowed, then call `TimeEntries::CreateContract#validate_user_current_user` to ensure he can add time for himself only
* The validation should use the permission `user.allowed_to?(:log_time, model.project)`
* Add new validation to the `TimeEntries::UpdateContract#validate_user_current_user` using the permission `user.allowed_to?(:edit_own_time_entries, model.project)`
* Add new validation to the `TimeEntries::UpdateContract` and check whether the user is allowed to add time for others
* The validation should use the permission `user.allowed_to?(:edit_time_entries, model.project)`
* If not allowed, then call a `TimeEntries::UpdateContract#validate_user_current_user` to ensure he can add time for himself only
**Log time modal:**
* Create a select field called "Resources", which will reference the `TimeEntry#user_id` field
* Populate it with all the available users for the project using the `API::V3::Projects::AvailableAssigneesAPI` endpoint
* Show it only when the current user has the permission `"log_time_for_others"`
* Use the `WorkPackageAuthorization` service to fetch permission to add time for others.
(See for example https://github.com/opf/openproject/blob/32da00108d89fc4e28c4b06ec77385beedc9ba81/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-single-context-menu.ts#L44-L45)
* The visual changes can be implemented later on, when the new design systems are in place. A follow up with the design team (Ben, Henriette) is required when starting on this feature.
* Most of the things are accessible already by visiting `/design/spot`.
* A few notable elements missing:
* A dropdown for picking users
* The label+input errors
* A main spot container that will align all the form elements with equal spacing.
**Time/cost report table:**
* Add a new field `:logged_by` to the `::Widget::Table::EntryTable::FIELDS` constant
(./modules/reporting/lib/widget/table/entry\_table.rb)
* Update the method `field_representation_map` and expand the `when :user_id, :assigned_to_id, :author_id` with `:logged_by_id` in the `ReportingHelper` module.
(./modules/reporting/app/helpers/reporting\_helper.rb)
* Create a new grouping condition class `CostQuery::GroupBy::LoggedById`
under the `label_work_package_attributes` and add it to the `CostQuery::GroupBy.all` method
* Create a new filtering condition `CostQuery::Filter::LoggedById` for and add it to the `CostQuery::Filter.all` method
**I want to** log time for other users
**so that** I can take over the task if the user does not have access to the system.
### **Note**
For 12.2, on the front-end, we will only be:
* adding the new "user" field in the log time module
* except when coming from "My Time Spent",
* adding the the "logged by" column in time report table
* changing the buttons so that they read "Cancel" and "Save" (blue, on the right)
This also means that we are conserving the horizontal format (with text field labels to the left).
### **Acceptance criteria**
#### **Permissions**
* There is a separate permission to log time for another user 'Log time for other users'.
* The current permission is renamed to “Log own time.”
* **\[open\]** There are some naming inconsistencies with the permissions `"log_time", "edit_time_entries", "edit_own_time_entries"`. Should we make them more consistent?
#### **Log time modal (default)**
In the "log time" modal when coming from a work package:
* There is a new select field called “User", with autocomplete, showing all project members
* This field is only visible for users who have the 'Log time for other users' permission.
* **\[closed\]**
To remain consistent with the column in the cost report page, we will use the word "user".
* **\[open\]** Do we
* By default, this field shows the name of the person opening the modal (current user).
* There are two buttons in the action bar at the buttom:
* "Save" (primary, on the right side)
* "Cancel"
#### **Log time modal (from "My Time Spent")**
The modal can also be called from the "My Time Spent" widget on My Page.
* The "User"
* All existing fields are conserved, including the
* The current behaviour is conserved (search field with autocomplete).
* There are two buttons in the action bar at the buttom:
* "Save" (primary, on the right side)
* "Cancel"
#### Time/cost report table
* There is a new column "Logged by", showing who made the entry.
* This could be a third user who has "log time for other users" permission, or the user themself.
* It should be possible to filter/group by "Logged by".
* _Note: that the buttons "Save" and "Apply" are next two each other and do two different things is a but, but it will be addressed in a separate ticket. Conserve current implementation for now._
#### Edit logged time
A logged time can be edited.
* Clicking on the "edit" icon will
* There is
* There are two buttons in
* "Cancel"
* The third delete button (which is currently there) is removed.
### Visuals
_**Log time module with User field (when coming from a work package):**_
<figure class="image op-uc-figure"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/32006/content"></div></figure>
_**Log time module without User field (when coming from the My Time Spent widget on My Page):**_
<figure class="image op-uc-figure" style="width:75%;"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/32007/content"></div></figure>
_**Logged time table with the "Logged by" column**_
<figure class="image op-uc-figure"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/32010/content"></div></figure>
_**Log time module in edit mode (both "User" and "Work package" fields are available):**_
<figure class="image op-uc-figure" style="width:75%;"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/32008/content"></div></figure>
All Figma screens available here:
[https://www.figma.com/file/xRFTkBJYxQJxwAf9fd3oM1/Log-time-for-others?node-id=0%3A1](https://www.figma.com/file/xRFTkBJYxQJxwAf9fd3oM1/Log-time-for-others?node-id=0%3A1)
### Technical details
**Rename "Log spent time" to "Log own time":**
* Create migration to replace the RolePermission#permission having "log\_time" with "log\_own\_time"
* Update translations
* Update the ocurrences of `:log_time` and `'log_time'` in the code with `:log_own_time`
**Add the new permission "Log time for other users":**
* Create migration to add `RolePermission#permission` "log\_time\_for\_others"
**Add a new field called logged\_by to the TimeEntry model:**
* Create a migration adding `logged_by_id` foreign key to the `TimeEntry` model, referencing the `User` model.
* Add belongs to relation, ie `belongs_to :logged_by, class_name: 'User'`
**Validations:**
* Add attribute `:user_id` to the `TimeEntries::BaseContract` to enable writing the user\_id.
* Add new validation to the `TimeEntries::CreateContract` and check whether the user is allowed to add time for others
* If not allowed, then call `TimeEntries::CreateContract#validate_user_current_user` to ensure he can add time for himself only
* The validation should use the permission `user.allowed_to?(:log_time, model.project)`
* Add new validation to the `TimeEntries::UpdateContract#validate_user_current_user` using the permission `user.allowed_to?(:edit_own_time_entries, model.project)`
* Add new validation to the `TimeEntries::UpdateContract` and check whether the user is allowed to add time for others
* The validation should use the permission `user.allowed_to?(:edit_time_entries, model.project)`
* If not allowed, then call a `TimeEntries::UpdateContract#validate_user_current_user` to ensure he can add time for himself only
**Log time modal:**
* Create a select field called "Resources", which will reference the `TimeEntry#user_id` field
* Populate it with all the available users for the project using the `API::V3::Projects::AvailableAssigneesAPI` endpoint
* Show it only when the current user has the permission `"log_time_for_others"`
* Use the `WorkPackageAuthorization` service to fetch permission to add time for others.
(See for example https://github.com/opf/openproject/blob/32da00108d89fc4e28c4b06ec77385beedc9ba81/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-single-context-menu.ts#L44-L45)
* The visual changes can be implemented later on, when the new design systems are in place. A follow up with the design team (Ben, Henriette) is required when starting on this feature.
* Most of the things are accessible already by visiting `/design/spot`.
* A few notable elements missing:
* A dropdown for picking users
* The label+input errors
* A main spot container that will align all the form elements with equal spacing.
**Time/cost report table:**
* Add a new field `:logged_by` to the `::Widget::Table::EntryTable::FIELDS` constant
(./modules/reporting/lib/widget/table/entry\_table.rb)
* Update the method `field_representation_map` and expand the `when :user_id, :assigned_to_id, :author_id` with `:logged_by_id` in the `ReportingHelper` module.
(./modules/reporting/app/helpers/reporting\_helper.rb)
* Create a new grouping condition class `CostQuery::GroupBy::LoggedById`
under the `label_work_package_attributes` and add it to the `CostQuery::GroupBy.all` method
* Create a new filtering condition `CostQuery::Filter::LoggedById` for and add it to the `CostQuery::Filter.all` method