mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-11-27 06:01:08 +08:00
Actually use role data from db
This commit is contained in:
parent
9653dd04c7
commit
dcfdd0b488
@ -6,6 +6,15 @@
|
||||
<fileSet type="globPattern" pattern="frontend/*" />
|
||||
</list>
|
||||
</option>
|
||||
<JavaCodeStyleSettings>
|
||||
<option name="IMPORT_LAYOUT_TABLE">
|
||||
<value>
|
||||
<package name="" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="" withSubpackages="true" static="true" />
|
||||
</value>
|
||||
</option>
|
||||
</JavaCodeStyleSettings>
|
||||
<SqlCodeStyleSettings version="6">
|
||||
<option name="KEYWORD_CASE" value="2" />
|
||||
<option name="IDENTIFIER_CASE" value="1" />
|
||||
@ -36,4 +45,4 @@
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
</component>
|
@ -8,6 +8,8 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.papermc.hangar.config.CacheConfig;
|
||||
import io.papermc.hangar.config.hangar.HangarConfig;
|
||||
import io.papermc.hangar.db.customtypes.RoleCategory;
|
||||
import io.papermc.hangar.db.dao.internal.table.roles.RolesDAO;
|
||||
import io.papermc.hangar.model.Announcement;
|
||||
import io.papermc.hangar.model.common.Color;
|
||||
import io.papermc.hangar.model.common.NamedPermission;
|
||||
@ -16,9 +18,7 @@ import io.papermc.hangar.model.common.Prompt;
|
||||
import io.papermc.hangar.model.common.projects.Category;
|
||||
import io.papermc.hangar.model.common.projects.FlagReason;
|
||||
import io.papermc.hangar.model.common.projects.Visibility;
|
||||
import io.papermc.hangar.model.common.roles.GlobalRole;
|
||||
import io.papermc.hangar.model.common.roles.OrganizationRole;
|
||||
import io.papermc.hangar.model.common.roles.ProjectRole;
|
||||
import io.papermc.hangar.model.common.roles.RoleData;
|
||||
import io.papermc.hangar.model.internal.api.responses.Validations;
|
||||
import io.papermc.hangar.model.internal.logs.LogAction;
|
||||
import io.papermc.hangar.security.annotations.Anyone;
|
||||
@ -50,13 +50,15 @@ public class BackendDataController {
|
||||
private final HangarConfig config;
|
||||
private final PlatformService platformService;
|
||||
private final Optional<GitProperties> gitProperties;
|
||||
private final RolesDAO rolesDAO;
|
||||
|
||||
@Autowired
|
||||
public BackendDataController(final ObjectMapper mapper, final HangarConfig config, final PlatformService platformService, final Optional<GitProperties> gitProperties) {
|
||||
public BackendDataController(final ObjectMapper mapper, final HangarConfig config, final PlatformService platformService, final Optional<GitProperties> gitProperties, final RolesDAO rolesDAO) {
|
||||
this.config = config;
|
||||
this.objectMapper = mapper.copy();
|
||||
this.platformService = platformService;
|
||||
this.gitProperties = gitProperties;
|
||||
this.rolesDAO = rolesDAO;
|
||||
this.objectMapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
|
||||
@Override
|
||||
protected <A extends Annotation> A _findAnnotation(final Annotated annotated, final Class<A> annoClass) {
|
||||
@ -144,22 +146,22 @@ public class BackendDataController {
|
||||
@GetMapping("/projectRoles")
|
||||
@Cacheable(CacheConfig.PROJECT_ROLES)
|
||||
@ResponseBody
|
||||
public List<ProjectRole> getAssignableProjectRoles() {
|
||||
return ProjectRole.getAssignableRoles();
|
||||
public List<RoleData> getAssignableProjectRoles() {
|
||||
return this.rolesDAO.getAssignableRoles(RoleCategory.PROJECT);
|
||||
}
|
||||
|
||||
@GetMapping("/globalRoles")
|
||||
@Cacheable(CacheConfig.GLOBAL_ROLES)
|
||||
@ResponseBody
|
||||
public GlobalRole[] getGlobalRoles() {
|
||||
return GlobalRole.getValues();
|
||||
public List<RoleData> getGlobalRoles() {
|
||||
return this.rolesDAO.getRoles(RoleCategory.GLOBAL);
|
||||
}
|
||||
|
||||
@GetMapping("/orgRoles")
|
||||
@Cacheable(CacheConfig.ORG_ROLES)
|
||||
@ResponseBody
|
||||
public List<OrganizationRole> getAssignableOrganizationRoles() {
|
||||
return OrganizationRole.getAssignableRoles();
|
||||
public List<RoleData> getAssignableOrganizationRoles() {
|
||||
return this.rolesDAO.getAssignableRoles(RoleCategory.ORGANIZATION);
|
||||
}
|
||||
|
||||
@GetMapping("/licenses")
|
||||
|
@ -1,6 +1,9 @@
|
||||
package io.papermc.hangar.db.dao.internal.table.roles;
|
||||
|
||||
import io.papermc.hangar.db.customtypes.RoleCategory;
|
||||
import io.papermc.hangar.model.common.roles.RoleData;
|
||||
import io.papermc.hangar.model.db.roles.RoleTable;
|
||||
import java.util.List;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.jdbi.v3.sqlobject.config.RegisterConstructorMapper;
|
||||
import org.jdbi.v3.sqlobject.customizer.BindBean;
|
||||
@ -17,9 +20,17 @@ public interface RolesDAO {
|
||||
@SqlUpdate("INSERT INTO roles VALUES (:id, :now, :name, :category, :title, :color, :assignable, :rank, cast(:permission AS bit(64)))")
|
||||
void insert(@BindBean RoleTable roleTable);
|
||||
|
||||
@SqlUpdate("UPDATE roles VALUES SET title = :title, color = :color, rank = :rank WHERE id = :id")
|
||||
@SqlUpdate("UPDATE roles values SET title = :title, color = :color, rank = :rank WHERE id = :id")
|
||||
void update(long id, String title, String color, @Nullable Integer rank);
|
||||
|
||||
@SqlQuery("SELECT id, created_at, name, category, title, color, assignable, rank, permission::bigint FROM roles WHERE id = :id")
|
||||
RoleTable getById(long id);
|
||||
|
||||
@SqlQuery("SELECT id AS roleid, created_at, name AS value, category AS rolecategory, title, color, assignable, rank, permission::bigint AS permissions FROM roles WHERE category = :category")
|
||||
@RegisterConstructorMapper(RoleData.class)
|
||||
List<RoleData> getRoles(RoleCategory category);
|
||||
|
||||
@SqlQuery("SELECT id AS roleid, created_at, name AS value, category AS rolecategory, title, color, assignable, rank, permission::bigint AS permissions FROM roles WHERE category = :category AND assignable")
|
||||
@RegisterConstructorMapper(RoleData.class)
|
||||
List<RoleData> getAssignableRoles(RoleCategory category);
|
||||
}
|
||||
|
@ -21,9 +21,7 @@ public enum GlobalRole implements Role<GlobalRoleTable> {
|
||||
|
||||
DUMMY("Dummy", 42, Permission.ViewPublicInfo, "Dummy", Color.CHARTREUSE, 42),
|
||||
|
||||
ORGANIZATION("Organization", 100, OrganizationRole.ORGANIZATION_OWNER.getPermissions(), "Organization", Color.PURPLE);
|
||||
|
||||
private static final GlobalRole[] VALUES = values();
|
||||
ORGANIZATION("Organization", 100, OrganizationRole.ORGANIZATION_OWNER.permissions(), "Organization", Color.PURPLE);
|
||||
|
||||
private final String value;
|
||||
private final long roleId;
|
||||
@ -47,42 +45,42 @@ public enum GlobalRole implements Role<GlobalRoleTable> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getValue() {
|
||||
public @NotNull String value() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRoleId() {
|
||||
public long roleId() {
|
||||
return this.roleId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull RoleCategory getRoleCategory() {
|
||||
public @NotNull RoleCategory roleCategory() {
|
||||
return RoleCategory.GLOBAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Permission getPermissions() {
|
||||
public @NotNull Permission permissions() {
|
||||
return this.permissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getTitle() {
|
||||
public @NotNull String title() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Color getColor() {
|
||||
public @NotNull Color color() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignable() {
|
||||
public boolean assignable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Integer getRank() {
|
||||
public @Nullable Integer rank() {
|
||||
return this.rank;
|
||||
}
|
||||
|
||||
@ -99,8 +97,4 @@ public enum GlobalRole implements Role<GlobalRoleTable> {
|
||||
}
|
||||
throw new IllegalArgumentException("No GlobalRole '" + apiValue + "'");
|
||||
}
|
||||
|
||||
public static GlobalRole[] getValues() {
|
||||
return VALUES;
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,6 @@ import io.papermc.hangar.db.customtypes.RoleCategory;
|
||||
import io.papermc.hangar.model.common.Color;
|
||||
import io.papermc.hangar.model.common.Permission;
|
||||
import io.papermc.hangar.model.db.roles.OrganizationRoleTable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.postgresql.shaded.com.ongres.scram.common.util.Preconditions;
|
||||
@ -15,11 +13,11 @@ import org.postgresql.shaded.com.ongres.scram.common.util.Preconditions;
|
||||
public enum OrganizationRole implements Role<OrganizationRoleTable> {
|
||||
|
||||
ORGANIZATION_SUPPORT("Organization_Support", 20, Permission.PostAsOrganization.add(Permission.IsOrganizationMember), "Support", Color.TRANSPARENT, 60),
|
||||
ORGANIZATION_EDITOR("Organization_Editor", 21, ProjectRole.PROJECT_EDITOR.getPermissions().add(ORGANIZATION_SUPPORT.permissions), "Editor", Color.TRANSPARENT, 50),
|
||||
ORGANIZATION_DEVELOPER("Organization_Developer", 22, ProjectRole.PROJECT_DEVELOPER.getPermissions().add(ORGANIZATION_EDITOR.permissions), "Developer", Color.TRANSPARENT, 40),
|
||||
ORGANIZATION_MAINTAINER("Organization_Maintainer", 23, Permission.CreateProject.add(Permission.EditProjectSettings).add(ProjectRole.PROJECT_MAINTAINER.getPermissions()).add(ORGANIZATION_DEVELOPER.permissions), "Maintainer", Color.TRANSPARENT, 30),
|
||||
ORGANIZATION_ADMIN("Organization_Admin", 24, Permission.IsOrganizationAdmin.add(ORGANIZATION_MAINTAINER.permissions).add(ProjectRole.PROJECT_ADMIN.getPermissions()), "Owner", Color.TRANSPARENT, 20),
|
||||
ORGANIZATION_OWNER("Organization_Owner", 25, Permission.IsOrganizationOwner.add(ProjectRole.PROJECT_OWNER.getPermissions()).add(ORGANIZATION_ADMIN.permissions), "Owner", Color.PURPLE, 10, false);
|
||||
ORGANIZATION_EDITOR("Organization_Editor", 21, ProjectRole.PROJECT_EDITOR.permissions().add(ORGANIZATION_SUPPORT.permissions), "Editor", Color.TRANSPARENT, 50),
|
||||
ORGANIZATION_DEVELOPER("Organization_Developer", 22, ProjectRole.PROJECT_DEVELOPER.permissions().add(ORGANIZATION_EDITOR.permissions), "Developer", Color.TRANSPARENT, 40),
|
||||
ORGANIZATION_MAINTAINER("Organization_Maintainer", 23, Permission.CreateProject.add(Permission.EditProjectSettings).add(ProjectRole.PROJECT_MAINTAINER.permissions()).add(ORGANIZATION_DEVELOPER.permissions), "Maintainer", Color.TRANSPARENT, 30),
|
||||
ORGANIZATION_ADMIN("Organization_Admin", 24, Permission.IsOrganizationAdmin.add(ORGANIZATION_MAINTAINER.permissions).add(ProjectRole.PROJECT_ADMIN.permissions()), "Owner", Color.TRANSPARENT, 20),
|
||||
ORGANIZATION_OWNER("Organization_Owner", 25, Permission.IsOrganizationOwner.add(ProjectRole.PROJECT_OWNER.permissions()).add(ORGANIZATION_ADMIN.permissions), "Owner", Color.PURPLE, 10, false);
|
||||
|
||||
private final String value;
|
||||
private final long roleId;
|
||||
@ -29,17 +27,6 @@ public enum OrganizationRole implements Role<OrganizationRoleTable> {
|
||||
private final boolean isAssignable;
|
||||
private final int rank;
|
||||
|
||||
private static final OrganizationRole[] VALUES = values();
|
||||
private static final List<OrganizationRole> ASSIGNABLE_ROLES = Arrays.stream(VALUES).filter(OrganizationRole::isAssignable).toList();
|
||||
|
||||
public static OrganizationRole[] getValues() {
|
||||
return VALUES;
|
||||
}
|
||||
|
||||
public static List<OrganizationRole> getAssignableRoles() {
|
||||
return ASSIGNABLE_ROLES;
|
||||
}
|
||||
|
||||
OrganizationRole(final String value, final long roleId, final Permission permissions, final String title, final Color color, final int rank) {
|
||||
this(value, roleId, permissions, title, color, rank, true);
|
||||
}
|
||||
@ -56,42 +43,42 @@ public enum OrganizationRole implements Role<OrganizationRoleTable> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getValue() {
|
||||
public @NotNull String value() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRoleId() {
|
||||
public long roleId() {
|
||||
return this.roleId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull RoleCategory getRoleCategory() {
|
||||
public @NotNull RoleCategory roleCategory() {
|
||||
return RoleCategory.ORGANIZATION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Permission getPermissions() {
|
||||
public @NotNull Permission permissions() {
|
||||
return this.permissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getTitle() {
|
||||
public @NotNull String title() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Color getColor() {
|
||||
public @NotNull Color color() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignable() {
|
||||
public boolean assignable() {
|
||||
return this.isAssignable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getRank() {
|
||||
public Integer rank() {
|
||||
return this.rank;
|
||||
}
|
||||
|
||||
|
@ -5,10 +5,7 @@ import io.papermc.hangar.db.customtypes.RoleCategory;
|
||||
import io.papermc.hangar.model.common.Color;
|
||||
import io.papermc.hangar.model.common.Permission;
|
||||
import io.papermc.hangar.model.db.roles.ProjectRoleTable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.postgresql.shaded.com.ongres.scram.common.util.Preconditions;
|
||||
@ -17,11 +14,11 @@ import org.postgresql.shaded.com.ongres.scram.common.util.Preconditions;
|
||||
public enum ProjectRole implements Role<ProjectRoleTable> {
|
||||
|
||||
PROJECT_SUPPORT("Project_Support", 30, Permission.IsProjectMember, "Support", Color.TRANSPARENT, 60),
|
||||
PROJECT_EDITOR("Project_Editor", 31, Permission.EditPage.add(PROJECT_SUPPORT.getPermissions()), "Editor", Color.TRANSPARENT, 50),
|
||||
PROJECT_DEVELOPER("Project_Developer", 32, PROJECT_EDITOR.getPermissions(), "Developer", Color.TRANSPARENT, 40),
|
||||
PROJECT_MAINTAINER("Project_Maintainer", 33, Permission.CreateVersion.add(Permission.EditVersion).add(Permission.DeleteVersion).add(Permission.EditTags).add(PROJECT_DEVELOPER.getPermissions()), "Maintainer", Color.TRANSPARENT, 30),
|
||||
PROJECT_ADMIN("Project_Admin", 34, Permission.IsProjectAdmin.add(Permission.EditApiKeys).add(PROJECT_MAINTAINER.getPermissions()), "Admin", Color.TRANSPARENT, 20),
|
||||
PROJECT_OWNER("Project_Owner", 35, Permission.IsProjectOwner.add(PROJECT_ADMIN.getPermissions()), "Owner", Color.TRANSPARENT, 10, false);
|
||||
PROJECT_EDITOR("Project_Editor", 31, Permission.EditPage.add(PROJECT_SUPPORT.permissions()), "Editor", Color.TRANSPARENT, 50),
|
||||
PROJECT_DEVELOPER("Project_Developer", 32, PROJECT_EDITOR.permissions(), "Developer", Color.TRANSPARENT, 40),
|
||||
PROJECT_MAINTAINER("Project_Maintainer", 33, Permission.CreateVersion.add(Permission.EditVersion).add(Permission.DeleteVersion).add(Permission.EditTags).add(PROJECT_DEVELOPER.permissions()), "Maintainer", Color.TRANSPARENT, 30),
|
||||
PROJECT_ADMIN("Project_Admin", 34, Permission.IsProjectAdmin.add(Permission.EditApiKeys).add(PROJECT_MAINTAINER.permissions()), "Admin", Color.TRANSPARENT, 20),
|
||||
PROJECT_OWNER("Project_Owner", 35, Permission.IsProjectOwner.add(PROJECT_ADMIN.permissions()), "Owner", Color.TRANSPARENT, 10, false);
|
||||
|
||||
private final String value;
|
||||
private final long roleId;
|
||||
@ -31,17 +28,6 @@ public enum ProjectRole implements Role<ProjectRoleTable> {
|
||||
private final boolean isAssignable;
|
||||
private final int rank;
|
||||
|
||||
private static final ProjectRole[] VALUES = values();
|
||||
private static final List<ProjectRole> ASSIGNABLE_ROLES = Arrays.stream(VALUES).filter(ProjectRole::isAssignable).toList();
|
||||
|
||||
public static ProjectRole[] getValues() {
|
||||
return VALUES;
|
||||
}
|
||||
|
||||
public static List<ProjectRole> getAssignableRoles() {
|
||||
return ASSIGNABLE_ROLES;
|
||||
}
|
||||
|
||||
ProjectRole(final String value, final long roleId, final Permission permissions, final String title, final Color color, final int rank) {
|
||||
this(value, roleId, permissions, title, color, rank, true);
|
||||
}
|
||||
@ -58,42 +44,42 @@ public enum ProjectRole implements Role<ProjectRoleTable> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getValue() {
|
||||
public @NotNull String value() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRoleId() {
|
||||
public long roleId() {
|
||||
return this.roleId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull RoleCategory getRoleCategory() {
|
||||
public @NotNull RoleCategory roleCategory() {
|
||||
return RoleCategory.PROJECT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Permission getPermissions() {
|
||||
public @NotNull Permission permissions() {
|
||||
return this.permissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getTitle() {
|
||||
public @NotNull String title() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Color getColor() {
|
||||
public @NotNull Color color() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignable() {
|
||||
public boolean assignable() {
|
||||
return this.isAssignable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getRank() {
|
||||
public Integer rank() {
|
||||
return this.rank;
|
||||
}
|
||||
|
||||
|
@ -10,39 +10,40 @@ import java.util.UUID;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
// TODO Remove this and the enums to keep everything data driven (see RoleData)
|
||||
public interface Role<T extends IRoleTable<? extends Role<T>>> {
|
||||
|
||||
Map<String, Role<?>> VALUE_ROLES = new HashMap<>();
|
||||
Map<Long, Role<?>> ID_ROLES = new HashMap<>();
|
||||
|
||||
static <C extends Enum<C> & Role<?>> void registerRole(final C roleEnum) {
|
||||
if (ID_ROLES.containsKey(roleEnum.getRoleId()) || VALUE_ROLES.containsKey(roleEnum.getValue())) {
|
||||
if (ID_ROLES.containsKey(roleEnum.roleId()) || VALUE_ROLES.containsKey(roleEnum.value())) {
|
||||
throw new IllegalArgumentException(roleEnum + " has a duplicate role ID or value");
|
||||
}
|
||||
ID_ROLES.put(roleEnum.getRoleId(), roleEnum);
|
||||
VALUE_ROLES.put(roleEnum.getValue(), roleEnum);
|
||||
ID_ROLES.put(roleEnum.roleId(), roleEnum);
|
||||
VALUE_ROLES.put(roleEnum.value(), roleEnum);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
String getValue();
|
||||
String value();
|
||||
|
||||
long getRoleId();
|
||||
long roleId();
|
||||
|
||||
@NotNull
|
||||
RoleCategory getRoleCategory();
|
||||
RoleCategory roleCategory();
|
||||
|
||||
@NotNull
|
||||
Permission getPermissions();
|
||||
Permission permissions();
|
||||
|
||||
@NotNull
|
||||
String getTitle();
|
||||
String title();
|
||||
|
||||
@NotNull
|
||||
Color getColor();
|
||||
Color color();
|
||||
|
||||
boolean isAssignable();
|
||||
boolean assignable();
|
||||
|
||||
@Nullable Integer getRank();
|
||||
@Nullable Integer rank();
|
||||
|
||||
@NotNull
|
||||
T create(@Nullable Long principalId, @Nullable UUID principalUuid, long userId, boolean isAccepted);
|
||||
|
@ -0,0 +1,15 @@
|
||||
package io.papermc.hangar.model.common.roles;
|
||||
|
||||
import io.papermc.hangar.db.customtypes.RoleCategory;
|
||||
import io.papermc.hangar.model.common.Permission;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public record RoleData(String value,
|
||||
long roleId,
|
||||
Permission permissions,
|
||||
RoleCategory roleCategory,
|
||||
String title,
|
||||
String color,
|
||||
@Nullable Integer rank,
|
||||
boolean assignable) {
|
||||
}
|
@ -48,13 +48,13 @@ public abstract class ExtendedRoleTable<R extends Role<? extends IRoleTable<R>>,
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public long getRoleId() {
|
||||
return this.role.getRoleId();
|
||||
return this.role.roleId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public String getRoleType() {
|
||||
return this.role.getValue();
|
||||
return this.role.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,12 +30,12 @@ public class GlobalRoleTable implements IRoleTable<GlobalRole> {
|
||||
|
||||
@Override
|
||||
public long getRoleId() {
|
||||
return this.role.getRoleId();
|
||||
return this.role.roleId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRoleType() {
|
||||
return this.role.getValue();
|
||||
return this.role.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,14 +72,14 @@ public class RoleTable extends Table implements Named {
|
||||
|
||||
public static RoleTable fromRole(final Role<?> role) {
|
||||
return new RoleTable(
|
||||
role.getRoleId(),
|
||||
role.getValue(),
|
||||
role.getRoleCategory(),
|
||||
role.getTitle(),
|
||||
role.getColor().getHex(),
|
||||
role.isAssignable(),
|
||||
role.getRank(),
|
||||
role.getPermissions()
|
||||
role.roleId(),
|
||||
role.value(),
|
||||
role.roleCategory(),
|
||||
role.title(),
|
||||
role.color().getHex(),
|
||||
role.assignable(),
|
||||
role.rank(),
|
||||
role.permissions()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -82,12 +82,12 @@ public abstract class MemberService<
|
||||
public void leave(final J joinable) {
|
||||
final RT role = this.roleService.getRole(joinable.getId(), this.getHangarUserId());
|
||||
if (this.invalidRolesToChange().contains(role.getRole())) {
|
||||
throw new HangarApiException(this.errorPrefix + "invalidRole", role.getRole().getTitle());
|
||||
throw new HangarApiException(this.errorPrefix + "invalidRole", role.getRole().title());
|
||||
}
|
||||
|
||||
this.membersDao.delete(role.getPrincipalId(), role.getUserId());
|
||||
this.roleService.deleteRole(role);
|
||||
this.logMemberRemoval(role, "Left:" + this.getHangarPrincipal().getName() + " (" + role.getRole().getTitle() + ")");
|
||||
this.logMemberRemoval(role, "Left:" + this.getHangarPrincipal().getName() + " (" + role.getRole().title() + ")");
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@ -96,7 +96,7 @@ public abstract class MemberService<
|
||||
this.membersDao.delete(roleTable.getPrincipalId(), roleTable.getUserId());
|
||||
this.roleService.deleteRole(roleTable);
|
||||
this.joinableNotificationService.removedFrom(roleTable, joinable, this.getHangarUserId());
|
||||
this.logMemberRemoval(joinable, "Removed: " + member.getName() + " (" + member.getRole().getTitle() + ")");
|
||||
this.logMemberRemoval(joinable, "Removed: " + member.getName() + " (" + member.getRole().title() + ")");
|
||||
}
|
||||
|
||||
private void logMemberRemoval(final Loggable<LC> loggable, final String logEntry) {
|
||||
@ -110,14 +110,14 @@ public abstract class MemberService<
|
||||
return;
|
||||
}
|
||||
|
||||
final String oldTitle = roleTable.getRole().getTitle();
|
||||
final String oldTitle = roleTable.getRole().title();
|
||||
roleTable.setRole(member.getRole());
|
||||
|
||||
this.roleService.updateRole(roleTable);
|
||||
this.joinableNotificationService.roleChanged(roleTable, joinable, this.getHangarUserId());
|
||||
this.logMemberUpdate(joinable,
|
||||
"Old Roles: " + member.getName() + " (" + oldTitle + ")",
|
||||
"New Roles: " + member.getName() + " (" + roleTable.getRole().getTitle() + ")");
|
||||
"New Roles: " + member.getName() + " (" + roleTable.getRole().title() + ")");
|
||||
}
|
||||
|
||||
private void logMemberUpdate(final Loggable<LC> loggable, final String oldState, final String newState) {
|
||||
@ -135,10 +135,10 @@ public abstract class MemberService<
|
||||
throw new HangarApiException(this.errorPrefix + "notMember", member.getName());
|
||||
}
|
||||
if (this.invalidRolesToChange().contains(member.getRole())) {
|
||||
throw new HangarApiException(this.errorPrefix + "invalidRole", member.getRole().getTitle());
|
||||
throw new HangarApiException(this.errorPrefix + "invalidRole", member.getRole().title());
|
||||
}
|
||||
if (this.invalidRolesToChange().contains(roleTable.getRole())) {
|
||||
throw new HangarApiException(this.errorPrefix + "invalidRole", roleTable.getRole().getTitle());
|
||||
throw new HangarApiException(this.errorPrefix + "invalidRole", roleTable.getRole().title());
|
||||
}
|
||||
return roleTable;
|
||||
}
|
||||
|
@ -59,7 +59,6 @@ public abstract class RoleService<RT extends IRoleTable<R>, R extends Role<RT>,
|
||||
}
|
||||
|
||||
public List<RT> getRoles(final long principalId, final R role) {
|
||||
return this.roleDao.getRoleTablesByPrincipal(principalId, role.getValue());
|
||||
return this.roleDao.getRoleTablesByPrincipal(principalId, role.value());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public abstract class InviteService<LC extends LogContext<?, LC>, R extends Role
|
||||
}
|
||||
|
||||
this.joinableNotificationService.invited(List.of(roleTable), joinable, this.getHangarUserId());
|
||||
this.logInvitesSent(joinable, "Invited: " + userTable.getName() + " (" + invitee.getRole().getTitle() + ")");
|
||||
this.logInvitesSent(joinable, "Invited: " + userTable.getName() + " (" + invitee.getRole().title() + ")");
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@ -115,7 +115,7 @@ public abstract class InviteService<LC extends LogContext<?, LC>, R extends Role
|
||||
this.memberService.addMember(roleTable);
|
||||
this.logInviteAccepted(roleTable, userTable);
|
||||
|
||||
if (roleTable.getRole().getRoleId() == this.getOwnerRole().getRoleId()) {
|
||||
if (roleTable.getRole().roleId() == this.getOwnerRole().roleId()) {
|
||||
this.setOwner(this.getJoinable(roleTable.getPrincipalId()), userTable, false);
|
||||
}
|
||||
}
|
||||
@ -150,7 +150,7 @@ public abstract class InviteService<LC extends LogContext<?, LC>, R extends Role
|
||||
abstract LogAction<LC> getInviteAcceptAction();
|
||||
|
||||
protected void logInviteAccepted(final RT roleTable, final UserTable userTable) {
|
||||
roleTable.logAction(this.actionLogger, this.getInviteAcceptAction(), userTable.getName() + " accepted an invite for " + roleTable.getRole().getTitle(), roleTable.getCreatedAt().format(DateTimeFormatter.RFC_1123_DATE_TIME));
|
||||
roleTable.logAction(this.actionLogger, this.getInviteAcceptAction(), userTable.getName() + " accepted an invite for " + roleTable.getRole().title(), roleTable.getCreatedAt().format(DateTimeFormatter.RFC_1123_DATE_TIME));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@ -162,7 +162,7 @@ public abstract class InviteService<LC extends LogContext<?, LC>, R extends Role
|
||||
abstract LogAction<LC> getInviteDeclineAction();
|
||||
|
||||
protected void logInviteDeclined(final RT roleTable, final UserTable userTable) {
|
||||
roleTable.logAction(this.actionLogger, this.getInviteDeclineAction(), userTable.getName() + " declined an invite for " + roleTable.getRole().getTitle(), roleTable.getCreatedAt().format(DateTimeFormatter.RFC_1123_DATE_TIME));
|
||||
roleTable.logAction(this.actionLogger, this.getInviteDeclineAction(), userTable.getName() + " declined an invite for " + roleTable.getRole().title(), roleTable.getCreatedAt().format(DateTimeFormatter.RFC_1123_DATE_TIME));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public abstract class JoinableNotificationService<RT extends ExtendedRoleTable<?
|
||||
public void invited(final Collection<RT> inviteeRoleTables, final J joinable, final long inviterId) {
|
||||
final Collection<NotificationTable> notificationTables = new HashSet<>();
|
||||
for (final RT rt : inviteeRoleTables) {
|
||||
notificationTables.add(new NotificationTable(rt.getUserId(), "notifications", inviterId, new String[]{this.msgPrefix + "invite", rt.getRole().getTitle(), joinable.getName()}, NotificationType.INFO));
|
||||
notificationTables.add(new NotificationTable(rt.getUserId(), "notifications", inviterId, new String[]{this.msgPrefix + "invite", rt.getRole().title(), joinable.getName()}, NotificationType.INFO));
|
||||
}
|
||||
this.notificationsDAO.insert(notificationTables);
|
||||
}
|
||||
@ -43,12 +43,12 @@ public abstract class JoinableNotificationService<RT extends ExtendedRoleTable<?
|
||||
public void removedFrom(final RT removedFromRoleTable, final J joinable, final @Nullable Long byUserId) {
|
||||
final String msgKey = this.msgPrefix + (removedFromRoleTable.isAccepted() ? "removed" : "inviteRescinded");
|
||||
this.notificationsDAO.insert(new NotificationTable(removedFromRoleTable.getUserId(), null, byUserId,
|
||||
new String[]{msgKey, removedFromRoleTable.getRole().getTitle(), joinable.getName()}, NotificationType.WARNING));
|
||||
new String[]{msgKey, removedFromRoleTable.getRole().title(), joinable.getName()}, NotificationType.WARNING));
|
||||
}
|
||||
|
||||
public void roleChanged(final RT changedRoleTable, final J joinable, final @Nullable Long byUserId) {
|
||||
this.notificationsDAO.insert(new NotificationTable(changedRoleTable.getUserId(), null, byUserId,
|
||||
new String[]{this.msgPrefix + "roleChanged", changedRoleTable.getRole().getTitle(), joinable.getName()}, NotificationType.INFO));
|
||||
new String[]{this.msgPrefix + "roleChanged", changedRoleTable.getRole().title(), joinable.getName()}, NotificationType.INFO));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user