Skip to content

Commit

Permalink
updated API controller to allow spaces parameter for /users/{id}/mode…
Browse files Browse the repository at this point in the history
…rator requests
  • Loading branch information
albogdano committed Oct 10, 2024
1 parent 6af35ae commit 46f5210
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/erudika/scoold/api/ApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,9 @@ public List<? extends Post> getUserFavorites(@PathVariable String id, HttpServle
}

@PutMapping("/users/{id}/moderator")
public void makeUserMod(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
profileController.makeMod(id, req, res);
public void makeUserMod(@PathVariable String id, @RequestParam(required = false, defaultValue = "") List<String> spaces,
HttpServletRequest req, HttpServletResponse res) {
profileController.makeMod(id, spaces, req, res);
}

@PutMapping("/users/{id}/ban")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public String get(@PathVariable(required = false) String id, HttpServletRequest
}

@PostMapping("/{id}/make-mod")
public String makeMod(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
public String makeMod(@PathVariable String id, @RequestParam(required = false, defaultValue = "") List<String> spaces,
HttpServletRequest req, HttpServletResponse res) {
Profile authUser = utils.getAuthUser(req);
if (!isMyid(authUser, Profile.id(id))) {
Profile showUser = pc.read(Profile.id(id));
Expand All @@ -158,11 +159,12 @@ public String makeMod(@PathVariable String id, HttpServletRequest req, HttpServl
if (CONF.modsAccessAllSpaces()) {
showUser.setGroups(utils.isMod(showUser) ? USERS.toString() : MODS.toString());
} else {
String space = req.getParameter("space");
if (showUser.isModInSpace(space)) {
showUser.getModspaces().remove(space);
} else {
showUser.getModspaces().add(space);
for (String space : spaces) {
if (showUser.isModInSpace(space)) {
showUser.getModspaces().remove(space);
} else {
showUser.getModspaces().add(space);
}
}
}
showUser.update();
Expand Down
12 changes: 9 additions & 3 deletions src/main/resources/templates/api.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: "3.0.2"
info:
description: "This is the Scoold API. First, you need to generate an [API key](/admin) in order to access the API."
version: "1.5.0"
version: "1.6.0"
title: "Scoold API documentation"
externalDocs:
description: "README"
Expand Down Expand Up @@ -751,7 +751,13 @@ paths:
- name: id
in: path
required: true
description: The id of the post
description: The id of the user to promote/demote
schema:
type: string
- name: spaces
in: query
required: false
description: A comma-separated list of spaces in which the user will be promoted/demoted to moderator. Endpoint acts a toggle switch. This parameter is **only required if** `scoold.mods_access_all_spaces = false`.
schema:
type: string
responses:
Expand All @@ -769,7 +775,7 @@ paths:
- name: id
in: path
required: true
description: The id of the post
description: The id of the user to ban/unban
schema:
type: string
- name: banuntil
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/profile.vm
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
#if ($isAdmin && !$scooldUtils.config.modsAccessAllSpaces())
#if(!$scooldUtils.isAdmin($showUser))
<small>
<a href="$profilelink/$showUser.creatorid/make-mod?space=$!s" class="make-mod-btn">
<a href="$profilelink/$showUser.creatorid/make-mod?spaces=$!s" class="make-mod-btn">
#if ($showUser.isModInSpace($s))#set($hidemakemod = "hide")#else#set($unhidemakemod = "hide")#end
<span class="#if($showUser.isModInSpace($s))#else hide#end">Unmake mod</span>
<span class="#if($showUser.isModInSpace($s))hide#else#end">Make mod</span>
Expand Down

0 comments on commit 46f5210

Please sign in to comment.