Révision ae34fb26
Ajouté par Assos Assos il y a presque 4 ans
drupal7/sites/all/modules/content_access/CHANGELOG.txt | ||
---|---|---|
1 |
Content Access 7.x-1.2-beta1, 2011-07-24 |
|
2 |
-------------------------------------- |
|
3 |
#1058526 by BenK, good_man: Rules 2.x integration. |
|
4 |
#572812 by NikLP, good_man: Add content type to permission title. |
|
5 |
#1135466 by Firewolf, videographics, good_man: Renaming a content type results |
|
6 |
in notices. |
|
7 |
#1144510 by good_man: Fix roles selection in test case. |
|
8 |
#1110860 by FiNeX, eosrei, good_man: Content access rules integration - |
|
9 |
missing function. |
|
10 |
#1159402 by FiNeX, dcmouyard, jjs, good_man: Wrong operations on rules |
|
11 |
integration. |
|
12 |
#1057400 by xaverx, dooug, jhayzhon, cnolle, Firewolf, Bitnetix, maciej.zgadzaj, |
|
13 |
karilu_ec, ChoY, BenK, good_man: Taxonomy access. |
|
14 |
#1097248 by ordermind, Itangalo, good_man: PDOException error 1062 when using |
|
15 |
rules on create node. |
|
16 |
#1209004 by Itangalo, good_man: "Reset content permissions" action doesn't go |
|
17 |
all the way. |
|
18 |
#1147526 by tmm360, good_man, Akaoni, danielb, Crusher, mithman, BenK, fago: |
|
19 |
Unpublished nodes displayed to anonymous users. |
|
20 |
#1115794 by rorydflynn, Waldknoblauch, aocoder, good_man, SNaKeMe, cgross, |
|
21 |
commanderflash, bryrock, enrikito, BenK, karilu_ec: Conflict with views |
|
22 |
module. |
drupal7/sites/all/modules/content_access/README.md | ||
---|---|---|
1 |
# CONTENTS OF THIS FILE |
|
2 |
|
|
3 |
* Introduction |
|
4 |
* Requirements |
|
5 |
* Recommended modules |
|
6 |
* Installation |
|
7 |
* Configuration |
|
8 |
* Maintainers |
|
9 |
* Notes |
|
10 |
|
|
11 |
|
|
12 |
# INTRODUCTION |
|
13 |
|
|
14 |
The **Content Access** module let you content manage access permission in a flexible and transparant way. |
|
15 |
|
|
16 |
It provides two new permissions: *view all* (allows anyone to view the |
|
17 |
content) and *view own* (allows only the content creator to see |
|
18 |
his/her own content). It also gives access to the existing core |
|
19 |
permissions *edit* and *delete* on the same settings page. |
|
20 |
|
|
21 |
It provides the following modalities: |
|
22 |
|
|
23 |
* Each *content type* can have its own default content access settings by role. |
|
24 |
* Optionally you can enable role based access control settings per *content node*. |
|
25 |
* Access control can be further customized per *user* if you have the **ACL** module enabled. |
|
26 |
|
|
27 |
For more information and reporting, please visit: |
|
28 |
|
|
29 |
* For a description of the module, visit the [project page][1]. |
|
30 |
* For on-screen documentation, visit the [documentation page][2], |
|
31 |
or enable [**Advanced Help**][6]. |
|
32 |
* To submit bug reports and feature suggestions, or to track changes |
|
33 |
visit the project's [issue tracker][3]. |
|
34 |
|
|
35 |
Features: |
|
36 |
|
|
37 |
* It comes with sensible defaults, so you need not configure anything |
|
38 |
and everything stays working. |
|
39 |
* It is as flexible as you want. It can work with per content type |
|
40 |
settings, per content node settings as well as with flexible Access |
|
41 |
Control Lists with the help of the **ACL** module |
|
42 |
([see Note 1](#ACL) at the end). |
|
43 |
* It reuses existing functionality instead of reimplementing it. So |
|
44 |
one can install the **ACL** module and set per user access control |
|
45 |
settings per content node. |
|
46 |
* It comes with a submodule named **Content Access Rules |
|
47 |
Interations**. It provides conditions and actions for the **Rules** |
|
48 |
module, which allows one to configure rule-based access permissions. |
|
49 |
* It optimizes the written content node grants, so that only the |
|
50 |
necessary grants are written. This is important for the |
|
51 |
performance of your site. |
|
52 |
* The module has a comes with automated testing to ensure everything |
|
53 |
stays working correctly. |
|
54 |
* It respects and makes use of Drupal's core permissions. This means |
|
55 |
that the "Access Control" tab provided by this module takes them |
|
56 |
into account and provides you a good overview of *all* applied |
|
57 |
access control settings on a single page (but see [Note 2](#adv) at |
|
58 |
the end). |
|
59 |
|
|
60 |
The module is designed to be simple to use, but can be configured to |
|
61 |
provide really fine-grained content access permissions. |
|
62 |
|
|
63 |
|
|
64 |
# REQUIREMENTS |
|
65 |
|
|
66 |
None. |
|
67 |
|
|
68 |
# RECOMMENDED MODULES |
|
69 |
|
|
70 |
* [**ACL**][4]: |
|
71 |
To use Access Control Lists for per user access control. |
|
72 |
* [**Advanced Help Hint**][7]: |
|
73 |
Links help text provided by `hook_help` to online help and |
|
74 |
**Advanced Help**. |
|
75 |
* [**Advanced Help**][6]: |
|
76 |
When this module is enabled, the project's `README.md` will be |
|
77 |
displayed when you visit `help/content_access/README.md`. |
|
78 |
* [**Markdown**][8]: |
|
79 |
When this module is enabled, display of the project's `README.md` |
|
80 |
will be rendered with the markdown filter. |
|
81 |
* [**Node Export**][N] |
|
82 |
To export content access rules. |
|
83 |
* [**Rules**][5]: |
|
84 |
To configure rule-based access permissions. |
|
85 |
|
|
86 |
|
|
87 |
# INSTALLATION |
|
88 |
|
|
89 |
The module is set up to require PHP ver. 5.6 or later. I do not want |
|
90 |
to keep supporting legacy PHP (at least not for free). If you need a |
|
91 |
version that runs on something more ancient, you have two options: |
|
92 |
|
|
93 |
1. Keep useing version 7.x-1.2-beta2. It does not restrict PHP |
|
94 |
version. It is very old tho', and is no longer recommended, nor is |
|
95 |
it supported. |
|
96 |
2. Ask me to create a separate branch of the project for a backport |
|
97 |
the current supported version to whatever version of PHP you need. |
|
98 |
Then get someone to support this branch. |
|
99 |
|
|
100 |
If you go for the backport option: If you're a developer, request to |
|
101 |
become a co-maintainer of this project and then create and support the |
|
102 |
backport yourself. If you're not, sponsor someone to do the backport |
|
103 |
and to support it. |
|
104 |
|
|
105 |
To install and enable, do the following: |
|
106 |
|
|
107 |
1. Install as you would normally install a contributed drupal |
|
108 |
module. See: [Installing modules][9] for further information. |
|
109 |
2. Enable the **Content Access** module on the *Modules* list |
|
110 |
page. |
|
111 |
3. If you want to use access control lists, download, install and |
|
112 |
configure the **ACL** module. |
|
113 |
|
|
114 |
|
|
115 |
# CONFIGURATION |
|
116 |
|
|
117 |
Note that users need at least the permission "View published content" |
|
118 |
to be able to access published content. Furthermore note that content |
|
119 |
which is not published is treated in a different way by Drupal: It can |
|
120 |
be viewed only by its author or users with "Bypass content access |
|
121 |
control" permission. You can *not* use this project to manage |
|
122 |
access to unpublished content. |
|
123 |
|
|
124 |
To inspect and change those permissions, navigate to *Administration » |
|
125 |
People » Permisions* and scroll down to the "Node" section. |
|
126 |
|
|
127 |
## Role based access control |
|
128 |
|
|
129 |
To set up access control for a content type, navigate to |
|
130 |
*Administration » Structure* and click on "edit" for the content type |
|
131 |
you want to set up. There will be a new tab named "Access Control" |
|
132 |
that let you control access. |
|
133 |
|
|
134 |
To set up role based access control, tick the boxes under "Role based |
|
135 |
access control settings". Note that only the "View" permissions are |
|
136 |
new permissions provided by this module. The "Edit" and "Delete" |
|
137 |
permissions are provided by the Drupal core, and can also be found if |
|
138 |
you navigate to *Administration » People » Permisions*. They are |
|
139 |
shown here to provide the full picture of what permission is set for |
|
140 |
the content type and role. It does not matter where you change these. |
|
141 |
|
|
142 |
## Per content node access control |
|
143 |
|
|
144 |
There is a a checkbox to enable per content node access control |
|
145 |
settings. If enabled, a new tab for the content access settings |
|
146 |
appears when viewing content. |
|
147 |
|
|
148 |
To configure permission to access these settings, navigate to |
|
149 |
*Administration » People » Permisions* and set the "Grant content |
|
150 |
access" permission for the relevant roles. |
|
151 |
|
|
152 |
## Advanced access control |
|
153 |
|
|
154 |
The "Advanced" settings are only relevant if you are running multiple |
|
155 |
node access modules on a site. |
|
156 |
|
|
157 |
A Drupal node access module can only grant access to content nodes, |
|
158 |
but not deny it. So if you are using multiple node access modules, |
|
159 |
access will be granted to a node as soon as one of the module grants |
|
160 |
access to it. |
|
161 |
|
|
162 |
However you can influence the behaviour by changing the priority of |
|
163 |
the content access module as drupal applies *only* the grants with the |
|
164 |
highest priority. So if content access has the highest priority |
|
165 |
*alone*, only its grants will be applied. |
|
166 |
|
|
167 |
By default node access modules should use priority 0 (zero). |
|
168 |
|
|
169 |
|
|
170 |
## Using access control lists |
|
171 |
|
|
172 |
To make use of access control lists you'll need to enable per content |
|
173 |
node access control settings for the content type. At the access control |
|
174 |
tab of such a content node you are able to grant view, edit or delete |
|
175 |
permission for specific users.. |
|
176 |
|
|
177 |
|
|
178 |
# MAINTAINERS |
|
179 |
|
|
180 |
**Content Access** was created by [fago][10] (Wolfgang Ziegler). |
|
181 |
It contains a lot of contributions from [good_man][11] (Khaled Al Hourani). |
|
182 |
The current maintainer is [gisle][12] (Gisle Hannemyr). |
|
183 |
|
|
184 |
Development and maintenance is sponsored by [Hannemyr Nye Medier AS][13]. |
|
185 |
|
|
186 |
Any help with development (patches, reviews, comments) are welcome. |
|
187 |
|
|
188 |
# NOTES |
|
189 |
|
|
190 |
**Note 1**<a id="ACL"></a>: ACL integration is not yet working right. |
|
191 |
|
|
192 |
**Note 2**<a id="adv"></a>: Note that this overview can't take other |
|
193 |
modules into account, which might also alter node access. If you have |
|
194 |
multiple modules installed that alter node access, read the paragraph |
|
195 |
about "Advanced access control". |
|
196 |
|
|
197 |
|
|
198 |
[1]: https://drupal.org/project/content_access |
|
199 |
[2]: https://drupal.org/node/1194974 |
|
200 |
[3]: https://drupal.org/project/issues/content_access |
|
201 |
[4]: https://www.drupal.org/project/acl |
|
202 |
[5]: https://www.drupal.org/project/rules |
|
203 |
[6]: https://www.drupal.org/project/advanced_help |
|
204 |
[7]: https://www.drupal.org/project/advanced_help_hint |
|
205 |
[8]: https://www.drupal.org/project/markdown |
|
206 |
[N]: https://www.drupal.org/project/node_export |
|
207 |
[9]: https://www.drupal.org/docs/7/extend/installing-modules |
|
208 |
[10]: https://www.drupal.org/u/fago |
|
209 |
[11]: https://www.drupal.org/u/good_man |
|
210 |
[12]: https://www.drupal.org/u/gisle |
|
211 |
[13]: https://hannemyr.no |
drupal7/sites/all/modules/content_access/README.txt | ||
---|---|---|
1 |
|
|
2 |
Content Access Module |
|
3 |
----------------------- |
|
4 |
by Wolfgang Ziegler, nuppla@zites.net |
|
5 |
|
|
6 |
Yet another node access module. |
|
7 |
This module allows you to manage permissions for content types by role. It allows you to specifiy |
|
8 |
custom view, view own, edit, edit own, delete and delete own permissions for each content type. |
|
9 |
Optionally you can enable per content access settings, so you can customize the access for each |
|
10 |
content node. |
|
11 |
|
|
12 |
In particular |
|
13 |
* it comes with sensible defaults, so you need not configure anything and everything stays working |
|
14 |
* it is as flexible as you want. It can work with per content type settings, per content node settings |
|
15 |
as well as with flexible Access Control Lists (with the help of the ACL module). |
|
16 |
* it trys to reuse existing functionality instead of reimplementing it. So one can install the ACL |
|
17 |
module and set per user access control settings per content node. |
|
18 |
Furthermore the module provides conditions and actions for the rules module, which allows one |
|
19 |
to configure even rule-based access permissions. |
|
20 |
* it optimizes the written content node grants, so that only the really necessary grants are written. |
|
21 |
This is important for the performance of your site. |
|
22 |
* it takes access control as important as it is. E.g. the module has a bunch of simpletests to ensure |
|
23 |
everything is working right. |
|
24 |
* it respects and makes use of drupal's built in permissions as far as possible. Which means the |
|
25 |
access control tab provided by this module takes them into account and provides you a good overview |
|
26 |
about the really applied access control settings. [1] |
|
27 |
|
|
28 |
|
|
29 |
So the module is simple to use, but can be configured to provide really fine-grained permissions! |
|
30 |
|
|
31 |
|
|
32 |
Installation |
|
33 |
------------ |
|
34 |
* Copy the content access module's directory to your modules directory and activate the module. |
|
35 |
* Optionally download and install the ACL module too. |
|
36 |
* Edit a content type at admin/content/types. There will be a new tab "Access Control". |
|
37 |
|
|
38 |
|
|
39 |
ACL Module |
|
40 |
----------- |
|
41 |
You can find the ACL module at http://drupal.org/project/acl. To make use of Access Control Lists |
|
42 |
you'll need to enable per content node access control settings for a content type. At the access |
|
43 |
control tab of such a content node you are able to grant view, edit or delete permission for specific |
|
44 |
users. |
|
45 |
|
|
46 |
|
|
47 |
Running multiple node access modules on a site (Advanced!) |
|
48 |
----------------------------------------------------------- |
|
49 |
A drupal node access module can only grant access to content nodes, but not deny it. So if you |
|
50 |
are using multiple node access modules, access will be granted to a node as soon as one of the |
|
51 |
module grants access to it. |
|
52 |
However you can influence the behaviour by changing the priority of the content access module as |
|
53 |
drupal applies *only* the grants with the highest priority. So if content access has the highest |
|
54 |
priority *alone*, only its grants will be applied. |
|
55 |
|
|
56 |
By default node access modules use priority 0. |
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
Footnotes |
|
61 |
---------- |
|
62 |
|
|
63 |
[1] Note that this overview can't take other modules into account, which might also alter node access. |
|
64 |
If you have multiple modules installed that alter node access, read the paragraph about "Running |
|
65 |
multiple node access modules on a site". |
drupal7/sites/all/modules/content_access/UPGRADE.txt | ||
---|---|---|
1 |
|
|
2 |
Upgrade from 5.x |
|
3 |
---------------- |
|
4 |
|
|
5 |
You can easily upgrade from drupal 5 installations. After upgrading your drupal installation |
|
6 |
just install the latest module and run update.php - it will automatically run the upgrade routine |
|
7 |
which is update 6001. |
|
8 |
|
|
9 |
After that the content access permissions for your site needs to be rebuilt. Just go to your |
|
10 |
site and follow the instructions. |
|
11 |
|
|
12 |
|
|
13 |
Notes for workflow-ng users |
|
14 |
---------------------------- |
|
15 |
The workflow-ng integration has been properly upgraded to its 6.x version, the rules module. |
|
16 |
However it has been a bit refactored: The 'Set content permissions' action has been removed in |
|
17 |
favor of the 'Grant content permissions by role' and 'Revoke content permissions by role' as |
|
18 |
this gives us more flexibility. |
|
19 |
|
|
20 |
So the automatic upgrade of your configured rules converts the 'Set content permissions' action |
|
21 |
to an 'Grant content permissions by role' action. If this doesn't fit, you'll have to edit it |
|
22 |
manually. |
|
23 |
|
|
24 |
All other conditions and actions have their equivalent in rules and will be automatically converted. |
drupal7/sites/all/modules/content_access/content_access.admin.inc | ||
---|---|---|
52 | 52 |
'#value' => t('Reset to defaults'), |
53 | 53 |
'#weight' => 10, |
54 | 54 |
'#submit' => array('content_access_page_reset'), |
55 |
'#access' => count(content_access_get_per_node_settings($node)) > 0,
|
|
55 |
'#access' => !empty(content_access_get_per_node_settings($node)),
|
|
56 | 56 |
); |
57 | 57 |
$form['submit'] = array( |
58 | 58 |
'#type' => 'submit', |
... | ... | |
93 | 93 |
|
94 | 94 |
// Apply new settings. |
95 | 95 |
node_access_acquire_grants($node); |
96 |
|
|
97 |
module_invoke_all('per_node', $settings); |
|
98 |
|
|
99 |
drupal_set_message(t('Your changes have been saved.')); |
|
96 |
cache_clear_all(); |
|
97 |
module_invoke_all('per_node', $settings, $node); |
|
98 |
drupal_set_message(t('Your changes have been saved. You may have to !rebuild for your changes to take effect.', array('!rebuild' => l(t('rebuild permissions'), 'admin/reports/status/rebuild')))); |
|
100 | 99 |
} |
101 | 100 |
|
102 | 101 |
/** |
... | ... | |
106 | 105 |
content_access_delete_per_node_settings($form_state['node']); |
107 | 106 |
node_access_acquire_grants($form_state['node']); |
108 | 107 |
|
109 |
drupal_set_message(t('The permissions have been reseted to the content type defaults.'));
|
|
108 |
drupal_set_message(t('The permissions have been reset to the content type defaults.')); |
|
110 | 109 |
} |
111 | 110 |
|
112 | 111 |
/** |
... | ... | |
219 | 218 |
} |
220 | 219 |
} |
221 | 220 |
|
222 |
drupal_set_message(t('Your changes have been saved.'));
|
|
221 |
drupal_set_message(t('Your changes have been saved. You may have to !rebuild for your changes to take effect.', array('!rebuild' => l(t('rebuild permissions'), 'admin/reports/status/rebuild'))));
|
|
223 | 222 |
} |
224 | 223 |
|
225 | 224 |
/** |
... | ... | |
272 | 271 |
'#type' => 'fieldset', |
273 | 272 |
'#title' => t('Role based access control settings'), |
274 | 273 |
'#collapsible' => TRUE, |
275 |
'#description' => t('Note that users need at least the %access_content permission to be able to deal in any way with content.', array('%access_content' => t('access content'))) .
|
|
276 |
' ' . t('Furthermore note that content which is not @published is treated in a different way by drupal: It can be viewed only by its author or users with the %administer_nodes permission.', array('@published' => t('published'), '%administer_nodes' => t('administer nodes'))),
|
|
274 |
'#description' => t('Note that users need at least the %view_published_content permission to be able to deal in any way with content.', array('%view_published_content' => t('view published content'))) .
|
|
275 |
' ' . t('Furthermore note that content which is not @published is treated in a different way by drupal: It can be viewed only by its author or users with the %bypass_node_access permission.', array('@published' => t('published'), '%bypass_node_access' => t('bypass content access control'))),
|
|
277 | 276 |
); |
278 | 277 |
|
279 | 278 |
$operations = _content_access_get_operations($type); |
... | ... | |
344 | 343 |
array('@types' => implode(', ', $types)) |
345 | 344 |
)); |
346 | 345 |
} |
347 |
} |
|
346 |
} |
drupal7/sites/all/modules/content_access/content_access.info | ||
---|---|---|
1 | 1 |
name = Content Access |
2 | 2 |
description = Provides flexible content access control. |
3 | 3 |
core = 7.x |
4 |
php = 5.6 |
|
4 | 5 |
package = Access control |
5 |
files[] = content_access.rules.inc |
|
6 | 6 |
files[] = tests/content_access.test |
7 |
files[] = tests/content_access_acl.test |
|
8 |
; Information added by drupal.org packaging script on 2013-04-15
|
|
9 |
version = "7.x-1.2-beta2"
|
|
7 |
|
|
8 |
; Information added by Drupal.org packaging script on 2020-06-25
|
|
9 |
version = "7.x-1.2-beta3"
|
|
10 | 10 |
core = "7.x" |
11 | 11 |
project = "content_access" |
12 |
datestamp = "1366014321" |
|
13 |
|
|
12 |
datestamp = "1593095998" |
drupal7/sites/all/modules/content_access/content_access.install | ||
---|---|---|
42 | 42 |
*/ |
43 | 43 |
function content_access_update_7101() { |
44 | 44 |
$settings = variable_get('content_access_settings', array()); |
45 |
$settings_new = array(); |
|
45 | 46 |
foreach ($settings as $setting => $data) { |
46 | 47 |
foreach ($data as $type_name => $value) { |
47 | 48 |
$settings_new[$type_name][$setting] = $value; |
drupal7/sites/all/modules/content_access/content_access.module | ||
---|---|---|
11 | 11 |
switch ($path) { |
12 | 12 |
case 'admin/help#content_access': |
13 | 13 |
$output = '<h3>' . t('About') . '</h3>'; |
14 |
$output .= '<p>' . t('Content Access module provides flexible way to control how and who should read or control your site content. Content Access can define custom access control rules for content types and even for every piece of content.') . '</p>'; |
|
15 |
$output .= '<h3>' . t('Uses') . '</h3>'; |
|
16 |
$output .= '<dl>'; |
|
17 |
$output .= '<dt>' . t('Default and custom settings') . '</dt>'; |
|
18 |
$output .= '<dd>' . t("Each <a href='@content-type'>content type</a> can have its own default content access settings configured as: <em>View any content</em> to allow anyone to view content from this content type, <em>View own content</em> to allow only content creators to see their own content, <em>Edit any content</em> to allow anyone to edit content from this content type, <em>Edit own content</em> to allow only content creators to edit their own content, <em>Delete any content</em> to allow anyone to delete content from this content type, <em>Delete own content </em> to allow content creators to delete their own content. This default settings for each content type can be further customized per every piece of content per user if you have <a href='@acl'>ACL</a> module enabled.", array('@content-type' => url('admin/structure/types'), '@acl' => 'http://drupal.org/project/acl/')) . '</dd>'; |
|
19 |
$output .= '</dl>'; |
|
14 |
$output .= '<p>' . t('The <strong>Content Access</strong> module let you content manage access permission in a flexible and transparant way.') . '</p>'; |
|
15 |
$output .= '<h3>' . t('Use') . '</h3>'; |
|
16 |
$output .= '<p>' . t('It provides two new permissions: <em>view all</em> (allows anyone to view the content) and <em>view own</em> (allows only the content creator to see his/her own content). It also gives access to the existing core permissions <em>edit</em> and <em>delete</em> on the same settings page.') . '</p>'; |
|
17 |
$output .= '<p>' . t('It provides the following modalities:') . '</p><ul>'; |
|
18 |
$output .= '<li>' . t('Each <em>!content-type</em> can have its own default content access settings by role.', array('!content-type' => l('content type', 'admin/structure/types'))) . '</li>'; |
|
19 |
$output .= '<li>' . t('Optionally you can enable role based access control settings per <em>content node</em>.') . '</li>'; |
|
20 |
$output .= '<li>' . t('Access control can be further customized per <em>user</em> if you have the <strong>!acl</strong> module enabled.', |
|
21 |
array('!acl' => l('ACL', 'https://www.drupal.org/project/acl/'))) . '</li></ul>'; |
|
22 |
if (function_exists('advanced_help_hint_docs')) { |
|
23 |
$output .= '<p>' . advanced_help_hint_docs('content_access', 'https://drupal.org/node/1194974', TRUE) . '</p>'; |
|
24 |
} |
|
25 |
else { |
|
26 |
$output .= '<p>' .t('If you install and enable the module <strong>!url</strong>, you will get more help for <strong>Content Access</strong>.', |
|
27 |
array('!url' => l('Advanced Help Hint', 'https://www.drupal.org/project/advanced_help_hint'))) . '</p>'; |
|
28 |
} |
|
20 | 29 |
return $output; |
21 | 30 |
} |
22 | 31 |
} |
23 |
|
|
32 |
|
|
24 | 33 |
/** |
25 | 34 |
* Implements hook_admin_paths(). |
26 | 35 |
*/ |
... | ... | |
219 | 228 |
* Save content_access settings of a content type. |
220 | 229 |
*/ |
221 | 230 |
function content_access_set_settings($settings, $type_name) { |
222 |
// Do not store default values so we do not have to care about synching our
|
|
231 |
// Do not store default values so we do not have to care about syncing our |
|
223 | 232 |
// settings with the permissions. |
224 | 233 |
foreach (content_access_get_setting_defaults($type_name) as $setting => $default_value) { |
225 | 234 |
if (isset($settings[$setting]) && $settings[$setting] == $default_value) { |
... | ... | |
329 | 338 |
* @param $any_roles |
330 | 339 |
* The roles with which anybody has access (not optimized!) |
331 | 340 |
* @param $own_roles |
332 |
* The roles with which only the author has acess (optimized!) |
|
341 |
* The roles with which only the author has access (optimized!)
|
|
333 | 342 |
*/ |
334 | 343 |
function content_access_own_op($node, $any_roles, $own_roles) { |
335 | 344 |
static $roles = array(); |
... | ... | |
385 | 394 |
* @param $node |
386 | 395 |
* The node object. |
387 | 396 |
* @param $settings |
388 |
* Optional array used to update the settings cache with the given settings.
|
|
397 |
* Optional array used to update the settings cache with the given settings. |
|
389 | 398 |
* @return |
390 | 399 |
* An array of role ids which have access. |
391 | 400 |
*/ |
... | ... | |
587 | 596 |
*/ |
588 | 597 |
function content_access_disable_checkboxes($element) { |
589 | 598 |
$access_roles = content_access_get_permission_access('access content'); |
590 |
$admin_roles = content_access_get_permission_access('administer nodes');
|
|
599 |
$admin_roles = content_access_get_permission_access('bypass node access');
|
|
591 | 600 |
|
592 | 601 |
foreach (element_children($element) as $key) { |
593 | 602 |
if (!in_array($key, $access_roles) && |
... | ... | |
600 | 609 |
} |
601 | 610 |
elseif (in_array($key, $admin_roles) || |
602 | 611 |
($key != DRUPAL_ANONYMOUS_RID && in_array(DRUPAL_AUTHENTICATED_RID, $admin_roles))) { |
603 |
// Fix the checkbox to be enabled for users with administer node privileges
|
|
612 |
// Fix the checkbox to be enabled for users with bypass node access privileges
|
|
604 | 613 |
$element[$key]['#disabled'] = TRUE; |
605 | 614 |
$element[$key]['#default_value'] = TRUE; |
606 |
$element[$key]['#prefix'] = '<span' . drupal_attributes(array('title' => t("This role has '@perm' permission, so access is granted.", array('@perm' => t('administer nodes'))))) . '>';
|
|
615 |
$element[$key]['#prefix'] = '<span' . drupal_attributes(array('title' => t("This role has '@perm' permission, so access is granted.", array('@perm' => t('bypass node access'))))) . '>';
|
|
607 | 616 |
$element[$key]['#suffix'] = "</span>"; |
608 | 617 |
} |
609 | 618 |
} |
... | ... | |
637 | 646 |
foreach ($result as $node) { |
638 | 647 |
acl_node_clear_acls($node->nid, 'content_access'); |
639 | 648 |
} |
640 |
} |
|
649 |
} |
|
650 |
|
|
651 |
/** |
|
652 |
* Implements hook_node_export_alter(). |
|
653 |
*/ |
|
654 |
function content_access_node_export_alter(array $nodes) { |
|
655 |
foreach ($nodes as $node) { |
|
656 |
$node->content_access = content_access_get_per_node_settings($node); |
|
657 |
} |
|
658 |
} |
|
659 |
|
|
660 |
/** |
|
661 |
* Implements hook_node_export_after_import_alter(). |
|
662 |
*/ |
|
663 |
function content_access_node_export_after_import_alter(array $nodes) { |
|
664 |
foreach ($nodes as $node) { |
|
665 |
if(empty($node->nid)) |
|
666 |
continue; |
|
667 |
content_access_save_per_node_settings($node, $node->content_access); |
|
668 |
} |
|
669 |
// Rebuild content access permissions |
|
670 |
node_access_rebuild(); |
|
671 |
} |
drupal7/sites/all/modules/content_access/content_access_rules/content_access_rules.info | ||
---|---|---|
4 | 4 |
core = 7.x |
5 | 5 |
dependencies[] = content_access |
6 | 6 |
dependencies[] = rules |
7 |
files[] = content_access.rules.inc |
|
8 | 7 |
|
9 |
; Information added by drupal.org packaging script on 2013-04-15
|
|
10 |
version = "7.x-1.2-beta2"
|
|
8 |
; Information added by Drupal.org packaging script on 2020-06-25
|
|
9 |
version = "7.x-1.2-beta3"
|
|
11 | 10 |
core = "7.x" |
12 | 11 |
project = "content_access" |
13 |
datestamp = "1366014321" |
|
14 |
|
|
12 |
datestamp = "1593095998" |
drupal7/sites/all/modules/content_access/content_access_rules/content_access_rules.module | ||
---|---|---|
22 | 22 |
/** |
23 | 23 |
* Implements hook_per_node(). |
24 | 24 |
*/ |
25 |
function content_access_rules_per_node($settings) { |
|
26 |
rules_invoke_event('content_access_per_node'); |
|
27 |
} |
|
25 |
function content_access_rules_per_node($settings, $node) { |
|
26 |
rules_invoke_event('content_access_per_node', $node); |
|
27 |
} |
drupal7/sites/all/modules/content_access/content_access_rules/content_access_rules.rules.inc | ||
---|---|---|
17 | 17 |
*/ |
18 | 18 |
function content_access_rules_rules_event_info() { |
19 | 19 |
$events['content_access_content_type'] = array('label' => t('Content type access control was changed')); |
20 |
$events['content_access_per_node'] = array('label' => t('Per node access control was changed')); |
|
20 |
$events['content_access_per_node'] = array( |
|
21 |
'label' => t('Per node access control was changed'), |
|
22 |
'variables' => array( |
|
23 |
'node' => array('type' => 'node', 'label' => 'Content with updated content access'), |
|
24 |
), |
|
25 |
); |
|
21 | 26 |
|
22 | 27 |
if (module_exists('acl')) { |
23 | 28 |
$events['content_access_user_acl'] = array('label' => t('User was added to ACL')); |
... | ... | |
25 | 30 |
|
26 | 31 |
$items = array(); |
27 | 32 |
foreach ($events as $name => $event) { |
28 |
$items[$name] = array( |
|
29 |
'label' => $event['label'], |
|
33 |
$items[$name] = $event + array( |
|
30 | 34 |
'group' => t('Content Access'), |
31 | 35 |
); |
32 | 36 |
} |
... | ... | |
390 | 394 |
// node_save() does implement node_access_acquire_grants() so we don't want |
391 | 395 |
// to execute it again or we'll get a duplicated key exception |
392 | 396 |
if (!isset($node->op) || |
393 |
(isset($node->op) && $node->op != 'Save')) {
|
|
397 |
(isset($node->op) && $node->op != t('Save'))) {
|
|
394 | 398 |
node_access_acquire_grants($node); |
395 | 399 |
} |
396 |
} |
|
400 |
} |
drupal7/sites/all/modules/content_access/help/content_access.help.ini | ||
---|---|---|
1 |
[advanced help settings] |
|
2 |
show readme = TRUE |
|
3 |
|
|
4 |
[rules] |
|
5 |
title = Rules |
|
6 |
weight = -11 |
|
7 |
|
|
8 |
[nodeexport] |
|
9 |
title = Node Export |
|
10 |
weight = -10 |
|
11 |
|
|
12 |
[integration] |
|
13 |
title = Integration with other modules |
|
14 |
weight = -9 |
drupal7/sites/all/modules/content_access/help/integration.html | ||
---|---|---|
1 |
<h2>Introduction</h2> |
|
2 |
|
|
3 |
<p>This section contains notes about how to integrate <strong>Content |
|
4 |
Access</strong> with other modules.</p> |
|
5 |
|
|
6 |
<p>I have not tested these myself, so I do not guarantee that the |
|
7 |
suggestion collected below actually work. They are just to keep the |
|
8 |
links to the workarounds posted somewhere on the web in a single |
|
9 |
file.</p> |
|
10 |
|
|
11 |
<p>If you spot link rot, or wrong information, on this page, please |
|
12 |
report it using the project's |
|
13 |
<a href="https://drupal.org/project/issues/content_access">issue queue</a>.</p> |
|
14 |
|
|
15 |
|
|
16 |
<h2>Varnish, Cachewall</h2> |
|
17 |
|
|
18 |
<p><em>Varnish</em> and other cache systems such as <em>Cachewall</em> |
|
19 |
by default will delete cookies before they reach Drupal, so everybody |
|
20 |
becomes an anonymous user. This precludes access to private file |
|
21 |
attachments.</p> |
|
22 |
|
|
23 |
<p>Below are settings for <em>Varnish</em> to prevent this for some |
|
24 |
file types:</p> |
|
25 |
|
|
26 |
<pre> |
|
27 |
# Always cache the following file types for all users. This list of extensions |
|
28 |
# appears twice, once here and again in vcl_fetch so make sure you edit both |
|
29 |
# and keep them equal. |
|
30 |
|
|
31 |
if (req.url ~ "(?i)\.(pdf|txt|csv|png|gif|jpg|ico|swf|css|js)(\?.*)?$") { |
|
32 |
unset req.http.Cookie; |
|
33 |
} |
|
34 |
</pre> |
|
35 |
|
|
36 |
<ul> |
|
37 |
<li>Drupal.org: <a href="https://www.drupal.org/project/content_access/issues/2682635">Issue #2682635</a></li> |
|
38 |
<li>Drupal.org: <a href="https://www.drupal.org/project/webform/issues/2421429#comment-9667677">Issue #2421429, comment #4</a></li> |
|
39 |
</ul> |
|
40 |
|
|
41 |
|
|
42 |
<h2>Views and Workbench</h2> |
|
43 |
|
|
44 |
<p>If you have problems intgrating <strong>Views</strong> and/or <strong>Workbench</strong>, |
|
45 |
in particular in connection with the “<em>View own unpublished content</em>” permission, |
|
46 |
one of these links may help:</p> |
|
47 |
|
|
48 |
<ul> |
|
49 |
<li>Drupal.org: <a href="https://www.drupal.org/project/content_access/issues/2204609">Issue #2205609</a></li> |
|
50 |
<li>Drupal Answers: <a href="https://drupal.stackexchange.com/q/41997/12076">Problem with “Content Access” and permission “View own unpublished content”</a>.</li> |
|
51 |
<li>Drupalprimer: <a href="http://drupalprimer.com/node/2">Drupal 7's Access Control module prevents view of user's own unpublished content</a>.</li> |
|
52 |
</ul> |
|
53 |
|
|
54 |
<p>Problems using relationships in <strong>Views</strong> may be solved by patching core:</p> |
|
55 |
|
|
56 |
<ul> |
|
57 |
<li>Drupal.org: <a href="https://www.drupal.org/project/content_access/issues/2020453">Issue #2020453</a></li> |
|
58 |
<li>Drupal.org: <a href="https://www.drupal.org/project/drupal/issues/1349080#comment-10953027">Issue #1349080, comment #332</a></li> |
|
59 |
</ul> |
drupal7/sites/all/modules/content_access/help/nodeexport.html | ||
---|---|---|
1 |
<h2>Introduction</h2> |
|
2 |
|
|
3 |
<p>This page is just a placeholder. Until it is populated, please see:</p> |
|
4 |
|
|
5 |
<ul> |
|
6 |
<li>Drupal.org: <a href="https://www.drupal.org/project/content_access/issues/2661872">Issue #2661872</a></li> |
|
7 |
</ul> |
|
8 |
|
|
9 |
|
|
10 |
|
drupal7/sites/all/modules/content_access/help/rules.html | ||
---|---|---|
1 |
<h2>Introduction</h2> |
|
2 |
|
|
3 |
<p>This section contains notes about how to |
|
4 |
integrate with <strong>Rules</strong>.</p> |
|
5 |
|
|
6 |
<p><strong>Note</strong>: This only work on individual nodes. The |
|
7 |
rules for access control that you set up will not be |
|
8 |
executed <em>unless</em> you have enabled per content node access |
|
9 |
control settings.</p> |
|
10 |
|
|
11 |
<h2>Rules integrations example</h2> |
|
12 |
|
|
13 |
<p>In this example, there will be two user roles: “writer” and |
|
14 |
“editor”. There will also be two users: A writer named “Bob” and an |
|
15 |
editor named “Ben”. There will also be a third user named “Alice” |
|
16 |
that will not belong to any of there roles. We shall set up a workflow |
|
17 |
where “Bob” creates content, and when that content is saved, only |
|
18 |
users with the “editor” user role (e.g. “Ben”) will be allowed to see |
|
19 |
it.</p> |
|
20 |
|
|
21 |
<p>Set up:</p> |
|
22 |
|
|
23 |
<ul> |
|
24 |
<li>Ensure <strong>Content Access</strong> is enabled (if you can read this in the browser, it is).</li> |
|
25 |
<li>Enable both the <strong>Rules</strong> and <strong>Rules UI</strong> modules.</li> |
|
26 |
<li>Enable the <strong>Content Access Rules Integrations</strong> module.</li> |
|
27 |
<li>Create the roles: “writer” and “editor” and the users “Bob”, “Ben” and “Alice”. Assign roles.</li> |
|
28 |
<li>Set up default role based access control settings. Give the “anonymous user” role and the “authenticated user” role access to “View any article content” and “View own article content”.</li> |
|
29 |
<li>Check “Enable per content node access control settings”. You find this checkbox under the “Access Control” tab located on the settings page for the content type.</li> |
|
30 |
</ul> |
|
31 |
|
|
32 |
<p>Create the rules:</p> |
|
33 |
|
|
34 |
<ul> |
|
35 |
<li>Navigate to <span class="nav">Configuration » Workflow » Rules<span>.</li> |
|
36 |
<li>Click “Add new rule”.</li> |
|
37 |
<li>Name the rule “editor oversight”.</li> |
|
38 |
<li>Leave the field “Tags” empty.</li> |
|
39 |
<li>In the pulldown menu for “React on event”, select “After saving new contents”.</li> |
|
40 |
<li>Leave “Restrict by type” set to “- None -”.</li> |
|
41 |
<li>Click “Save”.</li> |
|
42 |
</ul> |
|
43 |
|
|
44 |
<div class="help-imgpos-center" style="max-width:620px"> |
|
45 |
<img class="help-img" alt="ahelp_tab.png" title="New rule: Editor oversight" src="&path&rules01.png" width="620" /> |
|
46 |
<div class="help-img-caption" style="max-width:620px">Adding a new rule</div> |
|
47 |
</div> |
|
48 |
|
|
49 |
<p>This sets up a new rule named “editor oversight” that triggers when |
|
50 |
a new node is saved.</p> |
|
51 |
|
|
52 |
|
|
53 |
<ul> |
|
54 |
<li>Under “Conditions”, click “Add condition”,</li> |
|
55 |
<li>From the pulldown menu “Select <em>condition</em> to add”, select “User has role(s)”.</li> |
|
56 |
<li>After making the selection, you automatically continue to a new page to set up a data selector.</li> |
|
57 |
<li>For the “Data selector” field, choose “node:author”.</li> |
|
58 |
<li>Under “Roles”, for “Value”, select “writer”.</li> |
|
59 |
<li>Click “Save”.</li> |
|
60 |
</ul> |
|
61 |
|
|
62 |
<p>This sets up a contition for following the rule. The rule is only |
|
63 |
followed when the user with the role “writer” triggers an event that |
|
64 |
matches “After saving new contents”.</p> |
|
65 |
|
|
66 |
<p>The final step adds an action that happens when the rule is |
|
67 |
triggered and the conditions are met.</p> |
|
68 |
|
|
69 |
<ul> |
|
70 |
<li>Under “Actions”, click “Add action”,</li> |
|
71 |
<li>From the pulldown menu “Select <em>action</em> to add”, select “Grant Access by role”.</li> |
|
72 |
<li>After making the selection, you automatically continue to a new page to set up role based access settings.</li> |
|
73 |
<li>Look under “Role-based access control settings”. Give the “editor” the right to “View any content” “View own content”. Checking a box grants the access.</li> |
|
74 |
<li>Under “Actions”, again click “Add action”,</li> |
|
75 |
<li>From the pulldown menu “Select <em>action</em> to add”, select “Revoke Access by role”.</li> |
|
76 |
<li>After making the selection, you automatically continue to a new page to set up role based access settings.</li> |
|
77 |
<li>Look under “Role-based access control settings”. Revoke “View any content” “View own content” for the “anonymous user” role and the the “authenticated user” role. Checking a box revokes the access.</li> |
|
78 |
<li>Click “Save”.</li> |
|
79 |
</ul> |
|
80 |
|
|
81 |
<p>Verify that it works:</p> |
|
82 |
|
|
83 |
<ul> |
|
84 |
<li>Create an artcle as “Alice” (no special role). Verify that is viewable by everyone.</li> |
|
85 |
<li>Create an artcle as “Bob” (the writer). Verify that is viewable by “Ben” (the editor), but not by “Alice”.</li> |
|
86 |
</ul> |
|
87 |
|
drupal7/sites/all/modules/content_access/tests/content_access.test | ||
---|---|---|
2 | 2 |
|
3 | 3 |
/** |
4 | 4 |
* @file |
5 |
* Automatd SimpleTest Case for content access module
|
|
5 |
* Automated SimpleTest Case for content access module.
|
|
6 | 6 |
*/ |
7 | 7 |
|
8 |
require_once(drupal_get_path('module', 'content_access') .'/tests/content_access_test_help.php');
|
|
8 |
require_once drupal_get_path('module', 'content_access') . '/tests/content_access_test_help.php';
|
|
9 | 9 |
|
10 | 10 |
class ContentAccessModuleTestCase extends ContentAccessTestCase { |
11 | 11 |
|
12 | 12 |
/** |
13 |
* Implementation of get_info() for information
|
|
13 |
* Implements get_info() for information.
|
|
14 | 14 |
*/ |
15 | 15 |
public static function getInfo() { |
16 | 16 |
return array( |
... | ... | |
23 | 23 |
function setUp($module = '') { |
24 | 24 |
parent::setUp(); |
25 | 25 |
|
26 |
// Create test nodes |
|
26 |
// Create test nodes.
|
|
27 | 27 |
$this->node1 = $this->drupalCreateNode(array('type' => $this->content_type->type)); |
28 | 28 |
$this->node2 = $this->drupalCreateNode(array('type' => $this->content_type->type)); |
29 | 29 |
} |
30 | 30 |
|
31 | 31 |
/** |
32 |
* Test for viewing nodes |
|
32 |
* Test for viewing nodes.
|
|
33 | 33 |
*/ |
34 | 34 |
function testViewAccess() { |
35 |
// Restrict access to the content type (access is only allowed for the author) |
|
35 |
// Restrict access to the content type (access is only allowed for the |
|
36 |
// author). |
|
36 | 37 |
$access_permissions = array( |
37 | 38 |
'view[1]' => FALSE, |
38 | 39 |
'view[2]' => FALSE, |
39 | 40 |
); |
40 | 41 |
$this->changeAccessContentType($access_permissions); |
41 | 42 |
|
42 |
// Logout admin and try to access the node anonymously |
|
43 |
// Logout admin and try to access the node anonymously.
|
|
43 | 44 |
$this->drupalLogout(); |
44 |
$this->drupalGet('node/'. $this->node1->nid); |
|
45 |
$this->drupalGet('node/' . $this->node1->nid);
|
|
45 | 46 |
$this->assertText(t('Access denied'), 'node is not viewable'); |
46 | 47 |
|
47 |
// Login test user, view node, access must be denied |
|
48 |
// Login test user, view node, access must be denied.
|
|
48 | 49 |
$this->drupalLogin($this->test_user); |
49 |
$this->drupalGet('node/'. $this->node1->nid); |
|
50 |
$this->drupalGet('node/' . $this->node1->nid);
|
|
50 | 51 |
$this->assertText(t('Access denied'), 'node is not viewable'); |
51 | 52 |
|
52 |
// Login admin and grant access for viewing to the test user |
|
53 |
// Login admin and grant access for viewing to the test user.
|
|
53 | 54 |
$this->drupalLogin($this->admin_user); |
54 | 55 |
$this->changeAccessContentTypeKeyword('view'); |
55 | 56 |
|
56 |
// Logout admin and try to access the node anonymously |
|
57 |
// access must be denied again
|
|
57 |
// Logout admin and try to access the node anonymously.
|
|
58 |
// Access must be denied again.
|
|
58 | 59 |
$this->drupalLogout(); |
59 |
$this->drupalGet('node/'. $this->node1->nid); |
|
60 |
$this->drupalGet('node/' . $this->node1->nid);
|
|
60 | 61 |
$this->assertText(t('Access denied'), 'node is not viewable'); |
61 | 62 |
|
62 |
// Login test user, view node, access must be granted |
|
63 |
// Login test user, view node, access must be granted.
|
|
63 | 64 |
$this->drupalLogin($this->test_user); |
64 |
$this->drupalGet('node/'. $this->node1->nid); |
|
65 |
$this->drupalGet('node/' . $this->node1->nid);
|
|
65 | 66 |
$this->assertNoText(t('Access denied'), 'node is viewable'); |
66 | 67 |
|
67 |
// Login admin and enable per node access |
|
68 |
// Login admin and enable per node access.
|
|
68 | 69 |
$this->drupalLogin($this->admin_user); |
69 | 70 |
$this->changeAccessPerNode(); |
70 | 71 |
|
71 |
// Restrict access on node2 for the test user role |
|
72 |
// Restrict access on node2 for the test user role.
|
|
72 | 73 |
$this->changeAccessNodeKeyword($this->node2, 'view', FALSE); |
73 | 74 |
|
74 |
// Logout admin and try to access both nodes anonymously |
|
75 |
// Logout admin and try to access both nodes anonymously.
|
|
75 | 76 |
$this->drupalLogout(); |
76 |
$this->drupalGet('node/'. $this->node1->nid); |
|
77 |
$this->drupalGet('node/' . $this->node1->nid);
|
|
77 | 78 |
$this->assertText(t('Access denied'), 'node1 is not viewable'); |
78 |
$this->drupalGet('node/'. $this->node2->nid); |
|
79 |
$this->drupalGet('node/' . $this->node2->nid);
|
|
79 | 80 |
$this->assertText(t('Access denied'), 'node2 is not viewable'); |
80 | 81 |
|
81 |
// Login test user, view node1, access must be granted |
|
82 |
// Login test user, view node1, access must be granted.
|
|
82 | 83 |
$this->drupalLogin($this->test_user); |
83 |
$this->drupalGet('node/'. $this->node1->nid); |
|
84 |
$this->drupalGet('node/' . $this->node1->nid);
|
|
84 | 85 |
$this->assertNoText(t('Access denied'), 'node1 is viewable'); |
85 | 86 |
|
86 |
// View node2, access must be denied |
|
87 |
$this->drupalGet('node/'. $this->node2->nid); |
|
87 |
// View node2, access must be denied.
|
|
88 |
$this->drupalGet('node/' . $this->node2->nid);
|
|
88 | 89 |
$this->assertText(t('Access denied'), 'node2 is not viewable'); |
89 | 90 |
|
90 |
// Login admin, swap permissions between content type and node2 |
|
91 |
// Login admin, swap permissions between content type and node2.
|
|
91 | 92 |
$this->drupalLogin($this->admin_user); |
92 | 93 |
|
93 |
// Restrict access to content type |
|
94 |
// Restrict access to content type.
|
|
94 | 95 |
$this->changeAccessContentTypeKeyword('view', FALSE); |
95 | 96 |
|
96 |
// Grant access to node2 |
|
97 |
// Grant access to node2.
|
|
97 | 98 |
$this->changeAccessNodeKeyword($this->node2, 'view'); |
98 | 99 |
|
99 |
// Logout admin and try to access both nodes anonymously |
|
100 |
// Logout admin and try to access both nodes anonymously.
|
|
100 | 101 |
$this->drupalLogout(); |
101 |
$this->drupalGet('node/'. $this->node1->nid); |
|
102 |
$this->drupalGet('node/' . $this->node1->nid);
|
|
102 | 103 |
$this->assertText(t('Access denied'), 'node1 is not viewable'); |
103 |
$this->drupalGet('node/'. $this->node2->nid); |
|
104 |
$this->drupalGet('node/' . $this->node2->nid);
|
|
104 | 105 |
$this->assertText(t('Access denied'), 'node2 is not viewable'); |
105 | 106 |
|
106 |
// Login test user, view node1, access must be denied |
|
107 |
// Login test user, view node1, access must be denied.
|
|
107 | 108 |
$this->drupalLogin($this->test_user); |
108 |
$this->drupalGet('node/'. $this->node1->nid); |
|
109 |
$this->drupalGet('node/' . $this->node1->nid);
|
|
109 | 110 |
$this->assertText(t('Access denied'), 'node1 is not viewable'); |
110 | 111 |
|
111 |
// View node2, access must be granted |
|
112 |
$this->drupalGet('node/'. $this->node2->nid); |
|
112 |
// View node2, access must be granted.
|
|
113 |
$this->drupalGet('node/' . $this->node2->nid);
|
|
113 | 114 |
$this->assertNoText(t('Access denied'), 'node2 is viewable'); |
114 | 115 |
} |
115 | 116 |
|
116 | 117 |
/** |
117 |
* Test for editing nodes |
|
118 |
* Test for editing nodes.
|
|
118 | 119 |
*/ |
119 | 120 |
function testEditAccess() { |
120 |
// Logout admin and try to edit the node anonymously |
|
121 |
// Logout admin and try to edit the node anonymously.
|
|
121 | 122 |
$this->drupalLogout(); |
122 |
$this->drupalGet('node/'. $this->node1->nid .'/edit');
|
|
123 |
$this->drupalGet('node/' . $this->node1->nid . '/edit');
|
|
123 | 124 |
$this->assertText(t('Access denied'), 'edit access denied for anonymous'); |
124 | 125 |
|
125 |
// Login test user, edit node, access must be denied |
|
126 |
// Login test user, edit node, access must be denied.
|
|
126 | 127 |
$this->drupalLogin($this->test_user); |
127 |
$this->drupalGet('node/'. $this->node1->nid .'/edit');
|
|
128 |
$this->drupalGet('node/' . $this->node1->nid . '/edit');
|
|
128 | 129 |
$this->assertText(t('Access denied'), 'edit access denied for test user'); |
129 | 130 |
|
130 |
// Login admin and grant access for editing to the test user |
|
131 |
// Login admin and grant access for editing to the test user.
|
|
131 | 132 |
$this->drupalLogin($this->admin_user); |
132 | 133 |
$this->changeAccessContentTypeKeyword('update'); |
133 | 134 |
|
134 |
// Logout admin and try to edit the node anonymously |
|
135 |
// access must be denied again
|
|
135 |
// Logout admin and try to edit the node anonymously.
|
|
136 |
// Access must be denied again.
|
|
136 | 137 |
$this->drupalLogout(); |
137 |
$this->drupalGet('node/'. $this->node1->nid .'/edit');
|
|
138 |
$this->drupalGet('node/' . $this->node1->nid . '/edit');
|
|
138 | 139 |
$this->assertText(t('Access denied'), 'edit access denied for anonymous'); |
139 | 140 |
|
140 |
// Login test user, edit node, access must be granted |
|
141 |
// Login test user, edit node, access must be granted.
|
|
141 | 142 |
$this->drupalLogin($this->test_user); |
142 |
$this->drupalGet('node/'. $this->node1->nid .'/edit');
|
|
143 |
$this->drupalGet('node/' . $this->node1->nid . '/edit');
|
|
143 | 144 |
$this->assertNoText(t('Access denied'), 'node1 is editable'); |
144 | 145 |
|
145 |
// Login admin and enable per node access |
|
146 |
// Login admin and enable per node access.
|
|
146 | 147 |
$this->drupalLogin($this->admin_user); |
147 | 148 |
$this->changeAccessPerNode(); |
148 | 149 |
|
149 |
// Restrict access for this content type for the test user |
|
150 |
// Restrict access for this content type for the test user.
|
|
150 | 151 |
$this->changeAccessContentTypeKeyword('update', FALSE); |
151 | 152 |
|
152 |
// Allow acces for node1 only |
|
153 |
// Allow acces for node1 only.
|
|
153 | 154 |
$this->changeAccessNodeKeyword($this->node1, 'update'); |
154 | 155 |
|
155 |
// Logout admin and try to edit both nodes anonymously |
|
156 |
// Logout admin and try to edit both nodes anonymously.
|
|
156 | 157 |
$this->drupalLogout(); |
157 |
$this->drupalGet('node/'. $this->node1->nid .'/edit');
|
|
158 |
$this->drupalGet('node/' . $this->node1->nid . '/edit');
|
|
158 | 159 |
$this->assertText(t('Access denied'), 'node1 is not editable'); |
159 |
$this->drupalGet('node/'. $this->node2->nid .'/edit');
|
|
160 |
$this->drupalGet('node/' . $this->node2->nid . '/edit');
|
|
160 | 161 |
$this->assertText(t('Access denied'), 'node2 is not editable'); |
161 | 162 |
|
162 |
// Login test user, edit node1, access must be granted |
|
163 |
// Login test user, edit node1, access must be granted.
|
|
163 | 164 |
$this->drupalLogin($this->test_user); |
164 |
$this->drupalGet('node/'. $this->node1->nid .'/edit');
|
|
165 |
$this->drupalGet('node/' . $this->node1->nid . '/edit');
|
|
165 | 166 |
$this->assertNoText(t('Access denied'), 'node1 is editable'); |
166 | 167 |
|
167 |
// Edit node2, access must be denied |
|
168 |
$this->drupalGet('node/'. $this->node2->nid .'/edit');
|
|
168 |
// Edit node2, access must be denied.
|
|
169 |
$this->drupalGet('node/' . $this->node2->nid . '/edit');
|
|
169 | 170 |
$this->assertText(t('Access denied'), 'node2 is not editable'); |
170 | 171 |
|
171 |
// Login admin, swap permissions between node1 and node2 |
|
172 |
// Login admin, swap permissions between node1 and node2.
|
|
172 | 173 |
$this->drupalLogin($this->admin_user); |
173 | 174 |
|
174 |
// Grant edit access to node2 |
|
175 |
// Grant edit access to node2.
|
|
175 | 176 |
$this->changeAccessNodeKeyword($this->node2, 'update'); |
176 |
// Restrict edit acces to node1 |
|
177 |
// Restrict edit acces to node1.
|
|
177 | 178 |
$this->changeAccessNodeKeyword($this->node1, 'update', FALSE); |
178 | 179 |
|
179 |
// Logout admin and try to edit both nodes anonymously |
|
180 |
// Logout admin and try to edit both nodes anonymously.
|
|
180 | 181 |
$this->drupalLogout(); |
181 |
$this->drupalGet('node/'. $this->node1->nid .'/edit');
|
|
182 |
$this->drupalGet('node/' . $this->node1->nid . '/edit');
|
|
182 | 183 |
$this->assertText(t('Access denied'), 'node1 is not editable'); |
183 |
$this->drupalGet('node/'. $this->node2->nid .'/edit');
|
|
184 |
$this->drupalGet('node/' . $this->node2->nid . '/edit');
|
|
184 | 185 |
$this->assertText(t('Access denied'), 'node2 is not editable'); |
185 | 186 |
|
186 |
// Login test user, edit node1, access must be denied |
|
187 |
// Login test user, edit node1, access must be denied.
|
|
187 | 188 |
$this->drupalLogin($this->test_user); |
188 |
$this->drupalGet('node/'. $this->node1->nid .'/edit');
|
|
189 |
$this->drupalGet('node/' . $this->node1->nid . '/edit');
|
|
189 | 190 |
$this->assertText(t('Access denied'), 'node1 is not editable'); |
190 | 191 |
|
191 |
// Edit node2, access must be granted |
|
192 |
$this->drupalGet('node/'. $this->node2->nid .'/edit');
|
|
192 |
// Edit node2, access must be granted.
|
|
193 |
$this->drupalGet('node/' . $this->node2->nid . '/edit');
|
|
193 | 194 |
$this->assertNoText(t('Access denied'), 'node2 is editable'); |
194 | 195 |
} |
195 | 196 |
|
196 | 197 |
/** |
197 |
* Test for deleting nodes |
|
198 |
* Test for deleting nodes.
|
|
198 | 199 |
*/ |
199 | 200 |
function testDeleteAccess() { |
200 |
// Logout admin and try to delete the node anonymously |
|
201 |
// Logout admin and try to delete the node anonymously.
|
|
201 | 202 |
$this->drupalLogout(); |
202 |
$this->drupalGet('node/'. $this->node1->nid .'/delete');
|
|
203 |
$this->drupalGet('node/' . $this->node1->nid . '/delete');
|
|
203 | 204 |
$this->assertText(t('Access denied'), 'delete access denied for anonymous'); |
204 | 205 |
|
205 |
// Login test user, delete node, access must be denied |
|
206 |
// Login test user, delete node, access must be denied.
|
|
206 | 207 |
$this->drupalLogin($this->test_user); |
207 |
$this->drupalGet('node/'. $this->node1->nid .'/delete');
|
|
208 |
$this->drupalGet('node/' . $this->node1->nid . '/delete');
|
|
208 | 209 |
$this->assertText(t('Access denied'), 'delete access denied for test user'); |
209 | 210 |
|
210 |
// Login admin and grant access for deleting to the test user |
|
211 |
// Login admin and grant access for deleting to the test user.
|
|
211 | 212 |
$this->drupalLogin($this->admin_user); |
212 | 213 |
|
213 | 214 |
$this->changeAccessContentTypeKeyword('delete'); |
214 | 215 |
|
215 |
// Logout admin and try to edit the node anonymously |
|
216 |
// access must be denied again
|
|
216 |
// Logout admin and try to edit the node anonymously.
|
|
217 |
// Access must be denied again.
|
|
217 | 218 |
$this->drupalLogout(); |
218 |
$this->drupalGet('node/'. $this->node1->nid .'/delete');
|
|
219 |
$this->drupalGet('node/' . $this->node1->nid . '/delete');
|
|
219 | 220 |
$this->assertText(t('Access denied'), 'delete access denied for anonymous'); |
220 | 221 |
|
221 |
// Login test user, delete node, access must be granted |
|
222 |
// Login test user, delete node, access must be granted.
|
|
222 | 223 |
$this->drupalLogin($this->test_user); |
223 |
$this->drupalPost('node/'. $this->node1->nid .'/delete', array(), 'Delete');
|
|
224 |
$this->drupalPost('node/' . $this->node1->nid . '/delete', array(), 'Delete');
|
|
224 | 225 |
$this->assertRaw(t('%node has been deleted', array('%node' => $this->node1->title)), 'Test node was deleted successfully by test user'); |
225 | 226 |
|
226 |
// Login admin and recreate test node1 |
|
227 |
// Login admin and recreate test node1.
|
|
227 | 228 |
$this->drupalLogin($this->admin_user); |
228 | 229 |
$this->node1 = $this->drupalCreateNode(array('type' => $this->content_type->type)); |
229 | 230 |
|
230 |
// Enable per node access |
|
231 |
// Enable per node access.
|
|
231 | 232 |
$this->changeAccessPerNode(); |
232 | 233 |
|
233 |
// Restrict access for this content type for the test user |
|
234 |
// Restrict access for this content type for the test user.
|
|
234 | 235 |
$this->changeAccessContentTypeKeyword('delete', FALSE); |
235 | 236 |
|
236 |
// Allow acces for node1 only |
|
237 |
// Allow acces for node1 only.
|
|
237 | 238 |
$this->changeAccessNodeKeyword($this->node1, 'delete'); |
238 | 239 |
|
239 |
// Logout admin and try to delete both nodes anonymously |
|
240 |
// Logout admin and try to delete both nodes anonymously.
|
|
240 | 241 |
$this->drupalLogout(); |
241 |
$this->drupalGet('node/'. $this->node1->nid .'/delete');
|
|
242 |
$this->drupalGet('node/' . $this->node1->nid . '/delete');
|
|
242 | 243 |
$this->assertText(t('Access denied'), 'node1 is not deletable'); |
243 |
$this->drupalGet('node/'. $this->node2->nid .'/delete');
|
|
244 |
$this->drupalGet('node/' . $this->node2->nid . '/delete');
|
|
244 | 245 |
$this->assertText(t('Access denied'), 'node2 is not deletable'); |
245 | 246 |
|
246 |
// Login test user, delete node1, access must be granted |
|
247 |
// Login test user, delete node1, access must be granted.
|
|
247 | 248 |
$this->drupalLogin($this->test_user); |
248 |
$this->drupalGet('node/'. $this->node1->nid .'/delete');
|
|
249 |
$this->drupalGet('node/' . $this->node1->nid . '/delete');
|
|
249 | 250 |
$this->assertNoText(t('Access denied'), 'node1 is deletable'); |
250 | 251 |
|
251 |
// Delete node2, access must be denied |
|
252 |
$this->drupalGet('node/'. $this->node2->nid .'/delete');
|
|
252 |
// Delete node2, access must be denied.
|
|
253 |
$this->drupalGet('node/' . $this->node2->nid . '/delete');
|
|
253 | 254 |
$this->assertText(t('Access denied'), 'node2 is not deletable'); |
254 | 255 |
|
255 |
// Login admin, swap permissions between node1 and node2 |
|
256 |
// Login admin, swap permissions between node1 and node2.
|
|
256 | 257 |
$this->drupalLogin($this->admin_user); |
257 | 258 |
|
258 |
// Grant delete access to node2 |
|
259 |
// Grant delete access to node2.
|
|
259 | 260 |
$this->changeAccessNodeKeyword($this->node2, 'delete'); |
260 |
// Restrict delete acces to node1 |
|
261 |
// Restrict delete acces to node1.
|
|
261 | 262 |
$this->changeAccessNodeKeyword($this->node1, 'delete', FALSE); |
262 | 263 |
|
263 |
// Logout admin and try to delete both nodes anonymously |
|
264 |
// Logout admin and try to delete both nodes anonymously.
|
|
264 | 265 |
$this->drupalLogout(); |
265 |
$this->drupalGet('node/'. $this->node1->nid .'/delete');
|
|
266 |
$this->drupalGet('node/' . $this->node1->nid . '/delete');
|
|
266 | 267 |
$this->assertText(t('Access denied'), 'node1 is not deletable'); |
267 |
$this->drupalGet('node/'. $this->node2->nid .'/delete');
|
|
268 |
$this->drupalGet('node/' . $this->node2->nid . '/delete');
|
|
268 | 269 |
$this->assertText(t('Access denied'), 'node2 is not deletable'); |
269 | 270 |
|
270 |
// Login test user, delete node1, access must be denied |
|
271 |
// Login test user, delete node1, access must be denied.
|
|
271 | 272 |
$this->drupalLogin($this->test_user); |
272 |
$this->drupalGet('node/'. $this->node1->nid .'/delete');
|
|
273 |
$this->drupalGet('node/' . $this->node1->nid . '/delete');
|
|
273 | 274 |
$this->assertText(t('Access denied'), 'node1 is not deletable'); |
274 | 275 |
|
275 |
// Delete node2, access must be granted |
|
276 |
$this->drupalGet('node/'. $this->node2->nid .'/delete');
|
|
276 |
// Delete node2, access must be granted.
|
|
277 |
$this->drupalGet('node/' . $this->node2->nid . '/delete');
|
|
277 | 278 |
$this->assertNoText(t('Access denied'), 'node2 is deletable'); |
278 | 279 |
} |
279 | 280 |
|
280 | 281 |
/** |
281 |
* Test own view access |
|
282 |
* Test own view access.
|
|
282 | 283 |
*/ |
283 | 284 |
function testOwnViewAccess() { |
284 |
// Setup 2 test users |
|
285 |
// Setup 2 test users.
|
|
285 | 286 |
$test_user1 = $this->test_user; |
286 |
$test_user2 = $this->drupalCreateUser(); |
|
287 |
$test_user2 = $this->drupalCreateUser(array('access content'));
|
|
287 | 288 |
|
288 |
// Change ownership of test nodes to test users |
|
289 |
// Change ownership of test nodes to test users.
|
|
289 | 290 |
$this->node1->uid = $test_user1->uid; |
290 | 291 |
node_save($this->node1); |
291 | 292 |
$this->node2->uid = $test_user2->uid; |
292 | 293 |
node_save($this->node2); |
293 | 294 |
|
294 |
// Remove all view permissions for this content type |
|
295 |
// Remove all view permissions for this content type.
|
|
295 | 296 |
$access_permissions = array( |
296 | 297 |
'view[1]' => FALSE, |
297 | 298 |
'view[2]' => FALSE, |
... | ... | |
300 | 301 |
); |
301 | 302 |
$this->changeAccessContentType($access_permissions); |
302 | 303 |
|
303 |
// Allow view own content for test user 1 and 2 roles |
|
304 |
// Allow view own content for test user 1 and 2 roles.
|
|
304 | 305 |
$this->changeAccessContentTypeKeyword('view_own', TRUE, $test_user1); |
305 | 306 |
$this->changeAccessContentTypeKeyword('view_own', TRUE, $test_user2); |
306 | 307 |
|
307 |
// Logout admin and try to access both nodes anonymously |
|
308 |
// Logout admin and try to access both nodes anonymously.
|
|
308 | 309 |
$this->drupalLogout(); |
309 |
$this->drupalGet('node/'. $this->node1->nid); |
|
310 |
$this->drupalGet('node/' . $this->node1->nid);
|
|
310 | 311 |
$this->assertText(t('Access denied'), 'node1 is not viewable'); |
311 |
$this->drupalGet('node/'. $this->node2->nid); |
|
312 |
$this->drupalGet('node/' . $this->node2->nid);
|
|
312 | 313 |
$this->assertText(t('Access denied'), 'node2 is not viewable'); |
313 | 314 |
|
314 |
// Login test user 1, view node1, access must be granted |
|
315 |
// Login test user 1, view node1, access must be granted.
|
|
315 | 316 |
$this->drupalLogin($test_user1); |
316 |
$this->drupalGet('node/'. $this->node1->nid); |
|
317 |
$this->drupalGet('node/' . $this->node1->nid);
|
|
317 | 318 |
$this->assertNoText(t('Access denied'), 'node1 is viewable'); |
318 | 319 |
|
319 |
// View node2, access must be denied |
|
320 |
$this->drupalGet('node/'. $this->node2->nid); |
|
320 |
// View node2, access must be denied.
|
|
321 |
$this->drupalGet('node/' . $this->node2->nid);
|
|
321 | 322 |
$this->assertText(t('Access denied'), 'node2 is not viewable'); |
322 | 323 |
|
323 |
// Login test user 2, view node1, access must be denied |
|
324 |
// Login test user 2, view node1, access must be denied.
|
|
324 | 325 |
$this->drupalLogin($test_user2); |
325 |
$this->drupalGet('node/'. $this->node1->nid); |
|
326 |
$this->drupalGet('node/' . $this->node1->nid);
|
|
326 | 327 |
$this->assertText(t('Access denied'), 'node1 is not viewable'); |
327 | 328 |
|
328 |
// View node2, access must be granted |
|
329 |
$this->drupalGet('node/'. $this->node2->nid); |
|
329 |
// View node2, access must be granted.
|
|
330 |
$this->drupalGet('node/' . $this->node2->nid);
|
|
330 | 331 |
$this->assertNoText(t('Access denied'), 'node2 is viewable'); |
331 | 332 |
} |
332 |
} |
|
333 |
} |
drupal7/sites/all/modules/content_access/tests/content_access_test_help.php | ||
---|---|---|
34 | 34 |
} |
35 | 35 |
} |
36 | 36 |
|
37 |
// Create test user with seperate role
|
|
38 |
$this->test_user = $this->drupalCreateUser(); |
|
37 |
// Create test user with separate role.
|
|
38 |
$this->test_user = $this->drupalCreateUser(array('access content'));
|
|
39 | 39 |
|
40 |
// Get the value of the new role |
|
41 |
// Needed in D7 because it's by default create two roles for new users
|
|
42 |
// one role is Authenticated and the second is new default one
|
|
40 |
// Get the value of the new role.
|
|
41 |
// Needed in D7 because drupalCreateUser() creates two roles for new users:
|
|
42 |
// one role is Authenticated and the second has the given permissions.
|
|
43 | 43 |
// @see drupalCreateUser() |
44 |
foreach ($this->test_user->roles as $rid => $role) { |
|
45 |
if (!in_array($rid, array(DRUPAL_AUTHENTICATED_RID))) { |
|
46 |
$this->rid = $rid; |
|
47 |
break; |
|
48 |
} |
|
49 |
} |
|
44 |
$roles = $this->test_user->roles; |
|
45 |
unset($roles[DRUPAL_AUTHENTICATED_RID]); |
|
46 |
$this->rid = key($roles); |
|
50 | 47 |
|
51 | 48 |
// Create admin user |
52 |
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'grant content access', 'grant own content access', 'administer nodes', 'access administration pages')); |
|
49 |
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'grant content access', 'grant own content access', 'bypass node access', 'administer nodes', 'access administration pages'));
|
|
53 | 50 |
$this->drupalLogin($this->admin_user); |
54 | 51 |
|
55 | 52 |
// Rebuild content access permissions |
... | ... | |
122 | 119 |
$this->drupalPost('node/'. $node->nid .'/access', $access_settings, t('Submit')); |
123 | 120 |
$this->assertText(t('Your changes have been saved.'), 'access rules of node were updated successfully'); |
124 | 121 |
} |
125 |
} |
|
122 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules