mirror of
https://github.com/HangarMC/Hangar.git
synced 2025-02-17 15:01:42 +08:00
finished HeaderData
This commit is contained in:
parent
41be95737e
commit
10929c97e6
@ -35,4 +35,17 @@ public interface NotificationsDao {
|
|||||||
"WHERE n.user_id = :userId AND <ifread> " +
|
"WHERE n.user_id = :userId AND <ifread> " +
|
||||||
"ORDER BY n.created_at")
|
"ORDER BY n.created_at")
|
||||||
LinkedHashMap<NotificationsTable, UsersTable> getUserNotifications(long userId, @Define("ifread") String read);
|
LinkedHashMap<NotificationsTable, UsersTable> getUserNotifications(long userId, @Define("ifread") String read);
|
||||||
|
|
||||||
|
// For HeaderData
|
||||||
|
@SqlQuery("SELECT exists(SELECT 1 FROM notifications n WHERE n.user_id = :userId AND n.read IS FALSE)")
|
||||||
|
boolean hasUnreadNotifications(long userId);
|
||||||
|
|
||||||
|
@SqlQuery("SELECT exists(SELECT 1 FROM project_flags WHERE is_resolved IS FALSE)")
|
||||||
|
boolean hasUnresolvedFlags();
|
||||||
|
|
||||||
|
@SqlQuery("SELECT exists(SELECT 1 FROM projects p WHERE p.owner_id = :userId AND p.visibility = 3)")
|
||||||
|
boolean hasProjectApprovals(long userId);
|
||||||
|
|
||||||
|
@SqlQuery("SELECT exists(SELECT 1 FROM project_versions pv WHERE pv.review_state = 0)")
|
||||||
|
boolean hasReviewQueue();
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package io.papermc.hangar.service;
|
|||||||
import io.papermc.hangar.config.CacheConfig;
|
import io.papermc.hangar.config.CacheConfig;
|
||||||
import io.papermc.hangar.config.hangar.HangarConfig;
|
import io.papermc.hangar.config.hangar.HangarConfig;
|
||||||
import io.papermc.hangar.db.dao.HangarDao;
|
import io.papermc.hangar.db.dao.HangarDao;
|
||||||
|
import io.papermc.hangar.db.dao.NotificationsDao;
|
||||||
import io.papermc.hangar.db.dao.OrganizationDao;
|
import io.papermc.hangar.db.dao.OrganizationDao;
|
||||||
import io.papermc.hangar.db.dao.ProjectDao;
|
import io.papermc.hangar.db.dao.ProjectDao;
|
||||||
import io.papermc.hangar.db.dao.UserDao;
|
import io.papermc.hangar.db.dao.UserDao;
|
||||||
@ -49,18 +50,20 @@ public class UserService extends HangarService {
|
|||||||
private final HangarDao<OrganizationDao> orgDao;
|
private final HangarDao<OrganizationDao> orgDao;
|
||||||
private final HangarDao<ProjectDao> projectDao;
|
private final HangarDao<ProjectDao> projectDao;
|
||||||
private final HangarDao<OrganizationDao> organizationDao;
|
private final HangarDao<OrganizationDao> organizationDao;
|
||||||
|
private final HangarDao<NotificationsDao> notificationsDao;
|
||||||
private final RoleService roleService;
|
private final RoleService roleService;
|
||||||
private final PermissionService permissionService;
|
private final PermissionService permissionService;
|
||||||
private final OrgService orgService;
|
private final OrgService orgService;
|
||||||
private final HangarConfig config;
|
private final HangarConfig config;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public UserService(HangarDao<UserDao> userDao, HangarConfig config, HangarDao<OrganizationDao> orgDao, HangarDao<ProjectDao> projectDao, HangarDao<OrganizationDao> organizationDao, RoleService roleService, PermissionService permissionService, OrgService orgService) {
|
public UserService(HangarDao<UserDao> userDao, HangarConfig config, HangarDao<OrganizationDao> orgDao, HangarDao<ProjectDao> projectDao, HangarDao<OrganizationDao> organizationDao, HangarDao<NotificationsDao> notificationsDao, RoleService roleService, PermissionService permissionService, OrgService orgService) {
|
||||||
this.userDao = userDao;
|
this.userDao = userDao;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.orgDao = orgDao;
|
this.orgDao = orgDao;
|
||||||
this.projectDao = projectDao;
|
this.projectDao = projectDao;
|
||||||
this.organizationDao = organizationDao;
|
this.organizationDao = organizationDao;
|
||||||
|
this.notificationsDao = notificationsDao;
|
||||||
this.roleService = roleService;
|
this.roleService = roleService;
|
||||||
this.permissionService = permissionService;
|
this.permissionService = permissionService;
|
||||||
this.orgService = orgService;
|
this.orgService = orgService;
|
||||||
@ -82,15 +85,20 @@ public class UserService extends HangarService {
|
|||||||
return HeaderData.UNAUTHENTICATED;
|
return HeaderData.UNAUTHENTICATED;
|
||||||
}
|
}
|
||||||
UsersTable curUser = currentUser.get().get();
|
UsersTable curUser = currentUser.get().get();
|
||||||
// TODO fill headerData
|
Permission perms = permissionService.getGlobalPermissions(curUser.getId());
|
||||||
|
|
||||||
|
boolean hasUnreadNotifs = notificationsDao.get().hasUnreadNotifications(curUser.getId());
|
||||||
|
boolean hasUnresolvedFlags = perms.has(Permission.ModNotesAndFlags) && notificationsDao.get().hasUnresolvedFlags();
|
||||||
|
boolean hasProjectApprovals = perms.has(Permission.ModNotesAndFlags.add(Permission.SeeHidden)) && notificationsDao.get().hasProjectApprovals(curUser.getId());
|
||||||
|
boolean hasReviewQueue = perms.has(Permission.Reviewer) && notificationsDao.get().hasReviewQueue();
|
||||||
return new HeaderData(
|
return new HeaderData(
|
||||||
curUser,
|
curUser,
|
||||||
permissionService.getGlobalPermissions(curUser.getId()),
|
permissionService.getGlobalPermissions(curUser.getId()),
|
||||||
false,
|
hasUnreadNotifs || hasUnresolvedFlags || hasProjectApprovals || hasReviewQueue,
|
||||||
false,
|
hasUnreadNotifs,
|
||||||
false,
|
hasUnresolvedFlags,
|
||||||
false,
|
hasProjectApprovals,
|
||||||
false
|
hasReviewQueue
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user