aicam commented on code in PR #4185:
URL: https://github.com/apache/texera/pull/4185#discussion_r2755846745


##########
amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/UserResource.scala:
##########
@@ -71,4 +72,48 @@ class UserResource {
     }
     java.lang.Boolean.valueOf(user.getAffiliation == null)
   }
+
+  /**
+   * Checks whether the user needs to submit joining reason.
+   * null: never prompted, need to prompt -> return true
+   * not null: already prompted, no need to prompt -> return false
+   * @param uid: user id
+   * @return boolean value to whether prompt user to enter joining reason or 
not
+   */
+  @GET
+  @Path("/joining-reason/required")

Review Comment:
   I think previously we had another way to check if user has submitted request 
or not, have you removed that since we are using this new endpoint?



##########
amber/src/main/scala/org/apache/texera/web/auth/UserAuthenticator.scala:
##########
@@ -43,6 +43,7 @@ object UserAuthenticator extends Authenticator[JwtContext, 
SessionUser] with Laz
       val comment = 
context.getJwtClaims.getClaimValue("comment").asInstanceOf[String]
       val accountCreation =
         
context.getJwtClaims.getClaimValue("accountCreation").asInstanceOf[OffsetDateTime]
+      val joiningReason = 
context.getJwtClaims.getClaimValue("joiningReason").asInstanceOf[String]

Review Comment:
   You can remove joining reason from token, it may be long and make token 
unnecessary long and take time and resource for processing



##########
frontend/src/app/common/service/user/auth.service.ts:
##########
@@ -177,4 +196,73 @@ export class AuthService {
   static removeAccessToken(): void {
     localStorage.removeItem(TOKEN_KEY);
   }
+
+  /**
+   * Returns true if the system needs to prompt the user with the registration 
form
+   * @param uid
+   * @private
+   */
+  private checkRegistrationRequired(uid: number): Observable<boolean> {
+    return 
this.http.get<boolean>(`${AppSettings.getApiEndpoint()}/user/joining-reason/required`,
 {
+      params: { uid: uid.toString() },
+    });
+  }
+
+  /**
+   * Submits changes to the backend with affiliation and joining reason
+   * @param uid
+   * @param affiliation
+   * @param reason
+   * @private
+   */
+  private submitRegistration(uid: number, affiliation: string, reason: 
string): Observable<void> {
+    return 
this.http.put<void>(`${AppSettings.getApiEndpoint()}/user/joining-reason`, {
+      uid,
+      affiliation,
+      joiningReason: reason,
+    });
+  }
+
+  /**
+   * Opens the registration modal (registration request modal)
+   * @param uid
+   * @param email
+   * @param defaultName
+   * @private
+   */
+  private openRegistrationModal(uid: number, email: string, defaultName: 
string): void {
+    const modalRef = this.modal.create<RegistrationRequestModalComponent>({
+      nzContent: RegistrationRequestModalComponent,
+      nzData: { uid, email, name: defaultName },
+      nzOkText: "Send request to Admin",
+      nzCancelText: "Cancel",
+      nzMaskClosable: false,
+      nzClosable: false,
+
+      nzOnOk: async () => {

Review Comment:
   Can we move this to `RegistrationRequestModalComponent`? currently its just 
50 lines and this logic is very specific to its component so I think it can be 
there



##########
frontend/src/app/common/service/user/auth.service.ts:
##########
@@ -127,16 +128,33 @@ export class AuthService {
     }
 
     const role = this.jwtHelperService.decodeToken(token).role;
+    const uid = this.jwtHelperService.decodeToken(token).userId;
     const email = this.jwtHelperService.decodeToken(token).email;
-    if (this.config.env.inviteOnly && role == Role.INACTIVE) {
-      this.modal.confirm({
-        nzTitle: "You Need Access",
-        nzContent:
-          "Currently the platform is invitation-only. Please request access 
from the platform admin or switch to an account that already has access.",
-        nzOkText: "Send request to Admin",
-        nzCancelText: "Cancel",
-        nzOnOk: () => this.gmailService.notifyUnauthorizedLogin(email),
-      });
+    const name = this.jwtHelperService.decodeToken(token).sub;
+
+    if (this.config.env.inviteOnly && role === Role.INACTIVE) {
+      setTimeout(() => {
+        this.checkRegistrationRequired(uid).subscribe(required => {
+          if (required) {
+            this.openRegistrationModal(uid, email, name);
+          } else {
+            this.modal.info({
+              nzTitle: "Access Pending",
+              nzContent: `
+            Your account is still inactive, and we already received your 
request.
+            Please wait for an admin to approve your access.
+          `,
+              nzOkText: "OK",
+              nzMaskClosable: false,
+              nzClosable: false,
+              nzOnOk: () => {
+                this.logout();
+                return true;
+              },
+            });
+          }
+        });
+      }, 0);

Review Comment:
   Why do we need timeout when its 0 millisecond?



##########
frontend/src/app/common/service/user/registration-request-modal/registration-request-modal.component.html:
##########
@@ -0,0 +1,46 @@
+<!--
+ 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.
+-->
+<ng-template #modalTitle>

Review Comment:
   is this a new component? if yes, have you deleted the old one?



-- 
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