Commit a960d4d6 authored by Gábor Hojtsy's avatar Gábor Hojtsy

#120960 by blakehall, JirkaRybka, catch: improve usability of content editing permission names

parent abd2477d
......@@ -83,7 +83,7 @@ function book_update_6000() {
$replace = array(
'outline posts in books' => 'administer book outlines',
'create book pages' => 'create book content',
'edit book pages' => 'edit book content',
'edit book pages' => 'edit any book content',
'edit own book pages' => 'edit own book content',
'see printer-friendly version' => 'access printer-friendly version',
);
......
......@@ -1048,9 +1048,9 @@ function node_perm() {
$name = check_plain($type->type);
$perms[] = 'create '. $name .' content';
$perms[] = 'delete own '. $name .' content';
$perms[] = 'delete '. $name .' content';
$perms[] = 'delete any '. $name .' content';
$perms[] = 'edit own '. $name .' content';
$perms[] = 'edit '. $name .' content';
$perms[] = 'edit any '. $name .' content';
}
}
......@@ -2223,13 +2223,13 @@ function node_content_access($op, $node, $account) {
}
if ($op == 'update') {
if (user_access('edit '. $type .' content', $account) || (user_access('edit own '. $type .' content', $account) && ($user->uid == $node->uid))) {
if (user_access('edit any '. $type .' content', $account) || (user_access('edit own '. $type .' content', $account) && ($user->uid == $node->uid))) {
return TRUE;
}
}
if ($op == 'delete') {
if (user_access('delete '. $type .' content') || (user_access('delete own '. $type .' content') && ($user->uid == $node->uid))) {
if (user_access('delete any '. $type .' content') || (user_access('delete own '. $type .' content') && ($user->uid == $node->uid))) {
return TRUE;
}
}
......
......@@ -54,7 +54,7 @@ function poll_theme() {
* Implementation of hook_perm().
*/
function poll_perm() {
return array('create polls', 'edit polls', 'edit own poll', 'vote on polls', 'cancel own vote', 'inspect all votes');
return array('create poll content', 'edit any poll content', 'edit own poll content', 'vote on polls', 'cancel own vote', 'inspect all votes');
}
/**
......@@ -65,9 +65,9 @@ function poll_access($op, $node, $account) {
switch ($op) {
case 'create':
return user_access('create polls', $account);
return user_access('create poll content', $account);
case 'update':
return user_access('edit polls') || (user_access('edit own poll') && ($node->uid == $user->uid));
return user_access('edit any poll content') || (user_access('edit own poll content') && ($node->uid == $user->uid));
}
}
......@@ -184,7 +184,7 @@ function poll_node_info() {
function poll_form(&$node, $form_state) {
global $user;
$admin = user_access('administer nodes') || user_access('edit polls') || (user_access('edit own polls') && $user->uid == $node->nid);
$admin = user_access('administer nodes') || user_access('edit any poll content') || (user_access('edit own poll content') && $user->uid == $node->nid);
$type = node_get_types('type', $node);
$form = array(
......
......@@ -2716,6 +2716,25 @@ function system_update_6038() {
return $ret;
}
/**
* Rename permissions "edit foo content" to "edit any foo content".
* Also update poll module permission "create polls" to "create
* poll content".
*/
function system_update_6039() {
$ret = array();
$result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid");
while ($role = db_fetch_object($result)) {
$renamed_permission = preg_replace('/(?<=^|,\ )edit\ ([a-zA-Z0-9_\-]+)\ content(?=,|$)/', 'edit any $1 content', $role->perm);
$renamed_permission = preg_replace('/(?<=^|,\ )create\ polls(?=,|$)/', 'create poll content', $renamed_permission);
if ($renamed_permission != $role->perm) {
$ret[] = update_sql("UPDATE {permission} SET perm = '$renamed_permission' WHERE rid = $role->rid");
}
}
return $ret;
}
/**
* @} End of "defgroup updates-5.x-to-6.x"
* The next series of updates should start at 7000.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment