Fix WSGI custom addons path
[odoo/odoo.git] / doc / 04_security.rst
1 .. _security:
2
3 ==================================
4 Security in OpenERP: users, groups
5 ==================================
6
7 Users and user roles are critical points concerning internal security in
8 OpenERP. OpenERP provides several security mechanisms concerning user roles,
9 all implemented in the OpenERP Server. They are implemented in the lowest
10 server level, which is the ORM engine. OpenERP distinguishes three different
11 concepts:
12
13  - user: a person identified by its login and password. Note that all employees
14    of a company are not necessarily OpenERP users; an user is somebody who
15    accesses the application.
16  - group: a group of users that has some access rights. A group gives its
17    access rights to the users that belong to the group. Ex: Sales Manager,
18    Accountant, etc.
19  - security rule: a rule that defines the access rights a given group grants
20    to its users. Security rules are attached to a given resource, for example
21    the Invoice model.
22
23 Security rules are attached to groups. Users are assigned to several groups.
24 This gives users the rights that are attached to their groups. Therefore 
25 controlling user roles is done by managing user groups and adding or modifying 
26 security rules attached to those groups.
27
28 Users
29 ======
30
31 Users represent physical persons using OpenERP. They are identified with
32 a login and a password,they use OpenERP, they can edit their own preferences, ...
33 By default, a user has no access right. The more we assign groups to the user,
34 the more he or she gets rights to perform some actions. A user may belong 
35 to several groups.
36
37 User groups
38 ===========
39
40 The groups determine the access rights to the different resources. A user
41 may belong to several groups. If he belongs to several groups, we always 
42 use the group with the highest rights for a selected resource. A group 
43 can inherit all the rights from another group
44
45 Figure 3 shows how group membership is displayed in the web client. The user
46 belongs to Sales / Manager, Accounting / Manager, Administration / Access Rights,
47 Administration / Configuration and Human Resources / Employee groups. Those 
48 groups define the user access rights.
49
50 Figure 3: Example of group membership for a given user
51
52 Rights
53 ======
54
55 Security rules are attached to groups. You can assign several security 
56 rules at the group level, each rule being of one of the following types :
57
58  - access rights are global rights on an object,
59  - record rules are records access filters,
60  - fields access right,
61  - workflow transition rules are operations rights.
62  
63 You can also define rules that are global, i.e. they are applied to all
64 users, indiscriminately of the groups they belong to. For example, the
65 multi-company rules are global; a user can only see invoices of the companies 
66 he or she belongs to.
67
68
69 Concerning configuration, it is difficult to have default generic configurations 
70 that suit all applications. Therefore, like SAP, OpenERP is by default 
71 pre-configured with best-practices.
72
73 Access rights
74 =============
75
76 Access rights are rules that define the access a user can have on a particular
77 object . Those global rights are defined per document type or model. Rights 
78 follow the CRUD model: create, read (search), update (write), delete. For 
79 example, you can define rules on invoice creation. By default, adding a 
80 right to an object gives the right to all records of that specific object.
81
82 Figure 4 shows some of the access rights of the Accounting / Accountant group.
83 The user has some read access rights on some objects.
84
85 Figure 4: Access rights for some objects.
86
87 Record rules
88 ++++++++++++
89
90 When accessing an object, records are filtered based on record rules. Record 
91 rules or access filters are therefore filters that limits records of an 
92 object a group can access. A record rule is a condition that each record 
93 must satisfy to be created, read, updated (written) or deleted. Records 
94 that do not meet the constraints are filtered.
95
96 For example, you can create a rule to limit a group in such a way that 
97 users of that group will see business opportunities in which he or she is 
98 flagged as the salesman. The rule can be salesman = connected_user. With 
99 that rule, only records respecting the rule will be displayed.
100
101
102 Field access rights
103 +++++++++++++++++++
104
105 .. versionadded:: 7.0
106
107 OpenERP now supports real access control at the field level, not just on the view side.
108 Previously it was already possible to set a ``groups`` attribute on a ``<field>`` element
109 (or in fact most view elements), but with cosmetics effects only: the element was made
110 invisible on the client side, while still perfectly available for read/write access at
111 the RPC level.
112
113 As of OpenERP 7.0 the existing behavior is preserved on the view level, but a new ``groups``
114 attribute is available on all model fields, introducing a model-level access control on
115 each field. The syntax is the same as for the view-level attribute::
116
117     _columns = {
118         'secret_key': fields.char('Secret Key', groups="base.group_erp_manager,base.group_system")
119      }
120
121 There is a major difference with the view-level ``groups`` attribute: restricting
122 the access at the model level really means that the field will be completely unavailable
123 for users who do not belong to the authorized groups:
124
125 * Restricted fields will be **completely removed** from all related views, not just
126   hidden. This is important to keep in mind because it means the field value will not be
127   available at all on the client side, and thus unavailable e.g. for ``on_change`` calls.
128 * Restricted fields will not be returned as part of a call to
129   :meth:`~openerp.osv.orm.fields_get` or :meth:`~openerp.osv.orm.fields_view_get`
130   This is in order to avoid them appearing in the list of fields available for
131   advanced search filters, for example. This does not prevent getting the list of
132   a model's fields by querying ``ir.model.fields`` directly, which is fine. 
133 * Any attempt to read or write directly the value of the restricted fields will result
134   in an ``AccessError`` exception.
135 * As a consequence of the previous item, restricted fields will not be available for
136   use within search filters (domains) or anything that would require read or write access.
137 * It is quite possible to set ``groups`` attributes for the same field both at the model
138   and view level, even with different values. Both will carry their effect, with the
139   model-level restriction taking precedence and removing the field completely in case of
140   restriction.
141
142 .. note:: The tests related to this feature are in ``openerp/tests/test_acl.py``.
143  
144 Workflow transition rules
145 +++++++++++++++++++++++++
146
147 Workflow transition rules are rules that restrict some operations to certain 
148 groups. Those rules handle rights to go from one step to another one in the 
149 workflow. For example, you can limit the right to validate an invoice, i.e. 
150 going from a draft action to a validated action.
151
152 Menu accesses
153 =============
154
155 In OpenERP, granting access to menus can be done using user groups. A menu 
156 that is not granted to any group is accessible to every user. It is possible 
157 in the administration panel to define the groups that can access a given menu.
158
159 However, one should note that using groups to hide or give access to menus 
160 is more within the filed of ergonomics or usability than within the field 
161 of security. It is a best practice putting rules on documents instead of 
162 putting groups on menu. For example, hiding invoices can be done by modifying 
163 the record rule on the invoice object, and it is more efficient and safer 
164 than hiding menus related to invoices.
165
166 Views customization
167 ===================
168
169 Customizing views based on groups is possible in OpenERP. You can put rules 
170 to display some fields based on group rules. However, as with menu accesses 
171 customization, this option should not be considered for security concerns. 
172 This way of customizing views belongs more to usability.
173
174 Administration
175 ==============
176
177 When installing your particular instance of OpenERP, a specific first user 
178 is installed by default. This first user is the Super User or administrator. 
179 The administrator is by default added access rights to every existing groups, 
180 as well as to every groups created during a new module installation. He also 
181 has access to a specific administration interface accessible via the administration 
182 menu, allowing the administration of OpenERP.
183
184 The administrator has rights to manage groups; he can add, create, modify 
185 or remove groups. He may also modify links between users and groups, such 
186 as adding or removing users. He also manages access rights. With those 
187 privileges, the administrator can therefore precisely define security 
188 accesses of every users of OpenERP.
189
190 There are user groups that are between normal groups and the super user. 
191 Those groups are Administration / Configuration and Administration / Access Rights. 
192 It gives to the users of those groups the necessary rights to configure access rights.
193