Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfwenzel@mozilla.com <fwenzel@mozilla.com@4eb1ac78-321c-0410-a911-ec516a8615a5>2009-06-22 21:24:34 (GMT)
committer fwenzel@mozilla.com <fwenzel@mozilla.com@4eb1ac78-321c-0410-a911-ec516a8615a5>2009-06-22 21:24:34 (GMT)
commit1e378b475447580035971b1ef37cee4df6e77ca5 (patch)
treeea5c35f8d44654b3827cccb17b1a741ffd40a044
parentce4cfe75293a0fc65f551e2a420e705506fc2fab (diff)
Remove collections owner role (bug 496419, r=clouserw)
git-svn-id: http://svn.mozilla.org/addons/trunk@28256 4eb1ac78-321c-0410-a911-ec516a8615a5
-rw-r--r--site/app/config/constants.php1
-rw-r--r--site/app/controllers/collections_controller.php12
-rw-r--r--site/app/controllers/sharing_api_controller.php14
-rw-r--r--site/app/models/collection.php4
-rw-r--r--site/app/models/user.php20
-rw-r--r--site/app/tests/controllers/sharing_api_controller.test.php4
-rw-r--r--site/app/views/collections/edit.thtml2
7 files changed, 24 insertions, 33 deletions
diff --git a/site/app/config/constants.php b/site/app/config/constants.php
index 705946c..444cc58 100644
--- a/site/app/config/constants.php
+++ b/site/app/config/constants.php
@@ -209,7 +209,6 @@ define('AUTHOR_ROLE_NONE', 0);
/**
* Collection Author Roles
*/
-define('COLLECTION_ROLE_OWNER', 2);
define('COLLECTION_ROLE_ADMIN', 1);
define('COLLECTION_ROLE_PUBLISHER', 0);
diff --git a/site/app/controllers/collections_controller.php b/site/app/controllers/collections_controller.php
index 476914e..3ea4688 100644
--- a/site/app/controllers/collections_controller.php
+++ b/site/app/controllers/collections_controller.php
@@ -240,7 +240,7 @@ class CollectionsController extends AppController
$collectionid = $this->Collection->id; // new collection id
$_coll = $this->Collection->findById($collectionid, array('Collection.uuid'));
- $this->Collection->addUser($this->Collection->id, $user['id'], COLLECTION_ROLE_OWNER);
+ $this->Collection->addUser($this->Collection->id, $user['id'], COLLECTION_ROLE_ADMIN);
if (!empty($this->params['form']['addons'])) {
// add-ons preselected
@@ -506,7 +506,7 @@ class CollectionsController extends AppController
if (!empty($this->data)) {
// Delete collection?
if (isset($this->data['action']) && $this->data['action'] == 'delete-coll') {
- if (!$rights['atleast_owner']) {
+ if (!$rights['atleast_manager']) {
$this->flash(___('error_access_denied'), '/', 3);
return;
}
@@ -736,8 +736,7 @@ class CollectionsController extends AppController
* get user rights for a specific collection
* @param array $user array from user model
* @param int $collection_id
- * @return array of booleans ('writable', 'isadmin', 'atleast_manager',
- * 'atleast_owner', 'role')
+ * @return array of booleans ('writable', 'isadmin', 'atleast_manager', 'role')
* @access private
*/
function _getUserRights($user, $collection_id) {
@@ -745,20 +744,17 @@ class CollectionsController extends AppController
$isadmin = $this->SimpleAcl->actionAllowed('Admin', 'EditAnyCollection', $user);
$role = $this->Collection->getUserRole($collection_id, $user['id']);
$writable = ($isadmin || $can_write);
- $atleast_manager = ($isadmin || in_array($role, array(COLLECTION_ROLE_ADMIN, COLLECTION_ROLE_OWNER)));
- $atleast_owner = ($isadmin || $role == COLLECTION_ROLE_OWNER);
+ $atleast_manager = ($isadmin || $role == COLLECTION_ROLE_ADMIN);
$this->publish('writable', $writable, false);
$this->publish('isadmin', $isadmin, false);
$this->publish('atleast_manager', $atleast_manager, false);
- $this->publish('atleast_owner', $atleast_owner, false);
$this->publish('role', $role, false);
return array(
'writable' => $writable,
'isadmin' => $isadmin,
'atleast_manager' => $atleast_manager,
- 'atleast_owner' => $atleast_owner,
'role' => $role
);
}
diff --git a/site/app/controllers/sharing_api_controller.php b/site/app/controllers/sharing_api_controller.php
index bab4e7c..1827959 100644
--- a/site/app/controllers/sharing_api_controller.php
+++ b/site/app/controllers/sharing_api_controller.php
@@ -305,9 +305,9 @@ class SharingApiController extends AppController
$new_collection = $this->Collection->findById($this->Collection->id);
- // Make the auth user owner of this new collection.
+ // Make the auth user a manager of this new collection.
$this->Collection->addUser(
- $new_collection['Collection']['id'], $this->auth_user['id'], COLLECTION_ROLE_OWNER
+ $new_collection['Collection']['id'], $this->auth_user['id'], COLLECTION_ROLE_ADMIN
);
$new_url = ( empty($_SERVER['HTTPS']) ? 'http' : 'https' ) .
@@ -922,15 +922,15 @@ class SharingApiController extends AppController
$row['Collection']['id'], $this->auth_user['id']
);
- // Try to look up the owner user for this collection and
+ // Try to look up one of the admin users for this collection and
// derive a name.
- $owner_users = $this->Collection->getUsers(
- $row['Collection']['id'], array( COLLECTION_ROLE_OWNER )
+ $admin_users = $this->Collection->getUsers(
+ $row['Collection']['id'], array( COLLECTION_ROLE_ADMIN )
);
- if (empty($owner_users)) {
+ if (empty($admin_users)) {
$creator_name = '';
} else {
- $u = $owner_users[0]['User'];
+ $u = $admin_users[0]['User'];
$creator_name = !empty($u['nickname']) ?
$u['nickname'] : "{$u['firstname']} {$u['lastname']}";
}
diff --git a/site/app/models/collection.php b/site/app/models/collection.php
index 59e0d13..fa751f6 100644
--- a/site/app/models/collection.php
+++ b/site/app/models/collection.php
@@ -330,7 +330,6 @@ class Collection extends AppModel
/**
* Remove all user rights from a collection, by role
- * Warning: do not do this with OWNER unless you know what you are doing.
*
* @param int $collection_id
* @param int $role user role to remove, for example COLLECTION_ROLE_ADMIN
@@ -450,14 +449,13 @@ class Collection extends AppModel
$role = $this->getUserRole($collection_id, $user_id);
if ($role === false) return false; // no access rights
return in_array($role, array(
- COLLECTION_ROLE_OWNER,
COLLECTION_ROLE_ADMIN,
COLLECTION_ROLE_PUBLISHER
));
}
/**
- * Determine a user's role for a collection (admin, owner, subscriber...).
+ * Determine a user's role for a collection (admin, subscriber...).
*
* @param int $collection_id
* @param int $user_id
diff --git a/site/app/models/user.php b/site/app/models/user.php
index 6a92c7b..b530245 100644
--- a/site/app/models/user.php
+++ b/site/app/models/user.php
@@ -60,7 +60,7 @@ class User extends AppModel
'foreignKey' => 'user_id',
'associationForeignKey' => 'collection_id'
),
- 'Collections' =>
+ 'Collections' =>
array('className' => 'Collection',
'joinTable' => 'collections_users',
'foreignKey' => 'user_id',
@@ -126,7 +126,7 @@ class User extends AppModel
$res = $this->execute("SELECT COUNT(*) as c FROM addons_users AS au WHERE au.user_id = '{$id}';");
return $res[0][0]['c'];
}
-
+
/**
* Anonymize a user account.
* This is the user-facing "delete account" feature, which does not delete
@@ -149,7 +149,7 @@ class User extends AppModel
));
return $this->save($data, false, array_keys($data['User']));
}
-
+
/**
* Enforce one of the name fields not to be empty
*/
@@ -164,7 +164,7 @@ class User extends AppModel
$this->invalidate('lastname');
$this->invalidate('nickname');
}
-
+
return parent::beforeValidate();
}
@@ -244,7 +244,7 @@ class User extends AppModel
"User.resetcode_expires > NOW()"));
return $user && $code == $user['User']['resetcode'];
}
-
+
/**
* Get subscriptions
*
@@ -255,7 +255,7 @@ class User extends AppModel
// Just bind to the collection subscriptions relation.
$this->bindModel(array(
'hasAndBelongsToMany' => array(
- 'CollectionSubscriptions' =>
+ 'CollectionSubscriptions' =>
$this->hasAndBelongsToMany_full['CollectionSubscriptions']
)
));
@@ -271,10 +271,10 @@ class User extends AppModel
$subscriptions = $this->Collection->findAll($criteria);
return $subscriptions;
}
-
+
/**
* Get IDs of collections this user has write access to
- *
+ *
* @param int $userId user id
* @param int $app (optional) only show collections with this app ID, defaults to all
* @param array $filterAddons (optional) list of add-ons to exclude:
@@ -304,8 +304,8 @@ class User extends AppModel
."INNER JOIN collections AS c ON (cu.collection_id = c.id) "
.$_join
."WHERE cu.user_id = {$userId} "
- ."AND cu.role IN (".implode(',', array(COLLECTION_ROLE_OWNER,
- COLLECTION_ROLE_ADMIN, COLLECTION_ROLE_PUBLISHER))."){$_where}");
+ ."AND cu.role IN (".implode(',', array(COLLECTION_ROLE_ADMIN,
+ COLLECTION_ROLE_PUBLISHER))."){$_where}");
$collectionIds = array();
foreach($res as &$_coll) $collectionIds[] = $_coll['c']['id'];
diff --git a/site/app/tests/controllers/sharing_api_controller.test.php b/site/app/tests/controllers/sharing_api_controller.test.php
index d92fd02..05939a2 100644
--- a/site/app/tests/controllers/sharing_api_controller.test.php
+++ b/site/app/tests/controllers/sharing_api_controller.test.php
@@ -1263,7 +1263,7 @@ class SharingApiTest extends WebTestHelper {
$this->Collection->save($collection);
$new_id = $this->Collection->id;
$this->Collection->addUser(
- $new_id, $user_id, COLLECTION_ROLE_OWNER
+ $new_id, $user_id, COLLECTION_ROLE_ADMIN
);
}
return $test_collections;
@@ -1353,7 +1353,7 @@ class SharingApiTest extends WebTestHelper {
$this->Collection->save($collection);
$new_id = $this->Collection->id;
$this->Collection->addUser(
- $new_id, $user['User']['id'], COLLECTION_ROLE_OWNER
+ $new_id, $user['User']['id'], COLLECTION_ROLE_ADMIN
);
$collections[] = $this->Collection->findById($new_id);
}
diff --git a/site/app/views/collections/edit.thtml b/site/app/views/collections/edit.thtml
index 1ac769f..9d57243 100644
--- a/site/app/views/collections/edit.thtml
+++ b/site/app/views/collections/edit.thtml
@@ -290,7 +290,6 @@ JS;
</fieldset>
<?php endif; ?>
- <?php if ($atleast_owner): ?>
<fieldset>
<h4><?=___('collections_edit_formfield_deletecollection')?></h4>
<p><?=___('collections_edit_formfield_deletecollection_description')?></p>
@@ -300,7 +299,6 @@ JS;
<p><?=sprintf(___('collections_edit_confirm_deletecollection_description'), ___('collections_edit_submit'))?></p>
</div>
</fieldset>
- <?php endif; // at least owner ?>
</div>
<?php endif; // at least manager ?>