Skip to content

Commit

Permalink
fix(writeapi): client-side group join API call
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Oct 8, 2020
1 parent e1c40b2 commit 68ecf41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
9 changes: 6 additions & 3 deletions public/src/client/groups/details.js
@@ -1,6 +1,5 @@
'use strict';


define('forum/groups/details', [
'forum/groups/memberlist',
'iconSelect',
Expand All @@ -9,7 +8,8 @@ define('forum/groups/details', [
'pictureCropper',
'translator',
'vendor/colorpicker/colorpicker',
], function (memberList, iconSelect, components, coverPhoto, pictureCropper, translator) {
'api',
], function (memberList, iconSelect, components, coverPhoto, pictureCropper, translator, api) {
var Details = {};
var groupName;

Expand Down Expand Up @@ -106,7 +106,10 @@ define('forum/groups/details', [
break;

case 'join': // intentional fall-throughs!
case 'leave':
api.put('/groups/' + ajaxify.data.group.slug + '/membership/' + (uid || app.user.uid), undefined, () => ajaxify.refresh(), err => app.alertError(err.status.message));
break;

case 'leave': // intentional fall-throughs!
case 'accept':
case 'reject':
case 'issueInvite':
Expand Down
11 changes: 4 additions & 7 deletions src/controllers/write/groups.js
Expand Up @@ -54,19 +54,16 @@ Groups.join = async (req, res) => {
});
const [isCallerOwner, userExists] = await Promise.all([
groups.ownership.isOwner(req.user.uid, group.name),
user.exists(req.user.uid),
user.exists(req.params.uid),
]);

if (group.isMember) {
if (!userExists) {
throw new Error('[[error:invalid-uid]]');
} else if (group.isMember) {
// No change
return helpers.formatApiResponse(200, res);
} else if (!userExists) {
throw new Error('[[error:invalid-uid]]');
}

// console.log(res.locals.privileges);
// return res.sendStatus(200);

if (!res.locals.privileges.isAdmin) {
// Admin and privilege groups unjoinable client-side
if (group.name === 'administrators' || groups.isPrivilegeGroup(group.name)) {
Expand Down

0 comments on commit 68ecf41

Please sign in to comment.