poel Posted December 20, 2018 Share Posted December 20, 2018 Hi, I need to do something like this https://belvg.com/blog/how-to-add-new-employees-and-set-up-permissions-in-prestashop-1-7.html But I need to do it programmatically, how can I do it? Link to comment Share on other sites More sharing options...
JBW Posted December 20, 2018 Share Posted December 20, 2018 Check the class Employee.php in folder /classes - this should offer all methods needed to manage Employees. Link to comment Share on other sites More sharing options...
poel Posted December 21, 2018 Author Share Posted December 21, 2018 On 12/20/2018 at 11:38 AM, JBW said: Check the class Employee.php in folder /classes - this should offer all methods needed to manage Employees. mmmm, I can see only the method for checking if a user can access a tab: public function can($action, $tab) { $access = Profile::getProfileAccess($this->id_profile, Tab::getIdFromClassName($tab)); return ($access[$action] == '1'); } I think it refers to ps_access table where I see a row for each menù permission looking at the DB I've found the ps_module_access that has permissions for users on modules. Now I'm looking for a function to set properly the access for a user to my module, during the installation script. Any ideas? Link to comment Share on other sites More sharing options...
JBW Posted December 21, 2018 Share Posted December 21, 2018 If you inspect Employee class you will find that a profile_id which is a value from class Profile. Looking further you will also find class Access to define the access right on module level. Link to comment Share on other sites More sharing options...
poel Posted January 3, 2019 Author Share Posted January 3, 2019 On 12/21/2018 at 9:00 PM, JBW said: If you inspect Employee class you will find that a profile_id which is a value from class Profile. Looking further you will also find class Access to define the access right on module level. I don't understand how to set permission for a certain user for using my module during the installation process of the module Link to comment Share on other sites More sharing options...
JBW Posted January 4, 2019 Share Posted January 4, 2019 Are you struggeling with the development part or with the permission concept overall? Whats the specific issue, how far did you get so far, what did you try? In general a user has a profile assigned. This profil has several permissions assigned including authorizations for actions on modules. By default only SuperAdmin profile has module authorizations. Link to comment Share on other sites More sharing options...
poel Posted January 4, 2019 Author Share Posted January 4, 2019 10 hours ago, JBW said: Are you struggeling with the development part or with the permission concept overall? Whats the specific issue, how far did you get so far, what did you try? In general a user has a profile assigned. This profil has several permissions assigned including authorizations for actions on modules. By default only SuperAdmin profile has module authorizations. ok, I was confusing. I'm a Magento developer and I've been assigned a task for a Prestashop project that I have not seen yet, but I'm trying to inform myself. Now I'll explain what I should do: I have a module that communicates with an external web service. I saw that the permissions on resources on PrestaShop, for web service, are assigned through an API key (I was confused because on Magento the permissions for web services are assigned by users). Now I have to give read permissions on this apikey on everything and in writing only on the orders is it clearer now? Link to comment Share on other sites More sharing options...
JBW Posted January 5, 2019 Share Posted January 5, 2019 Yes, it's clearer, but I think there is no permission on user level in Presta for API usage (I personally have no experience on this). Good luck with your dev, let us know about your results. Link to comment Share on other sites More sharing options...
poel Posted January 11, 2019 Author Share Posted January 11, 2019 (edited) ok, I was wrong I just needed to give permission to the webservice (advanced parameters -> webservice). I was able to do it using the WebserviceKey class that has the method setPermissionForAccount, and passing it a parameter containing the permissions extracted from a json file. Here is my install function: public function install() { $keyId = $this->getKeyId(); $wsKey = new WebserviceKey($keyId ? $keyId : null); $wsKey->active = true; $wsKey->description = self::KEY_DESCRIPTION_MARKER; do { $wsKey->key = $this->generateKey(self::KEY_LENGTH); } while (WebserviceKey::keyExists($wsKey->key)); $wsKey->add(); $permissions_file = "../modules/".$this->name."/data/permissions.json"; $jsonPermissions = file_get_contents($permissions_file); //TODO controlli sul file $permissions_to_set = json_decode($jsonPermissions,true); $wsKey->setPermissionForAccount($wsKey->id,$permissions_to_set); $configuration = new stdClass(); $configuration->soap_key = $wsKey->key; Configuration::updateValue('XXX_CONFIGURATION', json_encode($configuration)); return parent::install() && $this->registerHook('actionAdminControllerSetMedia') && $this->registerHook('displayBackOfficeHeader'); } in the permissions.json we have: { "messages": { "GET": "on" }, "order_carriers": { "GET": "on", "PUT": "on", "POST": "on" } } So the installation works fine, I'm trying to update my module via zip upload, in this case Prestashop updates the module to the correct version, but does not set the permissions of the web service, perhaps because the install method is not executed during an upgrade? Edited January 11, 2019 by poel (see edit history) Link to comment Share on other sites More sharing options...
JBW Posted January 15, 2019 Share Posted January 15, 2019 When doing an upgrade PrestaShop executes the upgrade method, not the install again Link to comment Share on other sites More sharing options...
kimokimo Posted January 15, 2020 Share Posted January 15, 2020 On 1/11/2019 at 12:37 PM, poel said: ok, I was wrong I just needed to give permission to the webservice (advanced parameters -> webservice). I was able to do it using the WebserviceKey class that has the method setPermissionForAccount, and passing it a parameter containing the permissions extracted from a json file. Here is my install function: public function install() { $keyId = $this->getKeyId(); $wsKey = new WebserviceKey($keyId ? $keyId : null); $wsKey->active = true; $wsKey->description = self::KEY_DESCRIPTION_MARKER; do { $wsKey->key = $this->generateKey(self::KEY_LENGTH); } while (WebserviceKey::keyExists($wsKey->key)); $wsKey->add(); $permissions_file = "../modules/".$this->name."/data/permissions.json"; $jsonPermissions = file_get_contents($permissions_file); //TODO controlli sul file $permissions_to_set = json_decode($jsonPermissions,true); $wsKey->setPermissionForAccount($wsKey->id,$permissions_to_set); $configuration = new stdClass(); $configuration->soap_key = $wsKey->key; Configuration::updateValue('XXX_CONFIGURATION', json_encode($configuration)); return parent::install() && $this->registerHook('actionAdminControllerSetMedia') && $this->registerHook('displayBackOfficeHeader'); } in the permissions.json we have: { "messages": { "GET": "on" }, "order_carriers": { "GET": "on", "PUT": "on", "POST": "on" } } So the installation works fine, I'm trying to update my module via zip upload, in this case Prestashop updates the module to the correct version, but does not set the permissions of the web service, perhaps because the install method is not executed during an upgrade? is the code missing somthing i have tried it but it dosn't seems to be working ? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now