You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2024-04-16 11:03:31

scarletTornado
Member
Registered: 2024-04-12
Posts: 19

[SOLVED]Plugin development: can't create custom list

I'm trying to develop a plugin that allows me to create lists of assets. I recently looked into the code of Appliance.php, took the code and database table structure from it and adapted it for my needs but I'm having no luck as I get no button to create a list in "front/assetlist.php" nor does "front/assetlist.form.php" show anything.

Last edited by scarletTornado (2024-04-29 15:14:22)

Offline

#2 2024-04-17 11:28:58

scarletTornado
Member
Registered: 2024-04-12
Posts: 19

Re: [SOLVED]Plugin development: can't create custom list

[solved]
Already solved it, couldn't manage lists because I didn't define the following methods for my main class:

    static function canCreate() {
        if (isset($_SESSION["glpi_plugin_assetlist_profile"])) {
           return ($_SESSION["glpi_plugin_assetlist_profile"]['assetlist'] == 'w');
        }
        return false;
    }

    static function canView() {
        if (isset($_SESSION["glpi_plugin_assetlist_profile"])) {
            return ($_SESSION["glpi_plugin_assetlist_profile"]['assetlist'] == 'w'
                   || $_SESSION["glpi_plugin_assetlist_profile"]['assetlist'] == 'r');
        }
        return false;
    }

    static function canDelete() {
        if (isset($_SESSION["glpi_plugin_assetlist_profile"])) {
            return ($_SESSION["glpi_plugin_assetlist_profile"]['assetlist'] == 'w');
        }
        return false;
    }

    public static function canUpdate() {
        if (isset($_SESSION["glpi_plugin_assetlist_profile"])) {
            return ($_SESSION["glpi_plugin_assetlist_profile"]['assetlist'] == 'w');
        }
        return false;
    }

    public static function canPurge() {
        if (isset($_SESSION["glpi_plugin_assetlist_profile"])) {
            return ($_SESSION["glpi_plugin_assetlist_profile"]['assetlist'] == 'w');
        }
        return false;
    }

Not sure if there are more profile options than 'w' and 'r' so I'm assuming 'r' stands only for being able to read the data and 'w' for being able to manage the objects in all possible ways (add, modify, delete, purge).

Last edited by scarletTornado (2024-04-17 11:43:21)

Offline

#3 2024-04-17 14:47:48

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,809
Website

Re: [SOLVED]Plugin development: can't create custom list

Is the "glpi_plugin_assetlist_profile" session data something you added yourself? It doesn't seem correct to me for plugin permissions.

If you would like a reference while creating your plugin, this is one of my plugins which has new permissions and adds new "pages":
https://github.com/cconard96/glpi-webresources-plugin

In the setup.php file, you can see that I register a "PluginWebresourcesProfile" class and add it as a tab on the Profile class.
PluginWebresourcesProfile (inc/profile.class.php) extends the Profile class from GLPI and lets me show a tab for the plugin-specific permissions.
All core GLPI and plugin permissions get saved in the same place in the DB, so there is no real special handling required by plugins.

In the PluginWebresourcesResource class (inc/resource.class.php), you can see I have a property "$rightname" set to "plugin_webresources_resource" which is the name of the right that I added. This specifies that for access to items of this type, GLPI should check the "plugin_webresources_resource" permission. By extending "CommonDBTM" directly or indirectly, the default can* methods should handle the permission checks automatically.

In GLPI, permissions are stored as bitflags. For example:
- READ = 1
- UPDATE = 2
- CREATE = 4
When the "plugin_webresources_resource" right has a value of 5 then it means I have permission to create and read the items but not update them. GLPI provides constants for the standard permission levels (see inc/define.php) for easy reference.


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#4 2024-04-18 10:35:51

scarletTornado
Member
Registered: 2024-04-12
Posts: 19

Re: [SOLVED]Plugin development: can't create custom list

Thanks for your answer cconard96, the thing is that I started my plugin from the github example plugin from GLPI Project but your solution is way better.

Offline

#5 2024-04-18 11:25:46

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,809
Website

Re: [SOLVED]Plugin development: can't create custom list

I think a review of the example plugin is long overdue. Typically when new hooks for plugins are added, a basic example is added to this plugin but old stuff tends to remain. As far as I can tell, GLPI used to handle permissions like this but it was over 10 years ago.


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

Board footer

Powered by FluxBB