1313use DateTimeImmutable ;
1414use DateTimeInterface ;
1515use OC \Core \AppInfo \Application ;
16+ use OC \Core \Sharing \Recipient \EmailShareRecipientType ;
17+ use OC \Core \Sharing \Recipient \TokenShareRecipientType ;
1618use OCP \L10N \IFactory ;
1719use OCP \Share \IManager ;
1820use OCP \Sharing \Property \ADateSharePropertyType ;
@@ -52,51 +54,50 @@ public function isAdvanced(): bool {
5254 }
5355
5456 #[\Override]
55- public function isRequired (): bool {
56- if ($ this ->legacyManager ->shareApiLinkDefaultExpireDateEnforced ()) {
57+ public function isRequired (Share $ share ): bool {
58+ if ($ this ->hasTokenOrEmailRecipient ( $ share ) && $ this -> legacyManager ->shareApiLinkDefaultExpireDateEnforced ()) {
5759 return true ;
5860 }
5961
60- if ($ this ->legacyManager ->shareApiRemoteDefaultExpireDateEnforced ()) {
62+ if ($ this ->hasRemoteRecipient ( $ share ) && $ this -> legacyManager ->shareApiRemoteDefaultExpireDateEnforced ()) {
6163 return true ;
6264 }
63-
64- return $ this ->legacyManager ->shareApiInternalDefaultExpireDateEnforced ();
65+ return $ this ->hasLocalNonTokenAndEmailRecipient ($ share ) && $ this ->legacyManager ->shareApiInternalDefaultExpireDateEnforced ();
6566 }
6667
6768 #[\Override]
68- public function getDefaultValue (): ?string {
69- return $ this ->getMaxExpirationDate ()?->format(DateTimeInterface::ATOM );
69+ public function getDefaultValue (Share $ share ): ?string {
70+ return $ this ->getMaxExpirationDate ($ share )?->format(DateTimeInterface::ATOM );
7071 }
7172
7273 #[\Override]
73- public function getMinDate (): \DateTimeImmutable {
74+ public function getMinDate (Share $ share ): \DateTimeImmutable {
7475 // Ensure the expiration date is in the future.
7576 return $ this ->now ->add (new DateInterval ('PT5M ' ));
7677 }
7778
7879 #[\Override]
79- public function getMaxDate (): ?DateTimeImmutable {
80- if ($ this ->isRequired ()) {
80+ public function getMaxDate (Share $ share ): ?DateTimeImmutable {
81+ if ($ this ->isRequired ($ share )) {
8182 // Allow some time to pass between the user getting the max date and saving the date, as the time will shift in between.
82- return $ this ->getMaxExpirationDate ()?->add(new DateInterval ('PT5M ' ));
83+ return $ this ->getMaxExpirationDate ($ share )?->add(new DateInterval ('PT5M ' ));
8384 }
8485
8586 return null ;
8687 }
8788
88- private function getMaxExpirationDate (): ?DateTimeImmutable {
89- // We do not have any distinction between link/remote/internal, so we just apply the lowest expiration days count to be safe.
89+ private function getMaxExpirationDate (Share $ share ): ?DateTimeImmutable {
9090 $ days = INF ;
91- if ($ this ->legacyManager ->shareApiLinkDefaultExpireDate ()) {
91+
92+ if ($ this ->hasTokenOrEmailRecipient ($ share ) && $ this ->legacyManager ->shareApiLinkDefaultExpireDate ()) {
9293 $ days = min ($ days , $ this ->legacyManager ->shareApiLinkDefaultExpireDays ());
9394 }
9495
95- if ($ this ->legacyManager ->shareApiRemoteDefaultExpireDate ()) {
96+ if ($ this ->hasRemoteRecipient ( $ share ) && $ this -> legacyManager ->shareApiRemoteDefaultExpireDate ()) {
9697 $ days = min ($ days , $ this ->legacyManager ->shareApiRemoteDefaultExpireDays ());
9798 }
9899
99- if ($ this ->legacyManager ->shareApiInternalDefaultExpireDate ()) {
100+ if ($ this ->hasLocalNonTokenAndEmailRecipient ( $ share ) && $ this -> legacyManager ->shareApiInternalDefaultExpireDate ()) {
100101 $ days = min ($ days , $ this ->legacyManager ->shareApiInternalDefaultExpireDays ());
101102 }
102103
@@ -120,4 +121,34 @@ public function isFiltered(ShareAccessContext $accessContext, Share $share): boo
120121
121122 return false ;
122123 }
124+
125+ private function hasTokenOrEmailRecipient (Share $ share ): bool {
126+ foreach ($ share ->recipients as $ recipient ) {
127+ if ($ recipient ->class === TokenShareRecipientType::class || $ recipient ->class === EmailShareRecipientType::class) {
128+ return true ;
129+ }
130+ }
131+
132+ return false ;
133+ }
134+
135+ private function hasRemoteRecipient (Share $ share ): bool {
136+ foreach ($ share ->recipients as $ recipient ) {
137+ if ($ recipient ->instance !== null ) {
138+ return true ;
139+ }
140+ }
141+
142+ return false ;
143+ }
144+
145+ private function hasLocalNonTokenAndEmailRecipient (Share $ share ): bool {
146+ foreach ($ share ->recipients as $ recipient ) {
147+ if ($ recipient ->instance === null && $ recipient ->class !== TokenShareRecipientType::class && $ recipient ->class !== EmailShareRecipientType::class) {
148+ return true ;
149+ }
150+ }
151+
152+ return false ;
153+ }
123154}
0 commit comments