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

feat(share): save date and time for expiration #43428

Merged
merged 1 commit into from
Feb 26, 2024

Conversation

Altahrim
Copy link
Collaborator

@Altahrim Altahrim commented Feb 7, 2024

Summary

When we store an expiration date for a share, we store only the date, without time.
If an user is in UTC + 9 and share a file before 9am, the server will consider the expiration date to be one day earlier (ie. D+6 instead of D+7). Then, the display is wrong.

To fix that, we have to store time.

Fix #43457
Fix #43243

Checklist

@Altahrim Altahrim self-assigned this Feb 8, 2024
@Altahrim Altahrim added the 2. developing Work in progress label Feb 8, 2024
@Altahrim Altahrim added this to the Nextcloud 29 milestone Feb 8, 2024
@Altahrim Altahrim force-pushed the feat/share-expiration-with-time branch 7 times, most recently from 41e359e to 719eed6 Compare February 9, 2024 08:02
@Altahrim Altahrim requested review from a team, ArtificialOwl, icewind1991 and Fenn-CS and removed request for a team February 9, 2024 08:20
@Altahrim Altahrim added 3. to review Waiting for reviews feature: sharing and removed 2. developing Work in progress labels Feb 9, 2024
@Altahrim Altahrim marked this pull request as ready for review February 9, 2024 08:20
@Altahrim
Copy link
Collaborator Author

Altahrim commented Feb 9, 2024

/backport to stable28

@Altahrim
Copy link
Collaborator Author

Altahrim commented Feb 9, 2024

/backport to stable27

@Altahrim
Copy link
Collaborator Author

Altahrim commented Feb 9, 2024

/backport to stable26

@Altahrim Altahrim force-pushed the feat/share-expiration-with-time branch 6 times, most recently from e019241 to ceebc38 Compare February 13, 2024 16:28
@Altahrim Altahrim force-pushed the feat/share-expiration-with-time branch from cca99e8 to e9733d0 Compare February 19, 2024 09:13
@Altahrim Altahrim added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Feb 19, 2024
@Altahrim Altahrim force-pushed the feat/share-expiration-with-time branch from e9733d0 to a05a877 Compare February 19, 2024 10:33
@Altahrim Altahrim force-pushed the feat/share-expiration-with-time branch from a05a877 to bc00614 Compare February 20, 2024 13:30
@Altahrim Altahrim added 2. developing Work in progress 3. to review Waiting for reviews feature: ldap and removed 2. developing Work in progress feature: ldap labels Feb 20, 2024
@@ -240,6 +240,7 @@ protected function formatShare(IShare $share, Node $recipientNode = null): array

$expiration = $share->getExpirationDate();
if ($expiration !== null) {
$expiration->setTimezone($this->dateTimeZone->getTimeZone());
Copy link
Contributor

Choose a reason for hiding this comment

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

Am I right that the timezone is relative to the current user, logged in or not? So, in the case of a public share, the timezone of the current user will be used instead of the one from the share owner. Maybe this is only ever called from the owner perspective, so it might not be a problem.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right.
It's mainly use for display, so an user will see the right expiration date for him, even if time will probably be false.

If a share expire at 00:00:00 UTC on day D, an user in UTC-2 will see D-1 00:00:00. Time is false but ensure API compatibility.

apps/files_sharing/lib/Controller/ShareAPIController.php Outdated Show resolved Hide resolved
Because of timezones, not saving time can lead to unexpected behaviour
when sharing an item sooner than timezone offset
Example: sharing a file before 9am when in UTC+9

Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
@Altahrim Altahrim force-pushed the feat/share-expiration-with-time branch from bc00614 to 01983d5 Compare February 22, 2024 10:26
@Altahrim Altahrim added the php Pull requests that update Php code label Feb 22, 2024
} catch (\Exception $e) {
throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
}

// Use server timezone to store the date
$date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
Copy link
Contributor

Choose a reason for hiding this comment

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

always UTC (see base.php)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews feature: sharing php Pull requests that update Php code
Projects
Archived in project
5 participants