Last group owner able to rescind ownership leaving group ownerless, but code was intended to disallow such action
-
I am working on an instance of nodebb where Groups are as major part as Categories, i.e. users are allowed to create groups, and have categories dedicated to groups, to moderate their own group/category as owners, etc.
I am finding that Groups part of nodebb hasn't gotten much attention since it is not the major aspect of a the usual use case.
However, here is a bug I found: It appears the program does not intend for any group to be ownerless (as per the code throwing error).
In src/groups/ownership
Method Groups.ownership.rescind
It appears the intention was for the function to make sure this wasn't the last owner who is being rescinded ownership, and throw an error.const numOwners = await db.setCount(`group:${groupName}:owners`); const isOwner = await db.isSortedSetMember(`group:${groupName}:owners`); if (numOwners <= 1 && isOwner) { throw new Error('[[error:group-needs-owner]]'); }
However, isOwner is returning false even when the uid is the owner, and hence they're being removed as owner, and group is able to become ownerless. Nothing wrong with ownerless groups, but since the intention in the code appears to be contrary to the output I felt it appropriate to be in the bug reports category here.
I've replaced the above check, with this function instead, and now I see the error thrown.
const isOwner = await db.isSetMember(`group:${groupName}:owners`, toUid);
Not a major issue, but since I am working on something where groups play a major role (group based site) I found this and wanted to bring this out here.
nodebb v3.7.1
-
@baris said in Last group owner able to rescind ownership leaving group ownerless, but code was intended to disallow such action:
@solmak nice catch, I've fixed it here will be available in 3.7.2.
Thank you for spending time on this, that was fast!
-
Thank you for spending time on this, that was fast!
he is quite speedy @baris is known to create a new plugin in 3 minutes of it being discussed in the forum... lol