Skip to content

Commit

Permalink
chore: cleanup unused stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniDigger committed Jan 12, 2025
1 parent 74a3e73 commit 0db7ade
Show file tree
Hide file tree
Showing 23 changed files with 7 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import io.papermc.hangar.components.auth.service.AuthService;
import io.papermc.hangar.components.auth.service.CredentialsService;
import io.papermc.hangar.components.auth.service.TokenService;
import io.papermc.hangar.components.auth.service.TurnstileService;
import io.papermc.hangar.components.auth.service.VerificationService;
import io.papermc.hangar.exceptions.HangarApiException;
import io.papermc.hangar.model.db.UserTable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
@ConfigurationProperties(prefix = "hangar")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ThreadLocalRandom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.info.GitProperties;
import org.springframework.cache.annotation.Cacheable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.papermc.hangar.HangarComponent;
import io.papermc.hangar.components.auth.model.dto.SignupForm;
import io.papermc.hangar.components.auth.service.AuthService;
import io.papermc.hangar.exceptions.HangarApiException;
import io.papermc.hangar.model.common.NamedPermission;
import io.papermc.hangar.model.common.roles.GlobalRole;
import io.papermc.hangar.model.db.UserTable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ResponseStatusException;

// @el(author: String, slug: String, projectId: long, project: io.papermc.hangar.model.db.projects.ProjectTable)
@RestController
Expand Down
13 changes: 2 additions & 11 deletions backend/src/main/java/io/papermc/hangar/db/dao/UsersDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,10 @@ public interface UsersDAO {
u.avatar_url,
exists(SELECT 1 FROM organizations o WHERE u.id = o.user_id) AS is_organization
FROM users u
WHERE lower(u.name) = lower(:name)
OR u.id = :id
WHERE u.id = :id
GROUP BY u.id
""")
<T extends User> T _getUser(String name, Long id, @MapTo Class<T> type);

default <T extends User> T getUser(final String name, final Class<T> type) {
return this._getUser(name, null, type);
}

default <T extends User> T getUser(final long id, final Class<T> type) {
return this._getUser(null, id, type);
}
<T extends User> T getUser(final Long id, @MapTo final Class<T> type);

@AllowUnusedBindings // query can be unused
@UseStringTemplateEngine
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package io.papermc.hangar.db.dao.internal.table.projects;

import io.papermc.hangar.model.db.projects.ProjectFlagNotificationTable;
import io.papermc.hangar.model.db.projects.ProjectFlagTable;
import java.util.Collection;
import java.util.List;
import org.jdbi.v3.spring.JdbiRepository;
import org.jdbi.v3.sqlobject.config.RegisterConstructorMapper;
import org.jdbi.v3.sqlobject.customizer.BindBean;
import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys;
import org.jdbi.v3.sqlobject.statement.SqlBatch;
import org.jdbi.v3.sqlobject.statement.SqlQuery;
import org.jdbi.v3.sqlobject.statement.SqlUpdate;

@JdbiRepository
Expand All @@ -22,7 +19,4 @@ public interface ProjectFlagNotificationsDAO {

@SqlBatch("INSERT INTO project_flag_notifications (flag_id, notification_id) VALUES (:flagId, :notificationId)")
void insert(@BindBean Collection<ProjectFlagNotificationTable> projectFlagNotificationTables);

@SqlQuery("SELECT * FROM project_flag_notifications WHERE flag_id = :flagId")
List<ProjectFlagTable> notificationsForFlag(long flagId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.jdbi.v3.sqlobject.customizer.BindBean;
import org.jdbi.v3.sqlobject.customizer.Timestamped;
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
import org.checkerframework.checker.nullness.qual.Nullable;

@JdbiRepository
public interface PinnedProjectVersionsDAO {
Expand All @@ -14,14 +13,6 @@ public interface PinnedProjectVersionsDAO {
@SqlUpdate("INSERT INTO pinned_project_versions (created_at, project_id, version_id) VALUES (:now, :projectId, :versionId) ON CONFLICT DO NOTHING")
void insert(@BindBean PinnedProjectVersionTable pinnedProjectVersionTable);

@SqlUpdate("DELETE FROM pinned_project_versions WHERE project_id = :projectId AND (id = :ppvId OR version_id = :versionId)")
void _delete(long projectId, @Nullable Long ppvId, @Nullable Long versionId);

default void deletePinnedProjectVersion(final long projectId, final long ppvId) {
this._delete(projectId, ppvId, null);
}

default void deleteVersion(final long projectId, final long versionId) {
this._delete(projectId, null, versionId);
}
@SqlUpdate("DELETE FROM pinned_project_versions WHERE project_id = :projectId AND version_id = :versionId")
void deleteVersion(long projectId, Long versionId);
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.papermc.hangar.model.internal.user;

import io.papermc.hangar.db.customtypes.JSONB;
import io.papermc.hangar.model.Identified;
import io.papermc.hangar.model.api.User;
import io.papermc.hangar.model.api.UserNameChange;
import io.papermc.hangar.model.common.Permission;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.papermc.hangar.model.internal.versions;

import io.papermc.hangar.config.jackson.RequiresPermission;
import io.papermc.hangar.model.Identified;
import io.papermc.hangar.model.api.project.ProjectChannel;
import io.papermc.hangar.model.api.project.version.Version;
import io.papermc.hangar.model.api.project.version.VersionStats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public PermissionService(final PermissionsDAO permissionsDAO) {
return this.getPermissions(userId, this.permissionsDAO::getGlobalPermission);
}

public @NotNull Permission getGlobalPermissions(final @Nullable String userName) {
return this.getPermissions(userName, this.permissionsDAO::getGlobalPermission);
}

// Project permissions
public Permission getProjectPermissions(final @Nullable Long userId, final long projectId) {
//TODO still leaks not listed projects (e.g. via pages api) as the perm is technically given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@
public class ProjectsApiService extends HangarComponent {

private final ProjectsApiDAO projectsApiDAO;
private final UsersApiService usersApiService;

@Autowired
public ProjectsApiService(final ProjectsApiDAO projectsApiDAO, final UsersApiService usersApiService) {
public ProjectsApiService(final ProjectsApiDAO projectsApiDAO) {
this.projectsApiDAO = projectsApiDAO;
this.usersApiService = usersApiService;
}

public Project getProject(final long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import io.papermc.hangar.model.internal.user.HangarUser;
import io.papermc.hangar.security.authentication.HangarPrincipal;
import io.papermc.hangar.service.PermissionService;
import io.papermc.hangar.components.images.service.AvatarService;
import io.papermc.hangar.service.internal.admin.FlagService;
import io.papermc.hangar.service.internal.organizations.OrganizationService;
import io.papermc.hangar.service.internal.projects.PinnedProjectService;
Expand Down Expand Up @@ -51,10 +50,9 @@ public class UsersApiService extends HangarComponent {
private final ReviewService reviewService;
private final ProjectAdminService projectAdminService;
private final FlagService flagService;
private final AvatarService avatarService;

@Autowired
public UsersApiService(final UsersDAO usersDAO, final UsersApiDAO usersApiDAO, final NotificationsDAO notificationsDAO, final PermissionService permissionService, final OrganizationService organizationService, final PinnedProjectService pinnedProjectService, final ReviewService reviewService, @Lazy final ProjectAdminService projectAdminService, final FlagService flagService, final AvatarService avatarService) {
public UsersApiService(final UsersDAO usersDAO, final UsersApiDAO usersApiDAO, final NotificationsDAO notificationsDAO, final PermissionService permissionService, final OrganizationService organizationService, final PinnedProjectService pinnedProjectService, final ReviewService reviewService, @Lazy final ProjectAdminService projectAdminService, final FlagService flagService) {
this.usersDAO = usersDAO;
this.usersApiDAO = usersApiDAO;
this.notificationsDAO = notificationsDAO;
Expand All @@ -64,7 +62,6 @@ public UsersApiService(final UsersDAO usersDAO, final UsersApiDAO usersApiDAO, f
this.reviewService = reviewService;
this.projectAdminService = projectAdminService;
this.flagService = flagService;
this.avatarService = avatarService;
}

public <T extends User> T getUser(final long id, final Class<T> type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
import io.papermc.hangar.db.dao.internal.table.OrganizationDAO;
import io.papermc.hangar.db.dao.internal.table.UserDAO;
import io.papermc.hangar.db.dao.internal.table.roles.OrganizationRolesDAO;
import io.papermc.hangar.exceptions.HangarApiException;
import io.papermc.hangar.model.common.Permission;
import io.papermc.hangar.model.db.OrganizationTable;
import io.papermc.hangar.model.db.UserTable;
import io.papermc.hangar.model.db.roles.OrganizationRoleTable;
import io.papermc.hangar.model.internal.HangarOrganization;
import io.papermc.hangar.model.internal.user.JoinableMember;
import io.papermc.hangar.service.PermissionService;
import io.papermc.hangar.components.images.service.AvatarService;
import io.papermc.hangar.service.internal.perms.members.OrganizationMemberService;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -31,17 +27,15 @@ public class OrganizationService extends HangarComponent {
private final UserDAO userDAO;
private final PermissionService permissionService;
private final OrganizationMemberService organizationMemberService;
private final AvatarService avatarService;

@Autowired
public OrganizationService(final HangarOrganizationsDAO hangarOrganizationsDAO, final OrganizationRolesDAO organizationRolesDAO, final OrganizationDAO organizationDAO, final UserDAO userDAO, final PermissionService permissionService, final OrganizationMemberService organizationMemberService, @Lazy final AvatarService avatarService) {
public OrganizationService(final HangarOrganizationsDAO hangarOrganizationsDAO, final OrganizationRolesDAO organizationRolesDAO, final OrganizationDAO organizationDAO, final UserDAO userDAO, final PermissionService permissionService, final OrganizationMemberService organizationMemberService) {
this.hangarOrganizationsDAO = hangarOrganizationsDAO;
this.organizationRolesDAO = organizationRolesDAO;
this.organizationDAO = organizationDAO;
this.userDAO = userDAO;
this.permissionService = permissionService;
this.organizationMemberService = organizationMemberService;
this.avatarService = avatarService;
}

public OrganizationTable getOrganizationTable(final long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,4 @@ public GlobalRoleService(final GlobalRolesDAO roleDao) {
public List<GlobalRole> getGlobalRoles(final long userId) {
return this.roleDao.getGlobalRoleTables(userId).stream().map(GlobalRoleTable::getRole).collect(Collectors.toList());
}

public void removeAllGlobalRoles(final long userId) {
this.roleDao.deleteAll(userId);
}
}
Loading

0 comments on commit 0db7ade

Please sign in to comment.