File modules/cms/action/object/ObjectAclformAction.class.php

Last commit: Wed Mar 9 13:28:52 2022 +0100	dankert	Refactoring: Checkbox values are always sent to the server. In the actions we must test the value with 'isTrue()'
1 <?php 2 namespace cms\action\object; 3 use cms\action\Action; 4 use cms\action\Method; 5 use cms\action\ObjectAction; 6 use cms\action\RequestParams; 7 use cms\model\Permission; 8 use cms\model\BaseObject; 9 use cms\model\Folder; 10 use cms\model\Group; 11 use cms\model\Project; 12 use cms\model\User; 13 use language\Messages; 14 use util\exception\ValidationException; 15 16 class ObjectAclformAction extends ObjectAction implements Method { 17 public function getRequiredPermission() 18 { 19 return Permission::ACL_GRANT; 20 } 21 22 public function view() { 23 $o = new BaseObject( $this->request->getId() ); 24 $o->objectLoadRaw(); 25 26 $this->setTemplateVars( $o->getAssocRelatedAclTypes() ); 27 $this->setTemplateVar( 'show',$o->getRelatedAclTypes() ); 28 29 $this->setTemplateVar('users' ,User::listAll() ); 30 $this->setTemplateVar('groups' ,Group::getAll() ); 31 32 $languages = array(0=>\cms\base\Language::lang('ALL_LANGUAGES')); 33 34 $project = new Project( $this->baseObject->projectid ); 35 36 $languages += $project->getLanguages(); 37 $this->setTemplateVar('languages',$languages ); 38 $this->setTemplateVar('objectid' ,$o->objectid ); 39 $this->setTemplateVar('action' ,$this->request->action); 40 } 41 42 43 public function post() { 44 $permission = new Permission(); 45 46 $permission->objectid = $this->request->getId(); 47 48 // Handelt es sich um eine Benutzer- oder Gruppen ACL? 49 switch( $this->request->getText('type') ) 50 { 51 case 'user': 52 $permission->userid = $this->request->getRequiredNumber('userid' ); 53 $permission->type = Permission::TYPE_USER; 54 55 break; 56 case 'group': 57 $permission->groupid = $this->request->getRequiredNumber('groupid'); 58 $permission->type = Permission::TYPE_GROUP; 59 break; 60 case 'all': 61 $permission->type = Permission::TYPE_AUTH; 62 break; 63 case 'guest': 64 $permission->type = Permission::TYPE_GUEST; 65 break; 66 default: 67 throw new ValidationException('type'); 68 } 69 70 $permission->languageid = $this->request->getLanguageId(); 71 72 $permission->write = ( $this->request->isTrue('write' ) ); 73 $permission->prop = ( $this->request->isTrue('prop' ) ); 74 $permission->delete = ( $this->request->isTrue('delete' ) ); 75 $permission->release = ( $this->request->isTrue('release' ) ); 76 $permission->publish = ( $this->request->isTrue('publish' ) ); 77 $permission->create_folder = ( $this->request->isTrue('create_folder') ); 78 $permission->create_file = ( $this->request->isTrue('create_file' ) ); 79 $permission->create_link = ( $this->request->isTrue('create_link' ) ); 80 $permission->create_page = ( $this->request->isTrue('create_page' ) ); 81 $permission->grant = ( $this->request->isTrue('grant' ) ); 82 $permission->transmit = ( $this->request->isTrue('transmit' ) ); 83 84 $permission->persist(); 85 86 // Falls die Berechtigung vererbbar ist, dann diese sofort an 87 // Unterobjekte vererben. 88 if ( $permission->transmit ) 89 { 90 $folder = new Folder( $permission->objectid ); 91 $oids = $folder->getObjectIds(); 92 foreach( $folder->getAllSubfolderIds() as $sfid ) 93 { 94 $subfolder = new Folder( $sfid ); 95 $oids = array_merge($oids,$subfolder->getObjectIds()); 96 } 97 98 foreach( $oids as $oid ) 99 { 100 $permission->aclid = null; 101 $permission->objectid = $oid; 102 $permission->persist(); 103 } 104 } 105 106 107 108 109 $this->addNoticeFor( $this->baseObject,Messages::ADDED); 110 111 $this->baseObject->setTimestamp(); 112 } 113 }
Download modules/cms/action/object/ObjectAclformAction.class.php
History Wed, 9 Mar 2022 13:28:52 +0100 dankert Refactoring: Checkbox values are always sent to the server. In the actions we must test the value with 'isTrue()' Sat, 27 Nov 2021 19:46:57 +0100 Jan Dankert Fix: Removed superfluous permission check. Sun, 14 Mar 2021 23:51:49 +0100 Jan Dankert Refactoring: Using the ValidationException where possible. Sat, 6 Mar 2021 03:42:38 +0100 Jan Dankert New: Better permission checks. Sat, 6 Mar 2021 02:09:25 +0100 Jan Dankert New: Allow permissions for guests only. Fri, 26 Feb 2021 01:06:01 +0100 Jan Dankert Refactoring accessing the request parameter values. Mon, 4 Jan 2021 19:03:18 +0100 Jan Dankert Refactoring: ACL class is renamed to Permission, because most RBAC/DMAC concepts are calling it a permission. Thu, 19 Nov 2020 14:49:58 +0100 Jan Dankert Fix: Action::addNotice() is replaced by Action::addNoticeFor() Thu, 19 Nov 2020 12:36:44 +0100 Jan Dankert Fix: nextSubAction() is depracated and should not be used. Wed, 18 Nov 2020 01:46:36 +0100 Jan Dankert Refactoring of model classes: New method persist() and some other cleanups. Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.