Permalink
Browse files

First phase of the patch for ticket #1273. This upgrades the core mod…

…ule to support the additional permissions of 'Edit All Photos', 'Edit My Photos', 'Add Albums' and 'Add Photos'. The values for the 'add_n' from the access_intent and access_cache tables are used to initialize the new corresponding add_albums_x an add_photos_x columns. The 'Add' permission is then removed.
  • Loading branch information...
1 parent 4060640 commit 28859a7e61de5631b0d2a9dbb8ace4799c0c02fd @talmdal talmdal committed Apr 28, 2011
Showing with 54 additions and 4 deletions.
  1. +30 −0 modules/gallery/helpers/access.php
  2. +23 −3 modules/gallery/helpers/gallery_installer.php
  3. +1 −1 modules/gallery/module.info
@@ -346,6 +346,36 @@ static function delete_permission($name) {
}
/**
+ * Copy permission values (used for core version 50 upgrade).
+ * It is a public method, but it is really internal hence the leading underscore in the name.
+ * Not part of the API.
+ *
+ * @param string $from_perm_name
+ * @param array $array of permission names to copy
+ * @return void
+ */
+ static function _copy_permissions($from_perm_name, $to_perm_names) {
+ self::_copy_permission_columns($from_perm_name, $to_perm_names, ORM::factory("access_intent")->find_all());
+
+ self::_copy_permission_columns($from_perm_name, $to_perm_names, ORM::factory("access_cache")->find_all());
+ }
+
+ private static function _copy_permission_columns($from_perm_name, $to_perm_names, $query) {
+ $groups = self::_get_all_groups();
+ foreach ($query as $row) {
+ foreach ($groups as $group) {
+ $from_column = "{$from_perm_name}_{$group->id}";
+
+ foreach ($to_perm_names as $to_perm_name) {
+ $to_column = "{$to_perm_name}_{$group->id}";
+ $row->$to_column = $row->$from_column;
+ }
+ $row->save();
+ }
+ }
+ }
+
+ /**
* Add the appropriate columns for a new group
*
* @param Group_Model $group
@@ -221,13 +221,21 @@ static function install() {
access::register_permission("view", "View");
access::register_permission("view_full", "View full size");
access::register_permission("edit", "Edit");
- access::register_permission("add", "Add");
+ access::register_permission("edit_all_photos", "Edit All Photos");
+ access::register_permission("edit_my_photos", "Edit My Photos");
+
+ access::register_permission("add_album", "Add Album");
+ access::register_permission("add_photo", "Add Photo");
// Mark for translation (must be the same strings as used above)
t("View full size");
t("View");
t("Edit");
- t("Add");
+ t("Edit All Photos");
+ t("Edit My Photos");
+
+ t("Add Album");
+ t("Add Photo");
// Hardcode the first item to sidestep ORM validation rules
$now = time();
@@ -313,7 +321,7 @@ static function install() {
module::set_var("gallery", "extra_binary_paths", "/usr/local/bin:/opt/local/bin:/opt/bin");
module::set_var("gallery", "timezone", null);
- module::set_version("gallery", 49);
+ module::set_version("gallery", 50);
}
static function upgrade($version) {
@@ -692,6 +700,18 @@ static function upgrade($version) {
module::set_var("gallery", "timezone", null);
module::set_version("gallery", $version = 49);
}
+
+ if ($version == 49) {
+ access::register_permission("edit_all", "Edit All Photos");
+ access::register_permission("edit_my_photos", "Edit My Photos");
+
+ access::register_permission("add_album", "Add Album");
+ access::register_permission("add_photo", "Add Photo");
+
+ access::_copy_permissions("add", array("add_album", "add_photo"));
+ access::delete_permission("add");
+ module::set_version("gallery", $version = 50);
+ }
}
static function uninstall() {
@@ -1,6 +1,6 @@
name = "Gallery 3"
description = "Gallery core application"
-version = 49
+version = 50
author_name = "Gallery Team"
author_url = "http://codex.gallery2.org/Gallery:Team"
info_url = "http://codex.gallery2.org/Gallery3:Modules:gallery"

0 comments on commit 28859a7

Please sign in to comment.