Fix desktop UX and configuration

Changes:
- MainLayoutController: Analytics access restricted to ADMIN only
  - STAFF users default to Sales view instead of Analytics
  - Logo click redirects STAFF to Sales, ADMIN to Analytics
  - Analytics button hidden for STAFF users
- LoginController: Added CUSTOMER login rejection with clear message
  - CUSTOMER role users are now rejected at login with helpful error
  - Directs customers to use web/mobile applications instead
- Configuration cleanup: Removed connectionpetstore.properties from project root
  - Config file remains in src/main/resources for proper packaging
  - ApiConfig already loads from classpath correctly

These changes ensure proper role-based access control and clean configuration management.
This commit is contained in:
2026-03-09 01:32:40 -06:00
parent 90a6d5d464
commit 37327742ae
3 changed files with 28 additions and 5 deletions

View File

@@ -63,6 +63,13 @@ public class LoginController {
if (token == null || roleStr == null) {
throw new IllegalStateException("Token or role is null");
}
if ("CUSTOMER".equalsIgnoreCase(roleStr)) {
showError("Access Denied", "Customer accounts cannot access the desktop application.\n\nPlease use the web or mobile application instead.");
txtPassword.clear();
return;
}
Role role = Role.valueOf(roleStr.toUpperCase());
UserSession.getInstance().login(null, username, role, token);

View File

@@ -173,8 +173,14 @@ public class MainLayoutController {
@FXML
void logoClicked(MouseEvent event) {
loadView("analytics-view.fxml");
updateButtons(btnAnalytics);
UserSession session = UserSession.getInstance();
if (session.isAdmin()) {
loadView("analytics-view.fxml");
updateButtons(btnAnalytics);
} else {
loadView("sale-view.fxml");
updateButtons(btnSalesHistory);
}
}
@FXML
@@ -201,8 +207,14 @@ public class MainLayoutController {
public void initialize() {
applyRBAC();
loadView("analytics-view.fxml");
updateButtons(btnAnalytics);
UserSession session = UserSession.getInstance();
if (session.isAdmin()) {
loadView("analytics-view.fxml");
updateButtons(btnAnalytics);
} else {
loadView("sale-view.fxml");
updateButtons(btnSalesHistory);
}
}
private void applyRBAC() {
@@ -241,6 +253,11 @@ public class MainLayoutController {
separatorAdmin.setManaged(isAdmin);
}
if (btnAnalytics != null) {
btnAnalytics.setVisible(isAdmin);
btnAnalytics.setManaged(isAdmin);
}
btnSalesHistory.setText(isAdmin ? "Sales History" : "Sales");