mirror of
https://github.com/HangarMC/Hangar.git
synced 2025-02-05 14:40:33 +08:00
fix null permissions on org pages
This commit is contained in:
parent
9c0767b804
commit
c8bd4c0442
@ -9,6 +9,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class PermissionService {
|
||||
|
||||
@ -43,7 +45,7 @@ public class PermissionService {
|
||||
else return Permission.None;
|
||||
}
|
||||
if (includeGlobal) return addDefaults(permissionsDao.get().getProjectPermission(usersTable.getId(), pluginId));
|
||||
return permissionsDao.get().getProjectPermission(usersTable.getId(), pluginId);
|
||||
return orNone(permissionsDao.get().getProjectPermission(usersTable.getId(), pluginId));
|
||||
}
|
||||
|
||||
public Permission getOrganizationPermissions(UsersTable usersTable, String orgName) {
|
||||
@ -56,7 +58,7 @@ public class PermissionService {
|
||||
else return Permission.None;
|
||||
}
|
||||
if (includeGlobal) return addDefaults(permissionsDao.get().getOrgPermission(usersTable.getId(), orgName));
|
||||
else return permissionsDao.get().getOrgPermission(usersTable.getId(), orgName);
|
||||
else return orNone(permissionsDao.get().getOrgPermission(usersTable.getId(), orgName));
|
||||
}
|
||||
|
||||
public Permission getPossibleProjectPermissions(long userId) {
|
||||
@ -67,6 +69,10 @@ public class PermissionService {
|
||||
return addDefaults(permissionsDao.get().getPossibleOrganizationPermissions(userId));
|
||||
}
|
||||
|
||||
private Permission orNone(@Nullable Permission permission) {
|
||||
return Objects.requireNonNullElse(permission, Permission.None);
|
||||
}
|
||||
|
||||
private Permission addDefaults(@Nullable Permission permission) {
|
||||
if (permission == null) {
|
||||
return DEFAULT_GLOBAL_PERMISSIONS;
|
||||
|
@ -170,7 +170,7 @@ public class UserService {
|
||||
});
|
||||
List<Role> globalRoles = roleService.getGlobalRolesForUser(user.getId(), null);
|
||||
boolean isOrga = globalRoles.contains(Role.ORGANIZATION);
|
||||
Permission userPerm = Permission.All; // TODO perms here
|
||||
Permission userPerm = permissionService.getGlobalPermissions(user.getId());
|
||||
Permission orgaPerm = Permission.None; // TODO perms here
|
||||
return new UserData(getHeaderData(), user, isOrga, projectCount, organizations, globalRoles, userPerm, orgaPerm);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user