kunwp1 commented on code in PR #9498:
URL: https://github.com/apache/texera/pull/9498#discussion_r4595595696


##########
common/config/src/main/scala/org/apache/texera/common/config/DefaultsConfig.scala:
##########
@@ -27,6 +27,11 @@ object DefaultsConfig {
   val reinit: Boolean =
     
conf.getBoolean("config-service.always-reset-configurations-to-default-values")
 
+  // Typed rather than read off `allDefaults`: HOCON's parsing keeps the 
spellings
+  // USER_SYS_INVITE_ONLY has always accepted (yes/no, on/off), and an 
unreadable value stops
+  // config-service at startup, when it loads this object to seed 
site_settings.
+  val inviteOnly: Boolean = conf.getBoolean("user-sys.invite_only")

Review Comment:
   With `USER_SYS_INVITE_ONLY=off` (or `no`), which this parse accepts, 
`allDefaults` seeds the row as the raw string `"off"`. The backend can't parse 
that, so it falls back to this value (`false`) and sign-up is open. The admin 
card treats anything other than `"false"` as on, though, so it shows Invite 
Only switched on, and Reset writes `"off"` back. I checked it with a throwaway 
test. With `off` and `no`, the seeded row is `"off"`/`"no"`, the backend ends 
up `false`, and the card shows on. With `true` and `false`, they agree.
   
   Seeding the parsed value keeps every reader on the same spelling:
   
   ```scala
     private val InviteOnlyPath = "user-sys.invite_only"
     val inviteOnly: Boolean = conf.getBoolean(InviteOnlyPath)
     ...
       entries.toMap.updated(shortKey(InviteOnlyPath), inviteOnly.toString)
   ```
   
   A spec case `DefaultsConfig.allDefaults.get("invite_only") shouldBe 
Some(DefaultsConfig.inviteOnly.toString)` fails today under 
`USER_SYS_INVITE_ONLY=off` and passes with this change.



##########
common/auth/src/main/scala/org/apache/texera/auth/InviteOnly.scala:
##########
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.auth
+
+import org.apache.texera.common.config.DefaultsConfig
+import org.apache.texera.dao.SiteSettings
+
+/**
+  * Whether a new account has to wait for an admin's approval before it can be 
used.
+  *
+  * The switch is the `invite_only` site setting, which admins flip on the 
Admin Settings page. It
+  * is read on every call, so a change reaches the next sign-up without a 
restart. default.conf's
+  * `user-sys.invite_only` (USER_SYS_INVITE_ONLY) seeds that row and stands in 
whenever the row is
+  * missing, unreadable or not a boolean.
+  */
+object InviteOnly {
+
+  /** The `site_settings` key, which is also the default.conf leaf that seeds 
it. */
+  val SettingKey = "invite_only"
+
+  def enabled: Boolean = SiteSettings.getBoolean(SettingKey, 
DefaultsConfig.inviteOnly)

Review Comment:
   Since a REGULAR account can run code, should a failed read here fall back to 
on rather than to the seeded default? Say `USER_SYS_INVITE_ONLY=false` and an 
admin later turns the switch on in Admin → Settings. A read that fails, for 
example on a pool timeout, then admits that sign-up as REGULAR. A missing row 
could still use the seed; only an error would need to fail closed.



##########
frontend/src/app/hub/component/login/texera-login.component.ts:
##########
@@ -339,7 +345,23 @@ export class TexeraLoginComponent implements OnInit {
         }),
         untilDestroyed(this)
       )
-      .subscribe(() => this.notificationService.success(ACCOUNT_CREATED));
+      .subscribe(() => this.finishSignup());
+  }
+
+  /**
+   * Close a sign-up that created the account. Registering signs the user in, 
so an account that can
+   * already be used (invite-only off) goes where a sign-in would. An account 
waiting for an admin is
+   * INACTIVE: the session is signed straight back out, or kept by a page 
whose config predates
+   * invite-only being turned on. Either way the user stays here and is told 
to wait.
+   */
+  private finishSignup(): void {
+    const user = this.userService.getCurrentUser();
+    if (user !== undefined && user.role !== Role.INACTIVE) {
+      this.notificationService.success(ACCOUNT_READY);
+      this.navigateAfterLogin();
+    } else {
+      this.notificationService.success(ACCOUNT_PENDING);
+    }

Review Comment:
   `finishSignup` decides on the role alone, but 
`AuthService.loginWithExistingToken` still shows Access Pending only when 
`config.env.inviteOnly && role === Role.INACTIVE`. Now that the switch can be 
turned off at runtime, an account that signed up while it was on is still 
waiting, as the admin card says. If it signs in after the switch goes off, it 
lands on a dashboard where every request is refused. Checking the role alone 
there would keep the pending screen for those accounts, and the flag would 
still control the sign-up hint.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to