From 617ab2f782c8601b4d8cf6503ee3b2c118232a20 Mon Sep 17 00:00:00 2001 From: Yinyin Liu Date: Tue, 3 Feb 2026 13:52:20 +0100 Subject: [PATCH] fixed the bug of Sodistore Home Product not show on side bar and added related backend logs and more accurate frontend error messages --- csharp/App/Backend/Controller.cs | 22 ++++++-- .../App/Backend/DataTypes/Methods/Session.cs | 54 ++++++++++++++++--- typescript/frontend-marios2/src/App.tsx | 2 +- .../dashboards/ManageAccess/UserAccess.tsx | 16 +++++- 4 files changed, 80 insertions(+), 14 deletions(-) diff --git a/csharp/App/Backend/Controller.cs b/csharp/App/Backend/Controller.cs index 1fd23700e..41c7f70c6 100644 --- a/csharp/App/Backend/Controller.cs +++ b/csharp/App/Backend/Controller.cs @@ -596,7 +596,14 @@ public class Controller : ControllerBase var folder = Db.GetFolderById(folderAccess.FolderId); var user = Db.GetUserById(folderAccess.UserId); - return session.GrantUserAccessTo(user, folder) + // Check if user already has access - treat as idempotent (success) + if (user is not null && folder is not null && user.HasAccessTo(folder)) + { + Console.WriteLine($"GrantUserAccessToFolder: User {user.Id} ({user.Name}) already has access to folder {folder.Id} ({folder.Name}) - returning success"); + return Ok(); + } + + return session.GrantUserAccessTo(user, folder) ? Ok() : Unauthorized(); } @@ -621,12 +628,19 @@ public class Controller : ControllerBase public ActionResult GrantUserAccessToInstallation(InstallationAccess installationAccess, Token authToken) { var session = Db.GetSession(authToken); - + // TODO: automatic BadRequest when properties are null during deserialization var installation = Db.GetInstallationById(installationAccess.InstallationId); var user = Db.GetUserById(installationAccess.UserId); - - return session.GrantUserAccessTo(user, installation) + + // Check if user already has access - treat as idempotent (success) + if (user is not null && installation is not null && user.HasAccessTo(installation)) + { + Console.WriteLine($"GrantUserAccessToInstallation: User {user.Id} ({user.Name}) already has access to installation {installation.Id} ({installation.Name}) - returning success"); + return Ok(); + } + + return session.GrantUserAccessTo(user, installation) ? Ok() : Unauthorized(); } diff --git a/csharp/App/Backend/DataTypes/Methods/Session.cs b/csharp/App/Backend/DataTypes/Methods/Session.cs index b57f66e0b..110b9ab1b 100644 --- a/csharp/App/Backend/DataTypes/Methods/Session.cs +++ b/csharp/App/Backend/DataTypes/Methods/Session.cs @@ -405,13 +405,53 @@ public static class SessionMethods { var sessionUser = session?.User; - return sessionUser is not null - && folder is not null - && user is not null - && user.IsDescendantOf(sessionUser) - && sessionUser.HasAccessTo(folder) - && !user.HasAccessTo(folder) - && Db.Create(new FolderAccess { UserId = user.Id, FolderId = folder.Id }); + if (sessionUser is null) + { + Console.WriteLine($"GrantUserAccessToFolder failed: sessionUser is null"); + return false; + } + + if (folder is null) + { + Console.WriteLine($"GrantUserAccessToFolder failed: folder is null"); + return false; + } + + if (user is null) + { + Console.WriteLine($"GrantUserAccessToFolder failed: user is null"); + return false; + } + + if (!user.IsDescendantOf(sessionUser)) + { + Console.WriteLine($"GrantUserAccessToFolder failed: User {user.Id} ({user.Name}) is not a descendant of sessionUser {sessionUser.Id} ({sessionUser.Name})"); + return false; + } + + if (!sessionUser.HasAccessTo(folder)) + { + Console.WriteLine($"GrantUserAccessToFolder failed: SessionUser {sessionUser.Id} ({sessionUser.Name}) does not have access to folder {folder.Id} ({folder.Name})"); + return false; + } + + if (user.HasAccessTo(folder)) + { + Console.WriteLine($"GrantUserAccessToFolder failed: User {user.Id} ({user.Name}) already has access to folder {folder.Id} ({folder.Name})"); + return false; + } + + var created = Db.Create(new FolderAccess { UserId = user.Id, FolderId = folder.Id }); + if (!created) + { + Console.WriteLine($"GrantUserAccessToFolder failed: Failed to create FolderAccess record for User {user.Id} and Folder {folder.Id}"); + } + else + { + Console.WriteLine($"GrantUserAccessToFolder succeeded: Granted User {user.Id} ({user.Name}) access to Folder {folder.Id} ({folder.Name})"); + } + + return created; } public static Boolean RevokeUserAccessTo(this Session? session, User? user, Installation? installation) diff --git a/typescript/frontend-marios2/src/App.tsx b/typescript/frontend-marios2/src/App.tsx index d90d7a868..8ea1209fe 100644 --- a/typescript/frontend-marios2/src/App.tsx +++ b/typescript/frontend-marios2/src/App.tsx @@ -76,7 +76,7 @@ function App() { setUser(response.data.user); setAccessToSalimax(response.data.accessToSalimax); setAccessToSalidomo(response.data.accessToSalidomo); - setAccessToSodiohome(response.data.accessToSodiohome); + setAccessToSodiohome(response.data.accessToSodioHome); setAccessToSodistore(response.data.accessToSodistoreMax); if (response.data.accessToSalimax) { navigate(routes.installations); diff --git a/typescript/frontend-marios2/src/content/dashboards/ManageAccess/UserAccess.tsx b/typescript/frontend-marios2/src/content/dashboards/ManageAccess/UserAccess.tsx index 4c39af2ac..a0b8f5ddf 100644 --- a/typescript/frontend-marios2/src/content/dashboards/ManageAccess/UserAccess.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/ManageAccess/UserAccess.tsx @@ -172,7 +172,13 @@ function UserAccess(props: UserAccessProps) { } }) .catch((err) => { - setErrorMessage('An error has occured'); + if (err.response && err.response.status === 401) { + setErrorMessage( + `User ${props.current_user.name} already has access to folder "${folder.name}" or you don't have permission to grant this access` + ); + } else { + setErrorMessage('An error has occured'); + } setError(true); }); } @@ -195,7 +201,13 @@ function UserAccess(props: UserAccessProps) { } }) .catch((err) => { - setErrorMessage('An error has occured'); + if (err.response && err.response.status === 401) { + setErrorMessage( + `User ${props.current_user.name} already has access to installation "${installation.name}" or you don't have permission to grant this access` + ); + } else { + setErrorMessage('An error has occured'); + } setError(true); }); }