News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Add permission to mod - explain

Started by Jotade29, February 24, 2024, 10:03:54 PM

Previous topic - Next topic

Jotade29

Hi.

I have a question about how adding permissions to a mod works...

To explain my doubt, i am going to take the glossary mod as an example (https://custom.simplemachines.org/index.php?mod=1525;sa=parse)

According to the code in the mod, it has been added to managepermission.php...

'view_glossary' => array(false, 'glossary', 'view_basic_info'),
'admin_glossary' => array(false, 'glossary', 'administrate'),
'suggest_glossary' => array(false, 'glossary', 'view_basic_info'),

I understand that this is where the permission is created, but i don't understand how it works, for example with 'view glossary' what does the false, 'glossary' and 'view_basic_info' refer to? Also, nowhere do i see mention of the permission text, and yet it shows its name, in this case it would be $txt['permissionname_view_glossary'] = 'See glossary';

Thank you so much.
Quote from: Diego Andrés on August 12, 2023, 02:20:18 AMI'm afraid convincing Jotade to upgrade to SMF 2.1 will require bigger effort than your work sanitizing Unicode characters  :laugh:

Jotade29

Quote from: Diego Andrés on August 12, 2023, 02:20:18 AMI'm afraid convincing Jotade to upgrade to SMF 2.1 will require bigger effort than your work sanitizing Unicode characters  :laugh:

Doug Heffernan

Quote from: Jotade29 on February 24, 2024, 10:03:54 PMfor example with 'view glossary' what does the false, 'glossary' and 'view_basic_info' refer to?

False in this case means that said permission doesn't have multiple options. Whereas view_basic_info is the permission group/area where the aforementioned permission is added to by the mod.

Quote from: Jotade29 on February 24, 2024, 10:03:54 PMAlso, nowhere do i see mention of the permission text, and yet it shows its name, in this case it would be $txt['permissionname_view_glossary'] = 'See glossary';

This is handled/defined in the language file of the mod. Hope it helps.


Jotade29

Quote from: Doug Heffernan on February 26, 2024, 03:51:16 PM
Quote from: Jotade29 on February 24, 2024, 10:03:54 PMfor example with 'view glossary' what does the false, 'glossary' and 'view_basic_info' refer to?

False in this case means that said permission doesn't have multiple options. Whereas view_basic_info is the permission group/area where the aforementioned permission is added to by the mod.

Quote from: Jotade29 on February 24, 2024, 10:03:54 PMAlso, nowhere do i see mention of the permission text, and yet it shows its name, in this case it would be $txt['permissionname_view_glossary'] = 'See glossary';

This is handled/defined in the language file of the mod. Hope it helps.



Thnx for yur answer, Doug!!

I think i understand, thank you very much for the explanation. However, there is one thing ii can't understand. In the case of the example, what's the point of putting 'glossary'? That is: 'view_glossary' => array(false, 'glossary', 'view_basic_info'). With 'view_basic_info' I add it to the forum's basic permissions category, but is the 'glossary' after 'false' to mention the permission category?

I wud also like you to tell me about the txt issue of permissions. Do they have to mention the managepermission or do they simply have to follow the txt format in the forum language files $txt['permissionname_view_glossary'] ;$txt['permissionhelp_view_glossary']?

Thank you :)
Quote from: Diego Andrés on August 12, 2023, 02:20:18 AMI'm afraid convincing Jotade to upgrade to SMF 2.1 will require bigger effort than your work sanitizing Unicode characters  :laugh:

Jotade29

Quote from: Doug Heffernan on February 26, 2024, 03:51:16 PM
Quote from: Jotade29 on February 24, 2024, 10:03:54 PMfor example with 'view glossary' what does the false, 'glossary' and 'view_basic_info' refer to?

False in this case means that said permission doesn't have multiple options. Whereas view_basic_info is the permission group/area where the aforementioned permission is added to by the mod.

Quote from: Jotade29 on February 24, 2024, 10:03:54 PMAlso, nowhere do i see mention of the permission text, and yet it shows its name, in this case it would be $txt['permissionname_view_glossary'] = 'See glossary';

This is handled/defined in the language file of the mod. Hope it helps.



Another question, and sorry for the double post, but it won't let me modify it. To check the permission with isallowedto, do we need to put it only in the code of the source that we want to check, or do we also have to put it in the template?
Quote from: Diego Andrés on August 12, 2023, 02:20:18 AMI'm afraid convincing Jotade to upgrade to SMF 2.1 will require bigger effort than your work sanitizing Unicode characters  :laugh:

Arantor

Following the structure of the language string is enough - it's what the rest of SMF does.

As for allowedTo/isAllowedTo checks, they should only be in sources. (The difference is that allowedTo returns true/false so you can show/hide options etc., while isAllowedTo pushes the user to an error page if not allowed)
Holder of controversial views, all of which my own.


Steve

As @Jotade29 has been here 12 days after his last post in this topic without further input, I'm assuming this is resolved and marking it so.
My pet rock is not feeling well. I think it's stoned.

Advertisement: