mirror of
https://github.com/HangarMC/Hangar.git
synced 2025-04-24 16:40:37 +08:00
prompts
This commit is contained in:
parent
5680c9a859
commit
8e97d55516
src/main
java/io/papermc/hangar
controller
db/model
model
service
resources/templates
@ -8,6 +8,7 @@ import io.papermc.hangar.db.model.OrganizationsTable;
|
||||
import io.papermc.hangar.db.model.UsersTable;
|
||||
import io.papermc.hangar.model.InviteFilter;
|
||||
import io.papermc.hangar.model.NotificationFilter;
|
||||
import io.papermc.hangar.model.Prompt;
|
||||
import io.papermc.hangar.service.NotificationService;
|
||||
import io.papermc.hangar.service.OrgService;
|
||||
import io.papermc.hangar.service.SitemapService;
|
||||
@ -40,6 +41,8 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
import org.springframework.web.servlet.view.RedirectView;
|
||||
@ -178,8 +181,12 @@ public class UsersController extends HangarController {
|
||||
|
||||
@Secured("ROLE_USER")
|
||||
@RequestMapping("/prompts/read/{id}")
|
||||
public Object markPromptRead(@PathVariable Object id) {
|
||||
return null; // TODO implement markPromptRead request controller
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public void markPromptRead(@PathVariable("id") Prompt prompt) {
|
||||
if (prompt == null) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid prompt id");
|
||||
}
|
||||
userService.markPromptAsRead(prompt);
|
||||
}
|
||||
|
||||
@RequestMapping("/signup")
|
||||
|
@ -6,6 +6,7 @@ import org.jdbi.v3.core.annotation.Unmappable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class UsersTable implements Serializable {
|
||||
@ -17,7 +18,7 @@ public class UsersTable implements Serializable {
|
||||
private String email;
|
||||
private String tagline;
|
||||
private OffsetDateTime joinDate;
|
||||
private int[] readPrompts;
|
||||
private List<Integer> readPrompts;
|
||||
private boolean isLocked;
|
||||
private String language;
|
||||
|
||||
@ -26,7 +27,7 @@ public class UsersTable implements Serializable {
|
||||
|
||||
}
|
||||
|
||||
public UsersTable(long id, String fullName, String name, String email, String tagline, int[] readPrompts, boolean isLocked, String language) {
|
||||
public UsersTable(long id, String fullName, String name, String email, String tagline, List<Integer> readPrompts, boolean isLocked, String language) {
|
||||
this.id = id;
|
||||
this.fullName = fullName;
|
||||
this.name = name;
|
||||
@ -37,7 +38,7 @@ public class UsersTable implements Serializable {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public UsersTable(String fullName, String name, String email, String tagline, int[] readPrompts, boolean isLocked, String language) {
|
||||
public UsersTable(String fullName, String name, String email, String tagline, List<Integer> readPrompts, boolean isLocked, String language) {
|
||||
this.fullName = fullName;
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
@ -116,11 +117,11 @@ public class UsersTable implements Serializable {
|
||||
}
|
||||
|
||||
|
||||
public int[] getReadPrompts() {
|
||||
public List<Integer> getReadPrompts() {
|
||||
return readPrompts;
|
||||
}
|
||||
|
||||
public void setReadPrompts(int[] readPrompts) {
|
||||
public void setReadPrompts(List<Integer> readPrompts) {
|
||||
this.readPrompts = readPrompts;
|
||||
}
|
||||
|
||||
|
22
src/main/java/io/papermc/hangar/model/Prompt.java
Normal file
22
src/main/java/io/papermc/hangar/model/Prompt.java
Normal file
@ -0,0 +1,22 @@
|
||||
package io.papermc.hangar.model;
|
||||
|
||||
public enum Prompt {
|
||||
|
||||
CHANGE_AVATAR("prompt.changeAvatar.title", "prompt.changeAvatar.message");
|
||||
|
||||
final String titleId;
|
||||
final String messageId;
|
||||
|
||||
Prompt(String titleId, String messageId) {
|
||||
this.titleId = titleId;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public String getTitleId() {
|
||||
return titleId;
|
||||
}
|
||||
|
||||
public String getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
}
|
@ -193,7 +193,7 @@ public class AuthenticationService {
|
||||
userEntry.setFullName(hangarConfig.fakeUser.getName());
|
||||
userEntry.setName(hangarConfig.fakeUser.getUsername());
|
||||
userEntry.setId(hangarConfig.fakeUser.getId());
|
||||
userEntry.setReadPrompts(new int[0]);
|
||||
userEntry.setReadPrompts(List.of());
|
||||
|
||||
userEntry = userDao.get().insert(userEntry);
|
||||
|
||||
|
@ -7,6 +7,7 @@ import io.papermc.hangar.db.dao.UserDao;
|
||||
import io.papermc.hangar.db.model.OrganizationsTable;
|
||||
import io.papermc.hangar.db.model.UsersTable;
|
||||
import io.papermc.hangar.model.NotificationType;
|
||||
import io.papermc.hangar.model.Prompt;
|
||||
import io.papermc.hangar.model.Role;
|
||||
import io.papermc.hangar.model.viewhelpers.UserData;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@ -22,6 +23,7 @@ import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
@ -73,7 +75,7 @@ public class OrgFactory {
|
||||
}
|
||||
|
||||
// TODO this will happen via /api/sync_sso, but I have no idea how to get that whole system working with Docker
|
||||
userDao.get().insert(new UsersTable(authOrgUser.getId(), null, name, dummyEmail, null, new int[0], false, authOrgUser.getLang().toLanguageTag()));
|
||||
userDao.get().insert(new UsersTable(authOrgUser.getId(), null, name, dummyEmail, null, List.of(), false, authOrgUser.getLang().toLanguageTag()));
|
||||
OrganizationsTable org = new OrganizationsTable(name, ownerId, authOrgUser.getId());
|
||||
org = organizationDao.get().insert(org);
|
||||
long orgId = org.getId();
|
||||
|
@ -6,6 +6,7 @@ import io.papermc.hangar.db.dao.UserDao;
|
||||
import io.papermc.hangar.db.model.OrganizationsTable;
|
||||
import io.papermc.hangar.db.model.UserOrganizationRolesTable;
|
||||
import io.papermc.hangar.db.model.UsersTable;
|
||||
import io.papermc.hangar.model.Prompt;
|
||||
import io.papermc.hangar.model.SsoSyncData;
|
||||
import io.papermc.hangar.model.viewhelpers.FlagActivity;
|
||||
import io.papermc.hangar.model.viewhelpers.ReviewActivity;
|
||||
@ -188,7 +189,7 @@ public class UserService {
|
||||
authUser.getUsername(),
|
||||
authUser.getEmail(),
|
||||
null,
|
||||
new int[0],
|
||||
List.of(),
|
||||
false,
|
||||
authUser.getLang().toLanguageTag()
|
||||
);
|
||||
@ -206,7 +207,7 @@ public class UserService {
|
||||
syncData.getUsername(),
|
||||
syncData.getEmail(),
|
||||
null,
|
||||
new int[0],
|
||||
List.of(),
|
||||
false,
|
||||
null
|
||||
);
|
||||
@ -240,4 +241,14 @@ public class UserService {
|
||||
public List<FlagActivity> getFlagActivity(String username) {
|
||||
return userDao.get().getFlagActivity(username);
|
||||
}
|
||||
|
||||
public void markPromptAsRead(Prompt prompt) {
|
||||
UsersTable currentUser = getCurrentUser();
|
||||
if (currentUser != null) {
|
||||
if (!currentUser.getReadPrompts().contains(prompt.ordinal())) {
|
||||
currentUser.getReadPrompts().add(prompt.ordinal());
|
||||
}
|
||||
userDao.get().update(currentUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
<#import "*/utils/userAvatar.ftlh" as userAvatar />
|
||||
<#import "*/utils/form.ftlh" as form>
|
||||
<#import "*/utils/csrf.ftlh" as csrf>
|
||||
<#import "*/utils/prompt.ftlh" as promptView>
|
||||
|
||||
<#-- @ftlvariable name="u" type="io.papermc.hangar.model.viewhelpers.UserData" -->
|
||||
<#-- @ftlvariable name="Permission" type="io.papermc.hangar.model.Permission" -->
|
||||
@ -55,10 +56,11 @@
|
||||
<a href="${routes.getRouteUrl("org.updateAvatar", u.user.name)}"><i class="fas fa-edit"></i> <@spring.message "user.editAvatar" /></a>
|
||||
</div>
|
||||
|
||||
<#--TODO prompts -->
|
||||
<#--<#if !u.headerData.currentUser.readPrompts.contains(Prompt.ChangeAvatar)>
|
||||
<@prompt.prompt prompt=Prompt.ChangeAvatar id="popover-avatar" />
|
||||
</#if>-->
|
||||
<#assign Prompt=@helper["io.papermc.hangar.model.Prompt"] />
|
||||
<#-- @ftlvariable name="Prompt" type="io.papermc.hangar.model.Prompt" -->
|
||||
<#if !u.headerData.currentUser.readPrompts?seq_contains(Prompt.CHANGE_AVATAR)>
|
||||
<@promptView.prompt prompt=Prompt.CHANGE_AVATAR id="popover-avatar" />
|
||||
</#if>
|
||||
</#if>
|
||||
|
||||
<span class="user-title">
|
||||
|
@ -2,7 +2,8 @@
|
||||
<#import "*/utils/hangar.ftlh" as hangar />
|
||||
|
||||
<#macro prompt prompt id="" position="right">
|
||||
<div class="prompt popover ${id} ${position}" data-prompt-id="${prompt.value}">
|
||||
<#-- @ftlvariable name="prompt" type="io.papermc.hangar.model.Prompt" -->
|
||||
<div class="prompt popover ${id} ${position}" data-prompt-id="${prompt.ordinal()}">
|
||||
<div class="arrow"></div>
|
||||
<h3 class="popover-title"><@spring.message prompt.titleId /></h3>
|
||||
<div class="popover-content">
|
||||
|
Loading…
x
Reference in New Issue
Block a user