Skip to content

Commit

Permalink
Merge pull request #1190 from France-ioi/threads_latest_update_at_db_…
Browse files Browse the repository at this point in the history
…time

Store the DB time instead of the server time in threads.latest_update_at and compare its value with the DB time instead of the server time as well
  • Loading branch information
zenovich authored Oct 16, 2024
2 parents 9d0f9bd + f6151d5 commit 1cc46ba
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/api/threads/get_thread.robustness.feature
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Feature: Get thread - robustness
| 60 | 3 | closed | 10 | 2020-01-20 00:00:00 |
| 70 | 3 | waiting_for_trainer | 10 | 2020-01-20 00:00:00 |
| 80 | 3 | waiting_for_participant | 20 | 2020-01-20 00:00:00 |
And the server time now is "2020-01-20T00:00:00Z"
And the DB time now is "2020-01-20 00:00:00"

Scenario: Should be logged
When I send a GET request to "/items/10/participant/1/thread"
Expand Down
2 changes: 1 addition & 1 deletion app/api/threads/list_threads.feature
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Feature: List threads
| @B_SectionMember3 | @B_SectionMember2_CanViewContent2 | | | | 18 | @B_SectionMember2 is_mine=1 -> notok: not the participant |
| @B_SectionMember2 | @B_SectionMember2_CanViewContentWithDescendants | | | | 19 | @B_SectionMember2 is_mine=1 -> ok: can_view >= content |
| @OtherGroupMember | @Item2 | | | | 20 | |
And the server time now is "2022-01-01T00:00:00Z"
And the DB time now is "2022-01-01 00:00:00"

Scenario: Should have all the fields properly set, including first_name and last_name when the access is approved
Given I am @LaboratoryManagerCanWatch
Expand Down
2 changes: 1 addition & 1 deletion app/api/threads/update_thread.feature
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Feature: Update thread
| 12 | 11 | 3004 | 12 | 0 |
And the database has the following table "threads":
| item_id | participant_id | status | helper_group_id | latest_update_at |
And the server time now is "2022-01-01T00:00:00Z"
And the DB time now is "2022-01-01 00:00:00"

Scenario: Create a thread if it doesn't exist
Given I am the user with id "3"
Expand Down
3 changes: 1 addition & 2 deletions app/api/threads/update_thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package threads
import (
"errors"
"net/http"
"time"

"github.com/France-ioi/validator"
"github.com/go-chi/render"
Expand Down Expand Up @@ -197,7 +196,7 @@ func computeNewThreadData(
if len(threadData) > 0 {
threadData["item_id"] = itemID
threadData["participant_id"] = participantID
threadData["latest_update_at"] = time.Now()
threadData["latest_update_at"] = database.Now()

if _, ok := threadData["helper_group_id"]; !ok {
threadData["helper_group_id"] = oldHelperGroupID
Expand Down
7 changes: 1 addition & 6 deletions app/database/thread_store.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package database

import (
"time"

"github.com/jinzhu/gorm"
)

Expand Down Expand Up @@ -193,14 +191,11 @@ func (s *ThreadStore) WhereUserCanHelp(user *User) *ThreadStore {
// the thread is either open (=waiting_for_participant or =waiting_for_trainer), or closed for less than 2 weeks
// the current-user has validated the item

now := time.Now()
twoWeeksAgo := now.AddDate(0, 0, -14)

return s.NewThreadStore(
s.Joins("JOIN results ON results.item_id = threads.item_id AND results.participant_id = ?", user.GroupID).
Joins("JOIN groups_ancestors_active ON groups_ancestors_active.child_group_id = ?", user.GroupID).
Where("threads.helper_group_id = groups_ancestors_active.ancestor_group_id").
Where("threads.status != 'closed' OR threads.latest_update_at > ?", twoWeeksAgo).
Where("threads.status != 'closed' OR threads.latest_update_at > NOW() - INTERVAL 2 WEEK").
Where("results.validated"),
)
}
Expand Down

0 comments on commit 1cc46ba

Please sign in to comment.