Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
831 florian 1
Permissions in Phorum 5
2
=======================
3
 
4
This document describes the way the permission system of Phorum works.
5
It is targeted at developers that need inside information on the
6
API calls that are related to permission handling.
7
 
8
Table of contents:
9
 
10
1. Checking user permissions
11
2. Modifying user permissions
12
3. Some final notes
13
 
14
 
15
1. Checking user permissions
16
-------------------------------------------------------------------------------
17
 
18
   First and foremost, your code should use the function called
19
   phorum_user_access_allowed() to check for a given user permission
20
   in the current forum. However, if you find yourself needing to check
21
   the permisssion directly, here is some information.
22
 
23
   Permissions are stored using a bitmask. To check for a certain permission,
24
   simply use the bitwise AND (&) operator to match the permission against the
25
   user's permissions.
26
 
27
   For example, if we want to check if a user has permission to read
28
   a particular forum, we would use the following if statement:
29
 
30
      if($PHORUM["user"]["permissions"] & PHORUM_USER_ALLOW_READ){
31
          // the user can read this forum
32
      } else {
33
          // the user can NOT read this forum
34
      }
35
 
36
 
37
2. Modifying user permissions
38
-------------------------------------------------------------------------------
39
 
40
   If you need to modify the permissions, use the bitwise OR (|) to add
41
   a permission or the bitwise XOR (^) to remove a permission. After you
42
   make the change, save the user. Here is some example code:
43
 
44
      // add new topic permissions
45
      $PHORUM["user"]["permissions"] =
46
          $PHORUM["user"]["permissions"] | PHORUM_USER_ALLOW_NEW_TOPIC;
47
      phorum_user_save($PHORUM["user"]);
48
 
49
      // remove new topic permissions
50
      $PHORUM["user"]["permissions"] =
51
          $PHORUM["user"]["permissions"] ^ PHORUM_USER_ALLOW_NEW_TOPIC;
52
      phorum_user_save($PHORUM["user"]);
53
 
54
 
55
3. Some final notes
56
-------------------------------------------------------------------------------
57
 
58
   That should be all you need to know about the Phorum permission system.
59
   Here is some stuff that helped explain this to the other developers:
60
 
61
   > select (256 | 16);
62
   > That OR's the two numbers together.
63
   > you get 272
64
   > then:
65
   > select 16 & 272;
66
   > That returns 16.
67
   > So, in our data, the 272 represents what is in the database.
68
   > The 16 would be one of the permission constancts
69
   > Our constants would look like this:
70
   >     define("PHORUM_USER_ALLOW_READ", 1);
71
   >     define("PHORUM_USER_ALLOW_REPLY", 2);
72
   >     define("PHORUM_USER_ALLOW_EDIT", 4);
73
   >     define("PHORUM_USER_ALLOW_NEW_TOPIC", 8);
74
   >     define("PHORUM_USER_ALLOW_UPLOAD", 16);
75
   >     define("PHORUM_USER_ALLOW_ATTACH", 32);
76
   >     define("PHORUM_USER_ALLOW_MODERATE_MESSAGES", 64);
77
   >     define("PHORUM_USER_ALLOW_MODERATE_USERS", 128);
78
   >     define("PHORUM_USER_ALLOW_FORUM_PROPERTIES", 256);
79
   > To give someone read and reply, we would set their perm to 1 | 2
80
   > Then, to check it, we would $user_perm_value & $perm == $perm
81
   > or in sql
82
   > where permission & $perm = $perm
83
 
84
   Another example to show that the = $perm can be left out:
85
 
86
   > select 1 | 2
87
   > read, reply
88
   > = 3
89
   > select 3 & 16
90
   > =0
91