From 76594e599480c518e798aeffcd43d59746486752 Mon Sep 17 00:00:00 2001 From: Avneesh Hota Date: Tue, 1 Oct 2024 15:35:34 +0530 Subject: [PATCH 1/4] remove email request param from welcom detail api --- .../java/com/akto/action/DashboardAction.java | 29 +++++++++---------- .../components/WelcomeBackDetailsModal.jsx | 4 +-- .../web/src/apps/dashboard/pages/home/api.js | 4 +-- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/apps/dashboard/src/main/java/com/akto/action/DashboardAction.java b/apps/dashboard/src/main/java/com/akto/action/DashboardAction.java index 28eecc8388..4bd23e1711 100644 --- a/apps/dashboard/src/main/java/com/akto/action/DashboardAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/DashboardAction.java @@ -250,19 +250,16 @@ public String markConnectionAsSkipped(){ } } - private String email; private String username; private String organization; private final Pattern usernamePattern = Pattern.compile("^[\\w\\s-]{1,}$"); private final Pattern organizationPattern = Pattern.compile("^[\\w\\s.&-]{1,}$"); public String updateUsernameAndOrganization() { - this.setUsername(username.trim()); - this.setOrganization(organization.trim()); - - if(username.isEmpty()) { + if(username == null || username.trim().isEmpty()) { addActionError("Username cannot be empty"); return Action.ERROR.toUpperCase(); } + this.setUsername(username.trim()); if(!usernamePattern.matcher(username).matches()) { addActionError("Username is not valid"); @@ -274,18 +271,28 @@ public String updateUsernameAndOrganization() { return Action.ERROR.toUpperCase(); } + User userFromSession = getSUser(); + if (userFromSession == null) { + addActionError("Username can't be longer than 24 characters"); + return Action.ERROR.toUpperCase(); + } + + String email = userFromSession.getLogin(); + User user = UsersDao.instance.updateOneNoUpsert(Filters.in(User.LOGIN, email), Updates.combine( Updates.set(User.NAME, username), Updates.set(User.NAME_LAST_UPDATE, Context.now()) )); RBAC.Role currentRoleForUser = RBACDao.getCurrentRoleForUser(user.getId(), Context.accountId.get()); - if(currentRoleForUser.getName().equals(RBAC.Role.ADMIN.getName())) { - if(organization.isEmpty()) { + if(currentRoleForUser != null && currentRoleForUser.getName().equals(RBAC.Role.ADMIN.getName())) { + if(organization == null || organization.trim().isEmpty()) { addActionError("Organization cannot be empty"); return Action.ERROR.toUpperCase(); } + setOrganization(organization.trim()); + if(!organizationPattern.matcher(organization).matches()) { addActionError("Organization is not valid"); return Action.ERROR.toUpperCase(); @@ -389,14 +396,6 @@ public List getInitialHistoricalData() { return initialHistoricalData; } - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - public String getUsername() { return username; } diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/WelcomeBackDetailsModal.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/WelcomeBackDetailsModal.jsx index 55ecba22fe..c736cf1a18 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/WelcomeBackDetailsModal.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/WelcomeBackDetailsModal.jsx @@ -6,8 +6,8 @@ import homeRequests from "../pages/home/api" const WelcomeBackDetailsModal = ({ isAdmin }) => { const [modalToggle, setModalToggle] = useState(true) - const [username, setUsername] = useState(window.USER_FULL_NAME) - const [organization, setOrganization] = useState(window.ORGANIZATION_NAME) + const [username, setUsername] = useState(window.USER_FULL_NAME || "") + const [organization, setOrganization] = useState(window.ORGANIZATION_NAME || "") const handleWelcomeBackDetails = async () => { diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/home/api.js b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/home/api.js index ae44c09240..a55691ae45 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/home/api.js +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/home/api.js @@ -30,11 +30,11 @@ const homeRequests = { data: {} }) }, - updateUsernameAndOrganization: async(email, username, organization) => { + updateUsernameAndOrganization: async(username, organization) => { return await request({ url: 'api/updateUsernameAndOrganization', method: 'post', - data: {email, username, organization} + data: { username, organization} }) } } From e534e5f962ce0b2a97f78c3a79341941e092bab8 Mon Sep 17 00:00:00 2001 From: Avneesh Hota Date: Tue, 1 Oct 2024 15:36:45 +0530 Subject: [PATCH 2/4] fixed error message --- .../src/main/java/com/akto/action/DashboardAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dashboard/src/main/java/com/akto/action/DashboardAction.java b/apps/dashboard/src/main/java/com/akto/action/DashboardAction.java index 4bd23e1711..6239c6916b 100644 --- a/apps/dashboard/src/main/java/com/akto/action/DashboardAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/DashboardAction.java @@ -273,7 +273,7 @@ public String updateUsernameAndOrganization() { User userFromSession = getSUser(); if (userFromSession == null) { - addActionError("Username can't be longer than 24 characters"); + addActionError("Invalid user"); return Action.ERROR.toUpperCase(); } From 4a062a2134c96715dd6641ebbb850cc52830d79d Mon Sep 17 00:00:00 2001 From: TangoBeeAkto Date: Tue, 1 Oct 2024 17:05:42 +0530 Subject: [PATCH 3/4] fix: not showing welcome back modal until profileAction is loaded --- .../src/apps/dashboard/components/WelcomeBackDetailsModal.jsx | 4 +--- .../polaris_web/web/src/apps/dashboard/pages/Dashboard.jsx | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/WelcomeBackDetailsModal.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/WelcomeBackDetailsModal.jsx index c736cf1a18..eb8106eba1 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/WelcomeBackDetailsModal.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/WelcomeBackDetailsModal.jsx @@ -18,9 +18,7 @@ const WelcomeBackDetailsModal = ({ isAdmin }) => { return } - const email = window.USER_NAME - - homeRequests.updateUsernameAndOrganization(email ,username, organization).then((resp) => { + homeRequests.updateUsernameAndOrganization(username, organization).then((resp) => { try { setModalToggle(false) } catch (error) { diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/Dashboard.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/Dashboard.jsx index 60d62bad18..3ea55dacf7 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/Dashboard.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/Dashboard.jsx @@ -165,7 +165,7 @@ function Dashboard() { },[]) - const shouldShowWelcomeBackModal = !func.checkLocal() && (window?.USER_FULL_NAME?.length === 0 || (window.USER_ROLE === 'ADMIN' && window.ORGANIZATION_NAME?.length === 0)) + const shouldShowWelcomeBackModal = !func.checkLocal() && window?.USER_NAME?.length > 0 && (window?.USER_FULL_NAME?.length === 0 || (window?.USER_ROLE === 'ADMIN' && window?.ORGANIZATION_NAME?.length === 0)) return (
From 1736c0319af53d6dadad76f679dfc55533627f93 Mon Sep 17 00:00:00 2001 From: TangoBeeAkto Date: Tue, 1 Oct 2024 17:42:59 +0530 Subject: [PATCH 4/4] feat: disable welcome back modal --- .../polaris_web/web/src/apps/dashboard/pages/Dashboard.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/Dashboard.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/Dashboard.jsx index 3ea55dacf7..6013a836fe 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/Dashboard.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/Dashboard.jsx @@ -165,13 +165,13 @@ function Dashboard() { },[]) - const shouldShowWelcomeBackModal = !func.checkLocal() && window?.USER_NAME?.length > 0 && (window?.USER_FULL_NAME?.length === 0 || (window?.USER_ROLE === 'ADMIN' && window?.ORGANIZATION_NAME?.length === 0)) + // const shouldShowWelcomeBackModal = !func.checkLocal() && window?.USER_NAME?.length > 0 && (window?.USER_FULL_NAME?.length === 0 || (window?.USER_ROLE === 'ADMIN' && window?.ORGANIZATION_NAME?.length === 0)) return (
- {shouldShowWelcomeBackModal && } + {/* {shouldShowWelcomeBackModal && } */} {toastMarkup} {ConfirmationModalMarkup} {displayItems.length > 0 ?