inherit
267109
0
Mar 21, 2024 11:06:27 GMT -8
zweibieren
26
November 2022
zweibieren
|
Post by zweibieren on Nov 17, 2023 8:48:35 GMT -8
Suppose I know the name of a group (let's say it's "GroupA"). How can my plugin's javascript code get the corresponding group id.
I need the group id to check pb.data("user").groupids to see if the current user is in "GroupA".
Thanks, Fred Hansen
|
|
inherit
217348
0
Jul 27, 2022 7:26:44 GMT -8
Lynx
5,846
January 2015
msg
|
Post by Lynx on Nov 17, 2023 18:37:12 GMT -8
Suppose I know the name of a group (let's say it's "GroupA"). How can my plugin's javascript code get the corresponding group id. I need the group id to check pb.data("user").groupids to see if the current user is in "GroupA". Thanks, Fred Hansen
If you already know the name of the group, you can get its ID from the address bar. If you're on as root admin, go to your Profile and click the Groups tab to see all of the groups. If you click on the one that has the name that you want, you'll get something like this in your address bar: That 5 in group=5 is the ID number for that group. With that, you can get the ID's of the current user with pb.data('user').group_ids and compare it to what you're looking for. This returns an array of all the Group ID numbers the current user is in. NOTE: I deliberately did not give you any code snippet, as it seems like you're trying to learn yourself. If you run into problems, though, I can try to guide you a bit more.
|
|
inherit
267109
0
Mar 21, 2024 11:06:27 GMT -8
zweibieren
26
November 2022
zweibieren
|
Post by zweibieren on Nov 17, 2023 20:35:02 GMT -8
I like to believe code can do anything a human can. But nothing about groups is sent to the client side.
Of course I can hard code the group id; brittle that.
Or maybe I can compute some data in the template and have it sent to the client side.
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,017
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Nov 17, 2023 22:24:39 GMT -8
pb.data("user") has the information you require in the group_ids (array of numeric group IDs) and groups (object with group_id/group_name pairs) The ID is the lookup key so if you have the group name instead of the group ID then you'll need to do something like Object.values(pb.data('user').groups).includes('Internal Feedback Group') to see if the user belongs to a group with that name I like to believe code can do anything a human can. But nothing about groups is sent to the client side. Of course I can hard code the group id; brittle that. Or maybe I can compute some data in the template and have it sent to the client side. Plugins do have a search option for Groups: View Attachment
|
|