Content
View differences
Updated by Attila Dombi 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.
### **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:
* 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.
* ~~**\[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?
* 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" (Filled/Main)
* "Cancel" (Outlined/Main)
#### **Log time modal (from "My Time Spent")**
The modal can also be called from the "My Time Spent" widget on My Page.
* The "user" field does not exist (this widget is to log "my time").
* In this case, there is an additional "work package" field.
* The current behaviour is conserved (search field with autocomplete).
#### 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 themselves.
* It should be possible to filter/group by "Logged by".
#### Edit logged time
A logged time can be edited.
* Clicking on the "edit" icon will show the same modal as before, with an additional button on the action bar:
* There is a delete button on the left edge:
* "Delete" (Outlined/Danger with left-icon: _delete_)
### Visuals
<figure class="image op-uc-figure"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/31755/content"></div><figcaption class="op-uc-figure--description">The log time modal with User field</figcaption></figure>
<figure class="image op-uc-figure"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/31756/content"></div><figcaption class="op-uc-figure--description">Log time, searching for a user using autocomplete</figcaption></figure>
<figure class="image op-uc-figure"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/31757/content"></div></figure>
<figure class="image op-uc-figure" style="width:50%;"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/31758/content"></div><figcaption class="op-uc-figure--description"><strong>Work package</strong> field when coming from My Time Spent - does not have user field</figcaption></figure>
<figure class="image op-uc-figure"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/30816/content"></div><figcaption class="op-uc-figure--description">The logged time table has a new column called <strong>Logged by</strong></figcaption></figure>
<figure class="image op-uc-figure" style="width:50%;"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/31759/content"></div><figcaption class="op-uc-figure--description">Editing logged time</figcaption></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` TODO - Groupings and add it to the `CostQuery::GroupBy.all` method
* Create a new filtering condition `CostQuery::Filter::LoggedById` filters for and add it to the `CostQuery::Filter.all` method `:logged_by`
**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.
### **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:
* 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.
* ~~**\[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?
* 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" (Filled/Main)
* "Cancel" (Outlined/Main)
#### **Log time modal (from "My Time Spent")**
The modal can also be called from the "My Time Spent" widget on My Page.
* The "user" field does not exist (this widget is to log "my time").
* In this case, there is an additional "work package" field.
* The current behaviour is conserved (search field with autocomplete).
#### 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 themselves.
* It should be possible to filter/group by "Logged by".
#### Edit logged time
A logged time can be edited.
* Clicking on the "edit" icon will show the same modal as before, with an additional button on the action bar:
* There is a delete button on the left edge:
* "Delete" (Outlined/Danger with left-icon: _delete_)
### Visuals
<figure class="image op-uc-figure"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/31755/content"></div><figcaption class="op-uc-figure--description">The log time modal with User field</figcaption></figure>
<figure class="image op-uc-figure"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/31756/content"></div><figcaption class="op-uc-figure--description">Log time, searching for a user using autocomplete</figcaption></figure>
<figure class="image op-uc-figure"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/31757/content"></div></figure>
<figure class="image op-uc-figure" style="width:50%;"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/31758/content"></div><figcaption class="op-uc-figure--description"><strong>Work package</strong> field when coming from My Time Spent - does not have user field</figcaption></figure>
<figure class="image op-uc-figure"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/30816/content"></div><figcaption class="op-uc-figure--description">The logged time table has a new column called <strong>Logged by</strong></figcaption></figure>
<figure class="image op-uc-figure" style="width:50%;"><div class="op-uc-figure--content"><img class="op-uc-image" src="/api/v3/attachments/31759/content"></div><figcaption class="op-uc-figure--description">Editing logged time</figcaption></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`
* Create a new filtering condition `CostQuery::Filter::LoggedById`