misc stuff

This commit is contained in:
MiniDigger 2020-07-28 18:46:08 +02:00
parent ff230ece7a
commit 4d2b6896e7
9 changed files with 51 additions and 43 deletions

View File

@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Pattern;
import me.minidigger.hangar.db.dao.HangarDao;
@ -127,8 +129,10 @@ public class ProjectsController extends HangarController {
ModelAndView mav = new ModelAndView("projects/pages/view");
ProjectData projectData = projectService.getProjectData(author, slug);
mav.addObject("p", projectData);
mav.addObject("sp", new ScopedProjectData());
mav.addObject("rootPages");
ScopedProjectData sp = new ScopedProjectData();
sp.setPermissions(Permission.IsProjectOwner.add(Permission.EditPage));
mav.addObject("sp", sp);
mav.addObject("rootPages", new HashMap<ProjectPagesTable, List<ProjectPagesTable>>());
mav.addObject("page", projectService.getPage(projectData.getProject().getId(), "Home"));
mav.addObject("parentPage");
mav.addObject("pageCount", 0);

View File

@ -6,6 +6,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@ -20,6 +21,7 @@ import me.minidigger.hangar.db.dao.UserDao;
import me.minidigger.hangar.db.model.UsersTable;
import me.minidigger.hangar.service.AuthenticationService;
import me.minidigger.hangar.service.UserService;
import me.minidigger.hangar.util.RouteHelper;
@Controller
public class UsersController extends HangarController {
@ -29,14 +31,16 @@ public class UsersController extends HangarController {
private final AuthenticationService authenticationService;
private final ApplicationController applicationController;
private final UserService userService;
private final RouteHelper routeHelper;
@Autowired
public UsersController(HangarConfig hangarConfig, HangarDao<UserDao> userDao, AuthenticationService authenticationService, ApplicationController applicationController, UserService userService) {
public UsersController(HangarConfig hangarConfig, HangarDao<UserDao> userDao, AuthenticationService authenticationService, ApplicationController applicationController, UserService userService, RouteHelper routeHelper) {
this.hangarConfig = hangarConfig;
this.userDao = userDao;
this.authenticationService = authenticationService;
this.applicationController = applicationController;
this.userService = userService;
this.routeHelper = routeHelper;
}
@RequestMapping("/authors")
@ -115,10 +119,6 @@ public class UsersController extends HangarController {
@RequestMapping("/{user}")
public ModelAndView showProjects(@PathVariable String user) {
UsersTable dbUser = userDao.get().getByName(user);
return showProjects(dbUser);
}
private ModelAndView showProjects(UsersTable dbUser) {
if (dbUser == null) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
}
@ -138,18 +138,18 @@ public class UsersController extends HangarController {
return null; // TODO implement setLocked request controller
}
@RequestMapping(value = "/{user}/settings/tagline", method = RequestMethod.POST)
@PostMapping(value = "/{user}/settings/tagline")
public ModelAndView saveTagline(@PathVariable String user, @RequestParam("tagline") String tagline) {
if (tagline.length() > hangarConfig.getMaxTaglineLen()) {
ModelAndView mav = showProjects(user);
AlertUtil.showAlert(mav, AlertUtil.ERROR, "error.tagline.tooLong"); // TODO pass length param to key
return showProjects(user);
return new ModelAndView("redirect:" + routeHelper.getRouteUrl("users.showProjects", user));
}
// TODO user action log
UsersTable usersTable = userDao.get().getByName(user);
usersTable.setTagline(tagline);
usersTable = userDao.get().update(usersTable);
return showProjects(usersTable);
userDao.get().update(usersTable);
return new ModelAndView("redirect:" + routeHelper.getRouteUrl("users.showProjects", user));
}
@RequestMapping("/{user}/sitemap.xml")

View File

@ -1,6 +1,6 @@
package me.minidigger.hangar.db.dao;
import me.minidigger.hangar.service.project.ProjectFactory.InvalidProject;
import me.minidigger.hangar.service.project.ProjectFactory.InvalidProjectReason;
import org.jdbi.v3.sqlobject.config.RegisterBeanMapper;
import org.jdbi.v3.sqlobject.customizer.BindBean;
import org.jdbi.v3.sqlobject.customizer.Timestamped;
@ -23,7 +23,7 @@ public interface ProjectDao {
ProjectsTable insert(@BindBean ProjectsTable project);
@SqlQuery("SELECT CASE WHEN owner_id = :ownerId AND name = :name THEN 'OWNER_NAME' WHEN owner_id = :ownerId AND slug = :slug THEN 'OWNER_SLUG' WHEN plugin_id = :pluginId THEN 'PLUGIN_ID' END FROM projects")
InvalidProject checkValidProject(long ownerId, String pluginId, String name, String slug);
InvalidProjectReason checkValidProject(long ownerId, String pluginId, String name, String slug);
@SqlQuery("select * from projects where lower(owner_name) = lower(:author) AND lower(slug) = lower(:slug)")
ProjectsTable getBySlug(String author, String slug);

View File

@ -25,4 +25,3 @@ public interface UserGlobalRolesDao {
@RegisterBeanMapper(RolesTable.class)
List<RolesTable> getRolesByUserId(long id);
}
`

View File

@ -1,9 +1,12 @@
package me.minidigger.hangar.db.model;
import org.jdbi.v3.core.enums.EnumByOrdinal;
import java.time.OffsetDateTime;
import me.minidigger.hangar.db.customtypes.JSONB;
import me.minidigger.hangar.model.Category;
public class ProjectsTable {
@ -17,7 +20,7 @@ public class ProjectsTable {
private long ownerId;
private long topicId;
private long postId;
private long category;
private Category category;
private String description;
private long visibility;
private Object notes; // TODO jsonb
@ -34,7 +37,7 @@ public class ProjectsTable {
//
}
public ProjectsTable(String pluginId, String name, String slug, String ownerName, long ownerId, long category, String description, long visibility) {
public ProjectsTable(String pluginId, String name, String slug, String ownerName, long ownerId, Category category, String description, long visibility) {
this.pluginId = pluginId;
this.name = name;
this.slug = slug;
@ -135,11 +138,13 @@ public class ProjectsTable {
}
public long getCategory() {
@EnumByOrdinal
public Category getCategory() {
return category;
}
public void setCategory(long category) {
@EnumByOrdinal
public void setCategory(Category category) {
this.category = category;
}

View File

@ -7,7 +7,7 @@ import java.util.stream.Collectors;
public class Permission implements Comparable<Permission> {
public static final Permission None = new Permission(0);
public static final Permission All = new Permission(0XFFFFFFFFFFFFFFFFL);
public static final Permission All = new Permission(0XFFFFFFFFFFFFFFFL);
public static final Permission ViewPublicInfo = new Permission(1L << 0);
public static final Permission EditOwnUserSettings = new Permission(1L << 1);

View File

@ -1,6 +1,5 @@
package me.minidigger.hangar.service.project;
import me.minidigger.hangar.util.HangarException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -16,10 +15,9 @@ import me.minidigger.hangar.model.Role;
import me.minidigger.hangar.model.Visibility;
import me.minidigger.hangar.service.RoleService;
import me.minidigger.hangar.service.UserService;
import me.minidigger.hangar.util.HangarException;
import me.minidigger.hangar.util.StringUtils;
import java.util.List;
@Component
public class ProjectFactory {
@ -48,13 +46,13 @@ public class ProjectFactory {
public ProjectsTable createProject(UsersTable ownerUser, String name, String pluginId, Category category, String description) {
String slug = StringUtils.slugify(name);
ProjectsTable projectsTable = new ProjectsTable(pluginId, name, slug, ownerUser.getName(), ownerUser.getId(), category.getValue(), description, Visibility.NEW.getValue());
ProjectsTable projectsTable = new ProjectsTable(pluginId, name, slug, ownerUser.getName(), ownerUser.getId(), category, description, Visibility.NEW.getValue());
ProjectChannelsTable channelsTable = new ProjectChannelsTable(hangarConfig.getDefaultChannelName(), hangarConfig.getDefaultChannelColor().getValue(), -1);
InvalidProject invalidProjectReason = null;
InvalidProjectReason invalidProjectReason;
if (!hangarConfig.isValidProjectName(name)) {
invalidProjectReason = InvalidProject.INVALID_NAME;
invalidProjectReason = InvalidProjectReason.INVALID_NAME;
} else {
invalidProjectReason = projectDao.get().checkValidProject(ownerUser.getId(), pluginId, name, slug);
}
@ -73,14 +71,15 @@ public class ProjectFactory {
return projectsTable;
}
public enum InvalidProject {
public enum InvalidProjectReason {
PLUGIN_ID("error.project.invalidPluginId"),
OWNER_NAME("error.project.nameExists"),
OWNER_SLUG("error.project.slugExists"),
INVALID_NAME("error.project.invalidName");
final String key;
InvalidProject(String key) {
InvalidProjectReason(String key) {
this.key = key;
}
}

View File

@ -47,18 +47,18 @@ Documentation page within Project overview.
<div class="col-md-3">
<div class="stats minor">
<p><@spring.messageArgs "project.category.info", p.project.category.title /></p>
<p><@spring.messageArgs "project.publishDate", prettifyDate(p.project.createdAt) /></p>
<p><@spring.messageArgs code="project.category.info" args=[p.project.category.title] /></p>
<p><@spring.messageArgs code="project.publishDate" args=[p.project.createdAt.format("yyyy-MM-dd")] /></p>
<p><span id="view-count"></span> views</p>
<p><span id="star-count"></span> <a href="${routes.getRouteUrl("projects.showStargazers", p.project.ownerName, p.project.slug, "")}">stars</a></p>
<p><span id="watcher-count"></span> <a href="${routes.getRouteUrl("projects.showWatchers", p.project.ownerName, p.project.slug, "")}">watchers</a></p>
<p><span id="download-count"></span> total downloads</p>
<#list p.project.settings.licenseName as licenseName>
<#if p.project.licenseName??>
<p>
<@spring.message "project.license.link" />
<a target="_blank" rel="noopener" href="${p.project.settings.licenseUrl}">${licenseName}</a>
<@spring.message "project.license.link" />
<a target="_blank" rel="noopener" href="${p.project.licenseUrl}">${p.project.licenseName}</a>
</p>
</#list>
</#if>
</div>
<div class="panel panel-default">
@ -87,7 +87,7 @@ Documentation page within Project overview.
${"Home"}
</a>
</li>
@rootPages.filter(_._1.name != "Home").map { case (pg, children) =>
<#list rootPages as pg, children>
<li class="list-group-item">
<#if children.nonEmpty>
<#if !page.parentId.contains(pg.id.value)>
@ -106,16 +106,16 @@ Documentation page within Project overview.
</li>
<#if page.parentId.contains(pg.id)>
<div class="page-children" data-page-id="${pg.id}">
@children.map { child =>
<li class="list-group-item page-item-child">
<a href="${routes.getRouteUrl("pages.show", p.project.ownerName, p.project.slug, child.fullSlug(pg))}">
${child.name}
</a>
</li>
}
<#list children as child>
<li class="list-group-item page-item-child">
<a href="${routes.getRouteUrl("pages.show", p.project.ownerName, p.project.slug, child.fullSlug(pg))}">
${child.name}
</a>
</li>
</#list>
</div>
</#if>
}
</#list>
</ul>
</div>

View File

@ -21,8 +21,9 @@
-->
<!-- TODO: Pagination -->
<#assign Permission=@helper["me.minidigger.hangar.model.Permission"]>
<#macro memberList j perms editable=false removeCall="" settingsCall="" saveCall="">
<#if j.members.nonEmpty>
<#if j.members?size != 0>
<#if editable && perms.has(Permission.ManageSubjectMembers)>
<@roleSelect.roleSelect roleCategory=j.roleCategory id="select-role" classes="pull-right" hidden=true />