Difference between revisions of "Permissions En"

From Dolibarr ERP CRM Wiki
Jump to navigation Jump to search
m
m (Import interlang links (links to translated versions of this page in other languages) from Multi Language Manager table.)
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
 +
<!-- BEGIN origin interlang links -->
 +
<!-- You can edit this section but do NOT remove these comments
 +
    Links below will be automatically replicated on translated pages by PolyglotBot -->
 +
[[es:Permisos]]
 +
[[fr:Permissions]]
 +
[[zh:用户权限]]
 +
<!-- END interlang links -->
 +
 +
[[Category:Core]]
 
{{TemplateDocDevEn}}
 
{{TemplateDocDevEn}}
  
 
Each permission has a unique ID.
 
Each permission has a unique ID.
 
All permissions managed by Dolibarr are saved into [[Table llx_rights_def]] and has its own ID.
 
All permissions managed by Dolibarr are saved into [[Table llx_rights_def]] and has its own ID.
This id is used to make link between a user and the permission (links are saved into [[Table llx_user_rights]] or to make link between groupe and the permission (links are saved into the [[Table llx_usergroup_rights]]).
+
This id is used to make link between a user and the permission (links are saved into [[Table llx_user_rights]] or to make link between group and the permission (links are saved into the [[Table llx_usergroup_rights]]).
 +
 
 +
 
 +
 
  
 
= Get permission and groups of a user =
 
= Get permission and groups of a user =
Line 9: Line 21:
 
It contains all informations of the current user.
 
It contains all informations of the current user.
 
Its permissions can be tested by a test
 
Its permissions can be tested by a test
if ($user->rights->module->codestringlevel1->codestringlevel1)
+
<source lang="php">
 +
if ($user->rights->module->codestringlevel1->codestringlevel1)
 +
</source>
  
 
To know list of groups in which a user is, you can use the following code (Dolibarr 2.5 or more):
 
To know list of groups in which a user is, you can use the following code (Dolibarr 2.5 or more):
$usergroup=new UserGroup($db);
+
<source lang="php">
$listofgroups=$usergroup->listGroupsForUser($fuser);
+
$usergroup=new UserGroup($db);
print $listofgroups[0]->nom;
+
$listofgroups=$usergroup->listGroupsForUser($fuser);
 +
print $listofgroups[0]->nom;
 +
</source>
 
$listofgroups is an array of all objects UserGroups (the groups) where the user $fuser belongs to
 
$listofgroups is an array of all objects UserGroups (the groups) where the user $fuser belongs to
 
and $fuser is the object User loaded with code
 
and $fuser is the object User loaded with code
$fuser=new User($db);
+
<source lang="php">
$fuser->fetch('login');
+
$fuser=new User($db);
 +
$fuser->fetch('login');
 +
</source>
  
 
= Array of available permissions =
 
= Array of available permissions =
 
Each module has its code string to use the $user->rights array to get its related permissions for user. List of code to use to read permissions are available of module developer documentation.
 
Each module has its code string to use the $user->rights array to get its related permissions for user. List of code to use to read permissions are available of module developer documentation.
  
Click [[:Category:List of Modules|here to get full list of modules]].
+
Click [[:Category:List of Modules|here to get full list of modules]] (and choose the developer version of module documentation to get list of possible permissions).

Latest revision as of 13:21, 23 July 2019

Each permission has a unique ID. All permissions managed by Dolibarr are saved into Table llx_rights_def and has its own ID. This id is used to make link between a user and the permission (links are saved into Table llx_user_rights or to make link between group and the permission (links are saved into the Table llx_usergroup_rights).



Get permission and groups of a user

In the source code of a Dolibarr page, the global object $user is automatically defined. It contains all informations of the current user. Its permissions can be tested by a test

if ($user->rights->module->codestringlevel1->codestringlevel1)

To know list of groups in which a user is, you can use the following code (Dolibarr 2.5 or more):

$usergroup=new UserGroup($db);
$listofgroups=$usergroup->listGroupsForUser($fuser);
print $listofgroups[0]->nom;

$listofgroups is an array of all objects UserGroups (the groups) where the user $fuser belongs to and $fuser is the object User loaded with code

$fuser=new User($db);
$fuser->fetch('login');

Array of available permissions

Each module has its code string to use the $user->rights array to get its related permissions for user. List of code to use to read permissions are available of module developer documentation.

Click here to get full list of modules (and choose the developer version of module documentation to get list of possible permissions).