Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHANGE #831: Allow accounts with Dev level to see error #832

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/me/universi/api/entities/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static Response buildResponse(ThrowingConsumer<Response> completionHandle
}
} else {
// unknown exception occurred
response.message = "Ocorreu um erro interno por parte do servidor." + (UserService.getInstance().isProduction() ? "" : "\n (" + e.getMessage() + ")");
response.message = "Ocorreu um erro interno por parte do servidor." + ((UserService.getInstance().isProduction() || !UserService.getInstance().isUserDevSession()) ? "" : "\n (" + e.getMessage() + ")");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acho que isso faz com que os usuários ADMIN_ROLE não consigam ver as mensagens de erro. Precisaria trocar o nosso nível de acesso nas instâncias, é isso mesmo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entendi vou ajustar o nivel, pq esta admin > dev > user, o dev pode ver as mensagens de debug mas fica limitado a somente isso ai realmente precisaria ficaria mudando td tempo so pra ver os errors, acho q seria melhor dev > admin > user

response.alertOptions.put("html", response.message + "<br/><br/><img src=\"https://i.imgur.com/OWV6eKo.gif\" width='70%'/>");
}

Expand Down
21 changes: 18 additions & 3 deletions src/main/java/me/universi/user/services/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,23 +420,38 @@ public boolean userIsLoggedIn() {
}

// check if user has authority following springsecurity hierarchy
public boolean userHasAuthority(User user, Authority authority) {
public boolean userHasAuthority(User user, Authority authority, boolean equal) {
if(equal) {
return user.getAuthority().equals(authority);
}
Collection<? extends GrantedAuthority> reachableRoles = roleHierarchy.getReachableGrantedAuthorities(user.getAuthorities());
return reachableRoles.contains(new SimpleGrantedAuthority(authority.toString()));
}

public boolean isUserAdmin(User userSession) {
public boolean isUserRole(User user, Authority role, boolean equal) {
try {
return userHasAuthority(userSession, Authority.ROLE_ADMIN);
return userHasAuthority(user, role, equal);
} catch (Exception e) {
return false;
}
}

public boolean isUserAdmin(User userSession) {
return isUserRole(userSession, Authority.ROLE_ADMIN, false);
}

public boolean isUserDev(User userSession) {
return isUserRole(userSession, Authority.ROLE_DEV, false);
}

public boolean isUserAdminSession() {
return isUserAdmin(getUserInSession());
}

public boolean isUserDevSession() {
return isUserDev(getUserInSession());
}

public boolean userNeedAnProfile(User user, boolean checkAdmin) {
try {
if(checkAdmin && isUserAdmin(user)) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/spring-security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
<beans:bean id="roleHierarchy" class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl">
<beans:property name="hierarchy">
<beans:value>
ROLE_ADMIN > ROLE_DEV > ROLE_USER
ROLE_DEV > ROLE_ADMIN > ROLE_USER
</beans:value>
</beans:property>
</beans:bean>
Expand Down
Loading