Skip to content

Commit 6c770c3

Browse files
committed
fix: hide ToS on login except login flow for clients
Signed-off-by: Grigorii K. Shartsev <[email protected]>
1 parent 1a19f92 commit 6c770c3

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

lib/AppInfo/Application.php

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,42 @@ public function boot(IBootContext $context): void {
7979
}
8080

8181
public function registerFrontend(IRequest $request, IConfig $config, IUserSession $userSession): void {
82+
// Ignore CLI
8283
/** @psalm-suppress UndefinedClass */
83-
if (!\OC::$CLI) {
84-
if ($userSession->getUser() instanceof IUser
85-
&& strpos($request->getPathInfo(), '/s/') !== 0
86-
&& strpos($request->getPathInfo(), '/login/') !== 0
87-
&& substr($request->getScriptName(), 0 - strlen('/index.php')) === '/index.php') {
88-
Util::addScript('terms_of_service', 'terms_of_service-user');
89-
} else if ($config->getAppValue(self::APPNAME, 'tos_on_public_shares', '0') === '1') {
90-
Util::addScript('terms_of_service', 'terms_of_service-public');
91-
}
84+
if (\OC::$CLI) {
85+
return;
86+
}
87+
88+
// Skip login-related pages
89+
// TODO: Add a universal way to specify skipped pages instead of hardcoding
90+
$skipPatterns = [
91+
// Login
92+
'#^/login$#',
93+
// Login Flow Grant must have the terms of service
94+
// so that the user can accept them before using the app
95+
// TODO: add a checkbox on the login instead, like on the Registration app
96+
'#^/login/(?!flow/grant|v2/grant)#',
97+
// SAML
98+
'#^/saml$#',
99+
'#^/saml/#',
100+
// user_oidc
101+
'#^/code$#',
102+
'#^/sls$#',
103+
'#^/id4me$#',
104+
'#^/id4me/code$#',
105+
];
106+
if (array_filter($skipPatterns, fn($pattern) => preg_match($pattern, $request->getPathInfo()))) {
107+
return;
108+
}
109+
110+
if ($userSession->getUser() instanceof IUser) {
111+
// Logged-in user
112+
Util::addScript('terms_of_service', 'terms_of_service-user');
113+
} else if ($config->getAppValue(self::APPNAME, 'tos_on_public_shares', '0') === '1') {
114+
// Guests on public pages
115+
Util::addScript('terms_of_service', 'terms_of_service-public');
92116
}
117+
93118
}
94119

95120
public function addStorageWrapper(): void {

0 commit comments

Comments
 (0)