[pLog-svn] r4150 - in plog/trunk: class/action/admin class/controller locale templates/admin

oscar at devel.lifetype.net oscar at devel.lifetype.net
Sat Oct 21 23:31:27 GMT 2006


Author: oscar
Date: 2006-10-21 23:31:26 +0000 (Sat, 21 Oct 2006)
New Revision: 4150

Added:
   plog/trunk/class/action/admin/admineditbloguseraction.class.php
   plog/trunk/class/action/admin/adminupdatebloguseraction.class.php
   plog/trunk/templates/admin/editbloguser.template
Modified:
   plog/trunk/class/controller/admincontrollermap.properties.php
   plog/trunk/locale/locale_en_UK.php
   plog/trunk/templates/admin/blogusers.template
Log:
added support for editing the permissions of a user in a blog


Added: plog/trunk/class/action/admin/admineditbloguseraction.class.php
===================================================================
--- plog/trunk/class/action/admin/admineditbloguseraction.class.php	2006-10-21 22:56:19 UTC (rev 4149)
+++ plog/trunk/class/action/admin/admineditbloguseraction.class.php	2006-10-21 23:31:26 UTC (rev 4150)
@@ -0,0 +1,61 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );	
+	lt_include( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/view/admin/adminbloguserslistview.class.php" );	
+	lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );	
+	lt_include( PLOG_CLASS_PATH."class/dao/permissions.class.php" );		
+
+    /**
+     * \ingroup Action
+     * @private
+     */
+    class AdminEditBlogUserAction extends AdminAction 
+	{	
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function AdminEditBlogUserAction( $actionInfo, $request )
+        {
+        	$this->AdminAction( $actionInfo, $request );
+			
+			// register one validator
+			$this->registerFieldValidator( "userId", new IntegerValidator());
+			// and the view we should show in case there is a validation error
+			$errorView = new AdminBlogUsersListView( $this->_blogInfo );
+			$errorView->setErrorMessage( $this->_locale->tr("error_invalid_user_id" ));			
+			$this->setValidationErrorView( $errorView );
+			
+			$this->requirePermission( "update_blog_user");
+        }
+
+        /**
+         * Carries out the specified action
+         */
+        function perform()
+        {
+			// fetch the data, we already know it's valid and that we can trust it!
+			$userId = $this->_request->getValue( "userId" );
+			
+			// load the user
+			$users = new Users();
+			$userInfo = $users->getUserInfoFromId( $userId );
+			if( !$userInfo ) {
+				$errorView = new AdminBlogUsersListView( $this->_blogInfo );
+				$errorView->setErrorMessage( $this->_locale->tr("error_invalid_user_id" ));
+				$this->setCommonData();
+				return( false );
+			}
+
+			// pass all the information to the view
+			$this->_view = new AdminTemplatedView( $this->_blogInfo, "editbloguser" );
+			$this->_view->setValue( "edituser", $userInfo );			
+	        $perms = new Permissions();
+			$this->_view->setValue( "perms", $perms->getAllPermissions());			
+			$this->setCommonData();
+			
+			return( true );
+        }
+    }
+?>
\ No newline at end of file

Added: plog/trunk/class/action/admin/adminupdatebloguseraction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminupdatebloguseraction.class.php	2006-10-21 22:56:19 UTC (rev 4149)
+++ plog/trunk/class/action/admin/adminupdatebloguseraction.class.php	2006-10-21 23:31:26 UTC (rev 4150)
@@ -0,0 +1,72 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );	
+	lt_include( PLOG_CLASS_PATH."class/view/admin/adminbloguserslistview.class.php" );	
+	lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );	
+	lt_include( PLOG_CLASS_PATH."class/dao/permissions.class.php" );		
+
+    /**
+     * \ingroup Action
+     * @private
+     */
+    class AdminUpdateBlogUserAction extends AdminAction 
+	{	
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function AdminUpdateBlogUserAction( $actionInfo, $request )
+        {
+        	$this->AdminAction( $actionInfo, $request );
+			
+			// register one validator
+			$this->registerFieldValidator( "userId", new IntegerValidator());
+			// and the view we should show in case there is a validation error
+			$errorView = new AdminBlogUsersListView( $this->_blogInfo );
+			$errorView->setErrorMessage( $this->_locale->tr("error_invalid_user_id" ));			
+			$this->setValidationErrorView( $errorView );
+			
+			$this->requirePermission( "update_blog_user");
+        }
+
+        /**
+         * Carries out the specified action
+         */
+        function perform()
+        {
+			// fetch the data, we already know it's valid and that we can trust it!
+			$userId = $this->_request->getValue( "userId" );
+			$this->_perms = $this->_request->getValue( "perm" );			
+			
+			// load the user
+			$users = new Users();
+			$userInfo = $users->getUserInfoFromId( $userId );
+			if( !$userInfo ) {
+				$errorView = new AdminBlogUsersListView( $this->_blogInfo );
+				$errorView->setErrorMessage( $this->_locale->tr("error_invalid_user_id" ));
+				$this->setCommonData();
+				return( false );
+			}
+			
+			$this->notifyEvent( EVENT_PRE_USER_UPDATE, Array( "user" => &$user ));			
+			
+			// first revoke all permissions
+			$userPerms = new UserPermissions();
+			$userPerms->revokeBlogPermissions( $this->_blogInfo->getId());
+			
+			// and then assign the new ones
+			foreach( $this->_perms as $val => $permId ) {
+	            $perm = new UserPermission( $userInfo->getId(), $this->_blogInfo->getId(), $permId );
+	            $res = $userPerms->grantPermission( $perm );
+			}
+			
+			$this->notifyEvent( EVENT_POST_USER_UPDATE, Array( "user" => &$user ));			
+			
+            $this->_view = new AdminBlogUsersListView( $this->_blogInfo );
+            $this->_view->setSuccessMessage( $this->_locale->pr("user_permissions_updated_ok", $userInfo->getUsername()));
+            $this->setCommonData();			
+			
+			return( true );
+        }
+    }
+?>
\ No newline at end of file

Modified: plog/trunk/class/controller/admincontrollermap.properties.php
===================================================================
--- plog/trunk/class/controller/admincontrollermap.properties.php	2006-10-21 22:56:19 UTC (rev 4149)
+++ plog/trunk/class/controller/admincontrollermap.properties.php	2006-10-21 23:31:26 UTC (rev 4150)
@@ -305,5 +305,9 @@
 	$actions["editPermission"] = "AdminEditPermissionAction";	
 	$actions["updatePermission"] = "AdminUpdatePermissionAction";		
 	$actions["newPermission"] = "AdminNewPermissionAction";	
-	$actions["addPermission"] = "AdminAddPermissionAction";		
+	$actions["addPermission"] = "AdminAddPermissionAction";
+	// edit blog user
+	$actions["editBlogUser"] = "AdminEditBlogUserAction";
+	// update blog user
+	$actions["updateBlogUser"] = "AdminUpdateBlogUserAction";	
 ?>
\ No newline at end of file

Modified: plog/trunk/locale/locale_en_UK.php
===================================================================
--- plog/trunk/locale/locale_en_UK.php	2006-10-21 22:56:19 UTC (rev 4149)
+++ plog/trunk/locale/locale_en_UK.php	2006-10-21 23:31:26 UTC (rev 4150)
@@ -1108,4 +1108,5 @@
 $messages['help_hard_recent_posts_max'] = 'Maximum upper limit for recent articles shown in blog pages. If users set a custom value over this limit, it will be ignored and the value specified here will be used [ Default = 25 ]';
 
 $messages['error_permission_required'] = 'You haven\'t got enough permissions to perform the requested action';
+$messages['user_permissions_updated_ok'] = 'User permissions updated successfully';
 ?>
\ No newline at end of file

Modified: plog/trunk/templates/admin/blogusers.template
===================================================================
--- plog/trunk/templates/admin/blogusers.template	2006-10-21 22:56:19 UTC (rev 4149)
+++ plog/trunk/templates/admin/blogusers.template	2006-10-21 23:31:26 UTC (rev 4150)
@@ -22,7 +22,7 @@
                             <input class="checkbox" type="checkbox" name="userIds[{$bloguser->getId()}]" id="checks_1" value="{$bloguser->getId()}" />
                         </td>
                         <td class="col_highlighted">
-                            {$bloguser->getUsername()}
+                            <a href="?op=editBlogUser&amp;userId={$bloguser->getId()}">{$bloguser->getUsername()}</a>
                         </td>
                         <td>
                             {$bloguser->getFullName()}
@@ -34,7 +34,7 @@
                         </td>
                         <td>
                             <div class="list_action_button">
-                            <!-- <a href="#"><img src="imgs/admin/icon_edit-16.png" alt="{$locale->tr("editUser")}" /></a> -->
+                            <a href="?op=editBlogUser&amp;userId={$bloguser->getId()}"><img src="imgs/admin/icon_edit-16.png" alt="{$locale->tr("edit_blog_user")}" /></a>
                             <a href="?op=deleteBlogUserPermissions&amp;userId={$bloguser->getId()}"><img src="imgs/admin/icon_delete-16.png" alt="{$locale->tr("revoke_permissions")}" /></a>
                             </div>
                         </td>

Added: plog/trunk/templates/admin/editbloguser.template
===================================================================
--- plog/trunk/templates/admin/editbloguser.template	2006-10-21 22:56:19 UTC (rev 4149)
+++ plog/trunk/templates/admin/editbloguser.template	2006-10-21 23:31:26 UTC (rev 4150)
@@ -0,0 +1,38 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=newBlogUser title=$locale->tr("editBlogUser")}
+
+ <form name="editBlogUser" action="admin.php" method="post">
+   <fieldset class="inputField">
+  
+     <legend>{$locale->tr("newBlogUser")}</legend>
+     {include file="$admintemplatepath/formvalidate.template" message=$locale->tr("error_updating_user")}
+
+     <div class="field">
+      <label for="newBlogUserName">{$locale->tr("username")}</label>
+      <input type="text" disabled="disabled" id="newBlogUsername" name="newBlogUserName" value="{$edituser->getUsername()}" />
+      {include file="$admintemplatepath/validate.template" field=newBlogUserName message=$locale->tr("error_invalid_user")}
+     </div>
+
+     <div class="field">
+      <label for="perm">{$locale->tr("permissions")}</label>
+      <span class="required"></span>
+      <div class="formHelp">{$locale->tr("new_blog_permissions_help")}</div>     
+     	{foreach from=$perms item=perm}
+     	 {if !$perm->isAdminOnlyPermission()}
+     	 <input type="checkbox" class="checkbox" name="perm[]" value="{$perm->getId()}" {if $edituser->hasPermissionByName($perm->getName(),$blog->getId())}checked="checked"{/if}/>
+     	 {$locale->tr($perm->getDescription())}<br/>
+     	 {/if}
+     	{/foreach}
+     </div>
+
+  </fieldset>
+  <div class="buttons"> 
+	<input type="hidden" name="userId" value="{$edituser->getId()}" />
+    <input type="reset" value="{$locale->tr("reset")}" name="reset" />
+    <input type="submit" name="Add this user" value="{$locale->tr("update")}"/>
+    <input type="hidden" name="op" value="updateBlogUser"/>
+  </div> 
+ </form>
+
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}



More information about the pLog-svn mailing list