Commit ae1ccccd75a9a7b67d8bd3b75dc5f5338bd73a32

Authored by Megan Watson
1 parent bb22bafd

Added new folderItem functions. Fixed up the Role and Permission Allocation func…

…tionality and unit tests.

Committed by: Megan Watson
Reviewed by: Kevin Cyster



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@9741 c91229c3-7414-0410-bfa2-8a42b809f60b
ktapi/KTAPIAcl.inc.php
... ... @@ -56,6 +56,7 @@ abstract class KTAPI_Dynamic
56 56 /**
57 57 * Generic getter method
58 58 *
  59 + * @author KnowledgeTree Team
59 60 * @access protected
60 61 * @param string $property
61 62 * @return mixed
... ... @@ -70,15 +71,16 @@ abstract class KTAPI_Dynamic
70 71 }
71 72 throw new Exception('Unknown method ' . get_class($this) . '.' . $method);
72 73 }
73   -
  74 +
74 75 /**
75 76 * Generic setter method
76   - *
  77 + *
  78 + * @author KnowledgeTree Team
77 79 * @access protected
78 80 * @param string $property
79 81 * @param mixed $value
80 82 */
81   -
  83 +
82 84 protected
83 85 function __set($property, $value)
84 86 {
... ... @@ -137,7 +139,9 @@ class KTAPI_User extends KTAPI_Member
137 139 /**
138 140 * Using the id, the user can be resolved.
139 141 *
140   - * @static
  142 + * @author KnowledgeTree Team
  143 + * @access public
  144 + * @static
141 145 * @param int $id
142 146 * @return KTAPI_User Returns null if there is no match.
143 147 */
... ... @@ -158,6 +162,8 @@ class KTAPI_User extends KTAPI_Member
158 162 /**
159 163 * Using the full name, the user can be resolved.
160 164 *
  165 + * @author KnowledgeTree Team
  166 + * @access public
161 167 * @static
162 168 * @param string $name
163 169 * @return KTAPI_User Returns null if there is no match.
... ... @@ -179,6 +185,8 @@ class KTAPI_User extends KTAPI_Member
179 185 /**
180 186 * Using the username, the user is resolved.
181 187 *
  188 + * @author KnowledgeTree Team
  189 + * @access public
182 190 * @static
183 191 * @param string $username
184 192 * @return KTAPI_User Returns null if there is no match.
... ... @@ -199,6 +207,8 @@ class KTAPI_User extends KTAPI_Member
199 207 /**
200 208 * Using the email, the user is resolved.
201 209 *
  210 + * @author KnowledgeTree Team
  211 + * @access public
202 212 * @static
203 213 * @param string $email
204 214 * @return KTAPI_User Returns null if there is no match.
... ... @@ -220,6 +230,8 @@ class KTAPI_User extends KTAPI_Member
220 230 /**
221 231 * Returns a list of users matching the filter criteria.
222 232 *
  233 + * @author KnowledgeTree Team
  234 + * @access public
223 235 * @static
224 236 * @param string $filter
225 237 * @param array $options
... ... @@ -245,15 +257,19 @@ class KTAPI_User extends KTAPI_Member
245 257 }
246 258  
247 259 /**
248   - * Return username property. (readonly)
  260 + * Return id property. (readonly)
249 261 *
250   - * @return string
  262 + * @author KnowledgeTree Team
  263 + * @access public
  264 + * @return integer
251 265 */
252 266 public function getId() { return $this->user->getId(); }
253 267  
254 268 /**
255 269 * Return username property. (readonly)
256 270 *
  271 + * @author KnowledgeTree Team
  272 + * @access public
257 273 * @return string
258 274 */
259 275 public function getUsername() { return $this->user->getUserName(); }
... ... @@ -261,6 +277,8 @@ class KTAPI_User extends KTAPI_Member
261 277 /**
262 278 * Return display name property. (readonly)
263 279 *
  280 + * @author KnowledgeTree Team
  281 + * @access public
264 282 * @return string
265 283 */
266 284 public function getName() { return $this->user->getName(); }
... ... @@ -268,6 +286,8 @@ class KTAPI_User extends KTAPI_Member
268 286 /**
269 287 * Return email property. (readonly)
270 288 *
  289 + * @author KnowledgeTree Team
  290 + * @access public
271 291 * @return string
272 292 */
273 293 public function getEmail() { return $this->user->getEmail(); }
... ... @@ -294,6 +314,7 @@ class KTAPI_Group extends KTAPI_Member
294 314 /**
295 315 * Constructor for KTAPI_Group. This is private, and can only be constructed by the static getByXXX() functions.
296 316 *
  317 + * @author KnowledgeTree Team
297 318 * @access private
298 319 * @param Group $group
299 320 */
... ... @@ -306,6 +327,8 @@ class KTAPI_Group extends KTAPI_Member
306 327 /**
307 328 * Using the id, the group can be resolved.
308 329 *
  330 + * @author KnowledgeTree Team
  331 + * @access public
309 332 * @static
310 333 * @param int $id
311 334 * @return KTAPI_Group Returns null if there is no match.
... ... @@ -327,6 +350,8 @@ class KTAPI_Group extends KTAPI_Member
327 350 /**
328 351 * Using the name, the group can be resolved.
329 352 *
  353 + * @author KnowledgeTree Team
  354 + * @access public
330 355 * @static
331 356 * @param string $name
332 357 * @return KTAPI_Group Returns null if there is no match.
... ... @@ -347,6 +372,8 @@ class KTAPI_Group extends KTAPI_Member
347 372 /**
348 373 * Returns a list of groups matching the filter criteria.
349 374 *
  375 + * @author KnowledgeTree Team
  376 + * @access public
350 377 * @static
351 378 * @param string $filter
352 379 * @param array $options
... ... @@ -374,6 +401,8 @@ class KTAPI_Group extends KTAPI_Member
374 401 /**
375 402 * Return username property. (readonly)
376 403 *
  404 + * @author KnowledgeTree Team
  405 + * @access public
377 406 * @return string
378 407 */
379 408 public function getId() { return $this->group->getId(); }
... ... @@ -381,6 +410,8 @@ class KTAPI_Group extends KTAPI_Member
381 410 /**
382 411 * Return display name property. (readonly)
383 412 *
  413 + * @author KnowledgeTree Team
  414 + * @access public
384 415 * @return string
385 416 */
386 417 public function getName() { return $this->group->getName(); }
... ... @@ -388,6 +419,8 @@ class KTAPI_Group extends KTAPI_Member
388 419 /**
389 420 * Indicates if the group members are system administrators. (readonly)
390 421 *
  422 + * @author KnowledgeTree Team
  423 + * @access public
391 424 * @return boolean
392 425 */
393 426 public function getIsSystemAdministrator() { return $this->group->getSysAdmin(); }
... ... @@ -414,6 +447,7 @@ class KTAPI_Role extends KTAPI_Member
414 447 /**
415 448 * Constructor for KTAPI_Group. This is private, and can only be constructed by the static getByXXX() functions.
416 449 *
  450 + * @author KnowledgeTree Team
417 451 * @access private
418 452 * @param Role $role
419 453 */
... ... @@ -426,6 +460,8 @@ class KTAPI_Role extends KTAPI_Member
426 460 /**
427 461 * Using the id, the role can be resolved.
428 462 *
  463 + * @author KnowledgeTree Team
  464 + * @access public
429 465 * @static
430 466 * @param int $id
431 467 * @return KTAPI_Role Returns null if there is no match.
... ... @@ -445,6 +481,8 @@ class KTAPI_Role extends KTAPI_Member
445 481 /**
446 482 * Using the name, the role can be resolved.
447 483 *
  484 + * @author KnowledgeTree Team
  485 + * @access public
448 486 * @static
449 487 * @param string $name
450 488 * @return KTAPI_Role Returns null if there is no match.
... ... @@ -467,6 +505,8 @@ class KTAPI_Role extends KTAPI_Member
467 505 /**
468 506 * Returns a list of roles matching the filter criteria.
469 507 *
  508 + * @author KnowledgeTree Team
  509 + * @access public
470 510 * @static
471 511 * @param string $filter
472 512 * @param array $options
... ... @@ -494,6 +534,8 @@ class KTAPI_Role extends KTAPI_Member
494 534 /**
495 535 * Return id property. (readonly)
496 536 *
  537 + * @author KnowledgeTree Team
  538 + * @access public
497 539 * @return string
498 540 */
499 541 public function getId() { return $this->role->getId(); }
... ... @@ -501,6 +543,8 @@ class KTAPI_Role extends KTAPI_Member
501 543 /**
502 544 * Return display name property. (readonly)
503 545 *
  546 + * @author KnowledgeTree Team
  547 + * @access public
504 548 * @return string
505 549 */
506 550 public function getName() { return $this->role->getName(); }
... ... @@ -529,6 +573,7 @@ class KTAPI_Permission extends KTAPI_Dynamic
529 573 /**
530 574 * Constructor for KTAPI_Permission. This is private, and can only be constructed by the static getByXXX() functions.
531 575 *
  576 + * @author KnowledgeTree Team
532 577 * @access private
533 578 * @param KTPermission $permission
534 579 */
... ... @@ -541,6 +586,8 @@ class KTAPI_Permission extends KTAPI_Dynamic
541 586 /**
542 587 * Return a list of permissions.
543 588 *
  589 + * @author KnowledgeTree Team
  590 + * @access public
544 591 * @static
545 592 * @param string $filter
546 593 * @param array $options
... ... @@ -567,6 +614,8 @@ class KTAPI_Permission extends KTAPI_Dynamic
567 614 /**
568 615 * Returns a KTAPI_Permission based on id.
569 616 *
  617 + * @author KnowledgeTree Team
  618 + * @access public
570 619 * @static
571 620 * @param int $id
572 621 * @return KTAPI_Permission Returns null if the namespace could not be resolved.
... ... @@ -587,6 +636,8 @@ class KTAPI_Permission extends KTAPI_Dynamic
587 636 /**
588 637 * Returns a KTAPI_Permission based on namespace.
589 638 *
  639 + * @author KnowledgeTree Team
  640 + * @access public
590 641 * @static
591 642 * @param string $namespace
592 643 * @return KTAPI_Permission Returns null if the namespace could not be resolved.
... ... @@ -607,6 +658,8 @@ class KTAPI_Permission extends KTAPI_Dynamic
607 658 /**
608 659 * Returns the permission id.
609 660 *
  661 + * @author KnowledgeTree Team
  662 + * @access public
610 663 * @return int
611 664 */
612 665 public
... ... @@ -615,6 +668,8 @@ class KTAPI_Permission extends KTAPI_Dynamic
615 668 /**
616 669 * Returns the permission name.
617 670 *
  671 + * @author KnowledgeTree Team
  672 + * @access public
618 673 * @return string
619 674 */
620 675 public
... ... @@ -623,6 +678,8 @@ class KTAPI_Permission extends KTAPI_Dynamic
623 678 /**
624 679 * Returns the permission namespace.
625 680 *
  681 + * @author KnowledgeTree Team
  682 + * @access public
626 683 * @return string
627 684 */
628 685 public
... ... @@ -630,7 +687,7 @@ class KTAPI_Permission extends KTAPI_Dynamic
630 687 }
631 688  
632 689 /**
633   - * AllocationBase.
  690 + * Allocation Base class
634 691 *
635 692 * @author KnowledgeTree Team
636 693 * @package KTAPI
... ... @@ -672,6 +729,8 @@ abstract class KTAPI_AllocationBase extends KTAPI_Dynamic
672 729  
673 730  
674 731 /**
  732 + * Instance of the KTAPI object
  733 + *
675 734 * @access protected
676 735 * @var KTAPI
677 736 */
... ... @@ -680,6 +739,7 @@ abstract class KTAPI_AllocationBase extends KTAPI_Dynamic
680 739 /**
681 740 * Constructor for KTAPI_Permission. This is protected, and can only be constructed by the static getAllocation() function.
682 741 *
  742 + * @author KnowledgeTree Team
683 743 * @access protected
684 744 * @param KTAPI_FolderItem $folderItem
685 745 */
... ... @@ -695,6 +755,7 @@ abstract class KTAPI_AllocationBase extends KTAPI_Dynamic
695 755 /**
696 756 * Helper method to identify the member type for the map.
697 757 *
  758 + * @author KnowledgeTree Team
698 759 * @access protected
699 760 * @param KTAPI_Member $member
700 761 * @return string
... ... @@ -707,7 +768,7 @@ abstract class KTAPI_AllocationBase extends KTAPI_Dynamic
707 768 {
708 769 case 'KTAPI_User': $type = 'user'; break;
709 770 case 'KTAPI_Group': $type = 'group'; break;
710   - case 'KTAPI_Route': $type = 'route'; break;
  771 + case 'KTAPI_Role': $type = 'role'; break;
711 772 default:
712 773 throw new Exception('Unknown type: ' . $type);
713 774 }
... ... @@ -717,6 +778,7 @@ abstract class KTAPI_AllocationBase extends KTAPI_Dynamic
717 778 /**
718 779 * Log the transaction for the current user.
719 780 *
  781 + * @author KnowledgeTree Team
720 782 * @access protected
721 783 * @param string $comment
722 784 * @param string $namespace
... ... @@ -761,6 +823,8 @@ abstract class KTAPI_AllocationBase extends KTAPI_Dynamic
761 823 /**
762 824 * Restore working copy, voiding the add(), remove() changes.
763 825 *
  826 + * @author KnowledgeTree Team
  827 + * @access public
764 828 */
765 829 public
766 830 function restore()
... ... @@ -792,7 +856,9 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
792 856 /**
793 857 * Returns the permission allocation for a specified folder item.
794 858 *
795   - * @static
  859 + * @author KnowledgeTree Team
  860 + * @access public
  861 + * @static
796 862 * @param KTAPI
797 863 * @param KTAPI_FolderItem
798 864 * @return KTAPI_PermissionAllocation
... ... @@ -808,6 +874,8 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
808 874 /**
809 875 * Force the current folder item to inherit permission from the parent.
810 876 *
  877 + * @author KnowledgeTree Team
  878 + * @access public
811 879 */
812 880 public
813 881 function inheritAllocation()
... ... @@ -822,6 +890,8 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
822 890 /**
823 891 * Creates a copy of the current permissions.
824 892 *
  893 + * @author KnowledgeTree Team
  894 + * @access public
825 895 */
826 896 public
827 897 function overrideAllocation()
... ... @@ -834,6 +904,8 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
834 904 /**
835 905 * Gives permission to the specified member.
836 906 *
  907 + * @author KnowledgeTree Team
  908 + * @access public
837 909 * @param KTAPI_Member $member A KTAPI_Role, KTAPI_Group or KTAPI_User.
838 910 * @param KTAPI_Permission $permission
839 911 */
... ... @@ -847,6 +919,8 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
847 919 * Removes permission from the specified member.
848 920 * NOTE: This only removes permission if it was already granted.
849 921 *
  922 + * @author KnowledgeTree Team
  923 + * @access public
850 924 * @param KTAPI_Member $member A KTAPI_Role, KTAPI_Group or KTAPI_User.
851 925 * @param KTAPI_Permission $permission
852 926 */
... ... @@ -859,6 +933,7 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
859 933 /**
860 934 * Helper method to update the permission map for the current folder item.
861 935 *
  936 + * @author KnowledgeTree Team
862 937 * @access private
863 938 * @param KTAPI_Member $member
864 939 * @param KTAPI_Permission $permission
... ... @@ -881,6 +956,7 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
881 956 /**
882 957 * Returns a list of members.
883 958 *
  959 + * @author KnowledgeTree Team
884 960 * @access private
885 961 * @param string $type
886 962 * @return array
... ... @@ -894,6 +970,8 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
894 970 /**
895 971 * Return list of users for which there are allocations.
896 972 *
  973 + * @author KnowledgeTree Team
  974 + * @access public
897 975 * @return array
898 976 */
899 977 public
... ... @@ -905,6 +983,8 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
905 983 /**
906 984 * Return list of groups for which there are allocations.
907 985 *
  986 + * @author KnowledgeTree Team
  987 + * @access public
908 988 * @return array
909 989 */
910 990 public
... ... @@ -916,6 +996,8 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
916 996 /**
917 997 * Return list of members for which there are allocations.
918 998 *
  999 + * @author KnowledgeTree Team
  1000 + * @access public
919 1001 * @return array
920 1002 */
921 1003 public
... ... @@ -927,6 +1009,8 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
927 1009 /**
928 1010 * Returns the map of permissions for the specific member.
929 1011 *
  1012 + * @author KnowledgeTree Team
  1013 + * @access public
930 1014 * @param KTAPI_Member $member
931 1015 * @return array
932 1016 */
... ... @@ -941,6 +1025,8 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
941 1025 /**
942 1026 * Returns true if the permission is set for the specific member.
943 1027 *
  1028 + * @author KnowledgeTree Team
  1029 + * @access public
944 1030 * @param KTAPI_Member $member
945 1031 * @param KTAPI_Permission $permission
946 1032 * @return boolean
... ... @@ -970,6 +1056,8 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
970 1056 /**
971 1057 * Returns the properties defined in the system.
972 1058 *
  1059 + * @author KnowledgeTree Team
  1060 + * @access public
973 1061 * @return array
974 1062 *
975 1063 */
... ... @@ -982,6 +1070,8 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
982 1070 /**
983 1071 * Returns an associative array with permissions mapped onto users, groups and roles.
984 1072 *
  1073 + * @author KnowledgeTree Team
  1074 + * @access public
985 1075 * @access protected
986 1076 */
987 1077 protected
... ... @@ -1097,13 +1187,13 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
1097 1187 $inheritedId = $inherited->getId();
1098 1188 $objectId = $object->getId();
1099 1189  
1100   - $map['inherited'] = ($inheritedId === $objectId) && ($objectId != 1);
  1190 + $map['inherited'] = ($inheritedId !== $objectId) && ($objectId != 1);
1101 1191  
1102   - // only allow inheritance if not inherited, -and- folders is editable
  1192 + // only allow inheritance of permissions from parent if not inherited, -and- folder is editable
1103 1193 $map['inheritable'] = $editable && !$map['inherited'] && ($objectId != 1);
1104 1194  
1105   - // only allow edit if the folder is editable.
1106   - $map['editable'] = $editable && $map['inherited'];
  1195 + // only allow edit if the folder is editable and not inherited
  1196 + $map['editable'] = $editable && !$map['inherited'];
1107 1197  
1108 1198 $this->map = $map;
1109 1199 $this->mapCopy = $map;
... ... @@ -1113,6 +1203,8 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
1113 1203 /**
1114 1204 * Saves changes made by add() and remove().
1115 1205 *
  1206 + * @author KnowledgeTree Team
  1207 + * @access public
1116 1208 */
1117 1209 public
1118 1210 function save()
... ... @@ -1124,7 +1216,7 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
1124 1216 }
1125 1217  
1126 1218 // if the current setup is inherited, then we must create a new copy to store the new associations.
1127   - if ($this->IsInherited)
  1219 + if ($this->getIsInherited())
1128 1220 {
1129 1221 $this->overrideAllocation();
1130 1222 }
... ... @@ -1185,6 +1277,8 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
1185 1277 /**
1186 1278 * Indicates if any changes have been made.
1187 1279 *
  1280 + * @author KnowledgeTree Team
  1281 + * @access public
1188 1282 * @return boolean
1189 1283 */
1190 1284 public
... ... @@ -1193,6 +1287,8 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
1193 1287 /**
1194 1288 * Indicates if the current folder item is allowed to inherit permissions from the parent.
1195 1289 *
  1290 + * @author KnowledgeTree Team
  1291 + * @access public
1196 1292 * @return boolean
1197 1293 */
1198 1294 public
... ... @@ -1201,6 +1297,8 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
1201 1297 /**
1202 1298 * Indicates it the current folder item currently inherits the permissions from the parent.
1203 1299 *
  1300 + * @author KnowledgeTree Team
  1301 + * @access public
1204 1302 * @return boolean
1205 1303 */
1206 1304 public
... ... @@ -1209,6 +1307,8 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
1209 1307 /**
1210 1308 * Indicates if the permissions are editable but the current user.
1211 1309 *
  1310 + * @author KnowledgeTree Team
  1311 + * @access public
1212 1312 * @return boolean
1213 1313 */
1214 1314 public
... ... @@ -1226,7 +1326,10 @@ final class KTAPI_PermissionAllocation extends KTAPI_AllocationBase
1226 1326 final class KTAPI_RoleAllocation extends KTAPI_AllocationBase
1227 1327 {
1228 1328 /**
1229   - *
  1329 + * Resolve the folder item allocations
  1330 + *
  1331 + * @author KnowledgeTree Team
  1332 + * @access public
1230 1333 * @access protected
1231 1334 */
1232 1335 protected
... ... @@ -1293,7 +1396,9 @@ final class KTAPI_RoleAllocation extends KTAPI_AllocationBase
1293 1396 /**
1294 1397 * Returns a reference to the role alloction on a folder item.
1295 1398 *
1296   - * @static
  1399 + * @author KnowledgeTree Team
  1400 + * @access public
  1401 + * @static
1297 1402 * @param KTAPI $ktapi
1298 1403 * @param KTAPI_FolderItem $folderItem
1299 1404 * @return KTAPI_RoleAllocation
... ... @@ -1308,7 +1413,9 @@ final class KTAPI_RoleAllocation extends KTAPI_AllocationBase
1308 1413 /**
1309 1414 * Return an array mapping the membership.
1310 1415 *
1311   - * @static
  1416 + * @author KnowledgeTree Team
  1417 + * @access public
  1418 + * @static
1312 1419 * @param string $filter
1313 1420 * @param array $options
1314 1421 * @return array of KTAPIMember
... ... @@ -1322,6 +1429,8 @@ final class KTAPI_RoleAllocation extends KTAPI_AllocationBase
1322 1429 /**
1323 1430 * Link a member to a role on the current folder item.
1324 1431 *
  1432 + * @author KnowledgeTree Team
  1433 + * @access public
1325 1434 * @param KTAPI_Role $role Must be a KTAPIRole, or an array of roles.
1326 1435 * @param KTAPI_Member $member A KTAPI_Group, KTAPI_User, array.
1327 1436 */
... ... @@ -1356,6 +1465,8 @@ final class KTAPI_RoleAllocation extends KTAPI_AllocationBase
1356 1465 /**
1357 1466 * Remove a member from a role on the current folder item.
1358 1467 *
  1468 + * @author KnowledgeTree Team
  1469 + * @access public
1359 1470 * @param KTAPI_Role $role Must be a KTAPIRole, or an array of roles.
1360 1471 * @param KTAPI_Member $member A KTAPI_Group or KTAPI_User.
1361 1472 */
... ... @@ -1382,6 +1493,8 @@ final class KTAPI_RoleAllocation extends KTAPI_AllocationBase
1382 1493 /**
1383 1494 * Check's if a role has a specific member
1384 1495 *
  1496 + * @author KnowledgeTree Team
  1497 + * @access public
1385 1498 * @param KTAPI_Role $role
1386 1499 * @param KTAPI_Member $member
1387 1500 * @return boolean
... ... @@ -1411,6 +1524,8 @@ final class KTAPI_RoleAllocation extends KTAPI_AllocationBase
1411 1524 /**
1412 1525 * Removes all members associated with roles on the current folder item.
1413 1526 *
  1527 + * @author KnowledgeTree Team
  1528 + * @access public
1414 1529 * @param KTAPI_Role $role Must be a KTAPI_Role, or an array of roles.
1415 1530 * @param KTAPI_Member $member A KTAPI_Group or KTAPI_User.
1416 1531 */
... ... @@ -1436,8 +1551,10 @@ final class KTAPI_RoleAllocation extends KTAPI_AllocationBase
1436 1551 }
1437 1552  
1438 1553 /**
1439   - *
  1554 + * Override the role allocation for each role
1440 1555 *
  1556 + * @author KnowledgeTree Team
  1557 + * @access public
1441 1558 */
1442 1559 public
1443 1560 function overrideAllocation()
... ... @@ -1447,10 +1564,12 @@ final class KTAPI_RoleAllocation extends KTAPI_AllocationBase
1447 1564 $this->overrideRoleAllocation(KTAPI_Role::getById($roleId));
1448 1565 }
1449 1566 }
1450   -
  1567 +
1451 1568 /**
1452 1569 * Overrides a role allocation
1453 1570 *
  1571 + * @author KnowledgeTree Team
  1572 + * @access public
1454 1573 * @param KTAPI_Role $role
1455 1574 */
1456 1575 public
... ... @@ -1497,12 +1616,15 @@ final class KTAPI_RoleAllocation extends KTAPI_AllocationBase
1497 1616  
1498 1617 // regenerate permissions
1499 1618  
1500   - $this->renegeratePermissionsForRole($roleId);
  1619 + $this->_regeneratePermissionsForRole($roleId);
  1620 + return $roleAllocation;
1501 1621 }
1502 1622  
1503 1623 /**
1504 1624 * Force all roles to inherit role associations.
1505 1625 *
  1626 + * @author KnowledgeTree Team
  1627 + * @access public
1506 1628 */
1507 1629 public
1508 1630 function inheritAllocation()
... ... @@ -1520,6 +1642,13 @@ final class KTAPI_RoleAllocation extends KTAPI_AllocationBase
1520 1642 }
1521 1643 }
1522 1644  
  1645 + /**
  1646 + * Can the folder inherit allocations
  1647 + *
  1648 + * @author KnowledgeTree Team
  1649 + * @access public
  1650 + * @return unknown
  1651 + */
1523 1652 public
1524 1653 function canInheritRoleAllocation()
1525 1654 {
... ... @@ -1532,6 +1661,8 @@ final class KTAPI_RoleAllocation extends KTAPI_AllocationBase
1532 1661 /**
1533 1662 * Inherit the role associations from the parent.
1534 1663 *
  1664 + * @author KnowledgeTree Team
  1665 + * @access public
1535 1666 * @param KTAPI_Role $role
1536 1667 * @param boolean $log
1537 1668 */
... ... @@ -1565,19 +1696,21 @@ final class KTAPI_RoleAllocation extends KTAPI_AllocationBase
1565 1696 return PEAR::raiseError(_kt('Could not inherit allocation from parent.'));
1566 1697 }
1567 1698  
1568   - $this->_renegeratePermissionsForRole($roleId);
  1699 + $this->_regeneratePermissionsForRole($roleId);
1569 1700 }
1570 1701  
1571 1702 /**
1572 1703 * Regenerate permissions for a role.
1573 1704 *
1574   - * Adapted from KTRoleAllocationPlugin::renegeratePermissionsForRole()
  1705 + * Adapted from KTRoleAllocationPlugin::regeneratePermissionsForRole()
1575 1706 *
  1707 + * @author KnowledgeTree Team
  1708 + * @access public
1576 1709 * @access private
1577 1710 * @param int $iRoleId
1578 1711 */
1579 1712 private
1580   - function _renegeratePermissionsForRole($iRoleId)
  1713 + function _regeneratePermissionsForRole($iRoleId)
1581 1714 {
1582 1715 $object = $this->folderItem->getObject();
1583 1716  
... ... @@ -1642,6 +1775,8 @@ final class KTAPI_RoleAllocation extends KTAPI_AllocationBase
1642 1775 /**
1643 1776 * Save's the role allocation
1644 1777 *
  1778 + * @author KnowledgeTree Team
  1779 + * @access public
1645 1780 */
1646 1781 public
1647 1782 function save()
... ... @@ -1692,4 +1827,4 @@ final class KTAPI_RoleAllocation extends KTAPI_AllocationBase
1692 1827 }
1693 1828 }
1694 1829  
1695 1830 -?>
  1831 +?>
1696 1832 \ No newline at end of file
... ...
ktapi/KTAPIDocument.inc.php
... ... @@ -2257,6 +2257,30 @@ class KTAPI_Document extends KTAPI_FolderItem
2257 2257 }
2258 2258  
2259 2259 /**
  2260 + * Get the role allocation for the document
  2261 + *
  2262 + * @return KTAPI_RoleAllocation Instance of the role allocation object
  2263 + */
  2264 + public function getRoleAllocation()
  2265 + {
  2266 + $allocation = KTAPI_RoleAllocation::getAllocation($this->ktapi, $this);
  2267 +
  2268 + return $allocation;
  2269 + }
  2270 +
  2271 + /**
  2272 + * Get the permission allocation for the document
  2273 + *
  2274 + * @return KTAPI_PermissionAllocation Instance of the permission allocation object
  2275 + */
  2276 + public function getPermissionAllocation()
  2277 + {
  2278 + $allocation = KTAPI_PermissionAllocation::getAllocation($this->ktapi, $this);
  2279 +
  2280 + return $allocation;
  2281 + }
  2282 +
  2283 + /**
2260 2284 * Checks if the user is subscribed to the document
2261 2285 *
2262 2286 * @author KnowledgeTree Team
... ...
ktapi/KTAPIFolder.inc.php
... ... @@ -32,7 +32,7 @@
32 32 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33 33 * must display the words "Powered by KnowledgeTree" and retain the original
34 34 * copyright notice.
35   - *
  35 + *
36 36 * @copyright 2008-2009, KnowledgeTree Inc.
37 37 * @license GNU General Public License version 3
38 38 * @author KnowledgeTree Team
... ... @@ -50,7 +50,7 @@ require_once(KT_DIR . '/ktwebservice/KTUploadManager.inc.php');
50 50 * @author KnowledgeTree Team
51 51 * @package KTAPI
52 52 * @version Version 0.9
53   - *
  53 + *
54 54 */
55 55 class KTAPI_Folder extends KTAPI_FolderItem
56 56 {
... ... @@ -112,7 +112,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
112 112  
113 113 /**
114 114 * Checks if the folder is a shortcut
115   - *
  115 + *
116 116 * @author KnowledgeTree Team
117 117 * @access public
118 118 * @return boolean
... ... @@ -124,7 +124,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
124 124  
125 125 /**
126 126 * Retrieves the shortcuts linking to this folder
127   - *
  127 + *
128 128 * @author KnowledgeTree Team
129 129 * @access public
130 130 * @return array
... ... @@ -194,7 +194,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
194 194 }
195 195 /**
196 196 * This clears the global object cashe of the folder class.
197   - *
  197 + *
198 198 * @author KnowledgeTree Team
199 199 * @access public
200 200 *
... ... @@ -211,8 +211,8 @@ class KTAPI_Folder extends KTAPI_FolderItem
211 211 }
212 212  
213 213 /**
214   - *
215   - *
  214 + *
  215 + *
216 216 * @author KnowledgeTree Team
217 217 * @access public
218 218 * @return unknown
... ... @@ -247,7 +247,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
247 247  
248 248 /**
249 249 * This function will return a folder by it's name (not ID)
250   - *
  250 + *
251 251 * @author KnowledgeTree Team
252 252 * @access public
253 253 * @param KTAPI $ktapi
... ... @@ -303,7 +303,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
303 303  
304 304 /**
305 305 * This will return the full path string of the current folder object
306   - *
  306 + *
307 307 * @author KnowledgeTree Team
308 308 * @access public
309 309 * @return string
... ... @@ -318,7 +318,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
318 318  
319 319 /**
320 320 * This gets a document by filename or name.
321   - *
  321 + *
322 322 * @author KnowledgeTree Team
323 323 * @access private
324 324 * @param string $documentname
... ... @@ -409,7 +409,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
409 409  
410 410 /**
411 411 * Gets a User class based on the user id
412   - *
  412 + *
413 413 * @author KnowledgeTree Team
414 414 * @param int $userid
415 415 * @return User
... ... @@ -431,7 +431,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
431 431  
432 432 /**
433 433 * Get's a permission string for a folder eg: 'RW' or 'RWA'
434   - *
  434 + *
435 435 * @author KnowledgeTree Team
436 436 * @access public
437 437 * @param Folder $folder
... ... @@ -457,7 +457,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
457 457  
458 458 /**
459 459 * Get's a folder listing, recursing to the given depth
460   - *
  460 + *
461 461 * <code>
462 462 * $root = $this->ktapi->get_root_folder();
463 463 * $listing = $root->get_listing();
... ... @@ -468,7 +468,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
468 468 * }
469 469 * }
470 470 * </code>
471   - *
  471 + *
472 472 * @author KnowledgeTree Team
473 473 * @access public
474 474 * @param int $depth
... ... @@ -753,7 +753,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
753 753  
754 754 /**
755 755 * This adds a shortcut to an existing document to the current folder
756   - *
  756 + *
757 757 * @author KnowledgeTree Team
758 758 * @access public
759 759 * @param int $document_id The ID of the document to create a shortcut to
... ... @@ -787,7 +787,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
787 787  
788 788 /**
789 789 * This adds a shortcut pointing to an existing folder to the current folder
790   - *
  790 + *
791 791 * @author KnowledgeTree Team
792 792 * @access public
793 793 * @param int $folder_id The ID of the folder to create a shortcut to
... ... @@ -827,7 +827,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
827 827 * $folder = $kt->get_folder_by_name("My New folder");
828 828 * $res = $folder->add_document("Test Document", "test.txt", "Default", $tmpfname);
829 829 * </code>
830   - *
  830 + *
831 831 * @author KnowledgeTree Team
832 832 * @access public
833 833 * @param string $title This is the title for the file in the repository.
... ... @@ -905,7 +905,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
905 905 * $root->add_folder("My New folder");
906 906 * ?>
907 907 * </code>
908   - *
  908 + *
909 909 * @author KnowledgeTree Team
910 910 * @access public
911 911 * @param string $foldername
... ... @@ -944,7 +944,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
944 944 * $folder = $kt->get_folder_by_name("My New folder");
945 945 * $folder->delete("It was getting old!");
946 946 * </code>
947   - *
  947 + *
948 948 * @author KnowledgeTree Team
949 949 * @access public
950 950 * @param string $reason
... ... @@ -975,7 +975,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
975 975  
976 976 /**
977 977 * This renames the folder
978   - *
  978 + *
979 979 * @author KnowledgeTree Team
980 980 * @access public
981 981 * @param string $newname
... ... @@ -1043,7 +1043,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
1043 1043 * $new_folder = $root->add_folder("New test folder");
1044 1044 * $res = $folder->copy($new_folder, "Test copy");
1045 1045 * </code>
1046   - *
  1046 + *
1047 1047 * @author KnowledgeTree Team
1048 1048 * @access public
1049 1049 * @param KTAPI_Folder $ktapi_target_folder
... ... @@ -1113,6 +1113,30 @@ class KTAPI_Folder extends KTAPI_FolderItem
1113 1113 }
1114 1114  
1115 1115 /**
  1116 + * Get the role allocation for the folder
  1117 + *
  1118 + * @return KTAPI_RoleAllocation Instance of the role allocation object
  1119 + */
  1120 + public function getRoleAllocation()
  1121 + {
  1122 + $allocation = KTAPI_RoleAllocation::getAllocation($this->ktapi, $this);
  1123 +
  1124 + return $allocation;
  1125 + }
  1126 +
  1127 + /**
  1128 + * Get the permission allocation for the folder
  1129 + *
  1130 + * @return KTAPI_PermissionAllocation Instance of the permission allocation object
  1131 + */
  1132 + public function getPermissionAllocation()
  1133 + {
  1134 + $allocation = KTAPI_PermissionAllocation::getAllocation($this->ktapi, $this);
  1135 +
  1136 + return $allocation;
  1137 + }
  1138 +
  1139 + /**
1116 1140 * Determines whether the currently logged on user is subscribed
1117 1141 *
1118 1142 * @author KnowledgeTree Team
... ... @@ -1129,10 +1153,10 @@ class KTAPI_Folder extends KTAPI_FolderItem
1129 1153 }
1130 1154  
1131 1155 /**
1132   - *
  1156 + *
1133 1157 * @author KnowledgeTree Team
1134 1158 * @access public
1135   - *
  1159 + *
1136 1160 */
1137 1161 public function unsubscribe()
1138 1162 {
... ... @@ -1154,7 +1178,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
1154 1178 *
1155 1179 * @author KnowledgeTree Team
1156 1180 * @access public
1157   - *
  1181 + *
1158 1182 */
1159 1183 public function subscribe()
1160 1184 {
... ...
ktapi/ktapi.inc.php
... ... @@ -96,6 +96,10 @@ abstract class KTAPI_FolderItem
96 96  
97 97 public abstract function getObject();
98 98  
  99 + public abstract function getRoleAllocation();
  100 +
  101 + public abstract function getPermissionAllocation();
  102 +
99 103 public abstract function isSubscribed();
100 104  
101 105 public abstract function unsubscribe();
... ...
tests/api/testAcl.php
1 1 <?php
2   -require_once (KTAPI_TEST_DIR . '/test.php');
  2 +require_once (KT_DIR . '/tests/test.php');
3 3 require_once (KT_DIR . '/ktapi/ktapi.inc.php');
4 4  
5 5 class APIAclTestCase extends KTUnitTestCase {
... ... @@ -123,8 +123,10 @@ class APIAclTestCase extends KTUnitTestCase {
123 123 function testRoleAllocation()
124 124 {
125 125 $root = $this->ktapi->get_root_folder();
126   - $folder = $this->ktapi->get_folder_by_name('/test123');
127   -
  126 + $folder = $this->ktapi->get_folder_by_name('test123');
  127 + if(!$folder instanceof KTAPI_Folder){
  128 + $folder = $root->add_folder('test123');
  129 + }
128 130 $allocation = KTAPI_RoleAllocation::getAllocation($this->ktapi, $folder);
129 131  
130 132 $role2 = KTAPI_Role::getByName('Reviewer');
... ... @@ -133,27 +135,27 @@ class APIAclTestCase extends KTUnitTestCase {
133 135 $user2 = KTAPI_User::getByUsername('anonymous');
134 136 $group = KTAPI_Group::getByName('System Administrators');
135 137  
136   -// $this->assertFalse($allocation->doesRoleHaveMember($role, $user));
137   -// $this->assertTrue($allocation->doesRoleHaveMember($role2, $user));
138   -
139   -
  138 + $this->assertFalse($allocation->doesRoleHaveMember($role, $user));
  139 + $this->assertFalse($allocation->doesRoleHaveMember($role2, $user));
140 140  
  141 + // Add Admin user to Reviewer role
141 142 $allocation->add($role2, $user);
  143 + // Add Admin user to Publisher role
142 144 $allocation->add($role, $user);
  145 + // Add Sys admin group to Publisher role
143 146 $allocation->add($role, $group);
  147 + // Add Anonymous to Publisher role - duplicate to test
  148 + $allocation->add($role, $user2);
  149 + $allocation->add($role, $user2);
144 150 $allocation->save();
145   -/* $allocation->add($role, $user2);
146   - $allocation->add($role, $user2); // yup. this is a dup. just to test.
147   - $allocation->add($role, $group);
148 151  
149 152 $this->assertTrue($allocation->doesRoleHaveMember($role, $user));
  153 + $this->assertTrue($allocation->doesRoleHaveMember($role, $group));
150 154  
151 155 $allocation->remove($role, $user);
152   -
153 156 $this->assertFalse($allocation->doesRoleHaveMember($role, $user));
154 157  
155 158 $allocation->remove($role, $user2);
156   -
157 159 $this->assertFalse($allocation->doesRoleHaveMember($role, $user2));
158 160  
159 161 $allocation->save();
... ... @@ -162,8 +164,9 @@ class APIAclTestCase extends KTUnitTestCase {
162 164  
163 165 $allocation = KTAPI_RoleAllocation::getAllocation($this->ktapi, $root);
164 166 $this->assertFalse($allocation->doesRoleHaveMember($role, $user));
165   - $this->assertFalse($allocation->doesRoleHaveMember($role, $user2));*/
  167 + $this->assertFalse($allocation->doesRoleHaveMember($role, $user2));
166 168  
  169 + $folder->delete('Testing role allocation');
167 170 }
168 171  
169 172 /**
... ... @@ -173,12 +176,16 @@ class APIAclTestCase extends KTUnitTestCase {
173 176 function testPermissionAllocation()
174 177 {
175 178 $root = $this->ktapi->get_root_folder();
176   - $folder = $this->ktapi->get_folder_by_name('/test123');
  179 + $folder = $this->ktapi->get_folder_by_name('test123');
  180 + if(!$folder instanceof KTAPI_Folder){
  181 + $folder = $root->add_folder('test123');
  182 + }
177 183  
178   - $allocation = KTAPI_PermissionAllocation::getAllocation($this->ktapi, $root);
  184 + $allocation = KTAPI_PermissionAllocation::getAllocation($this->ktapi, $folder);
179 185  
180 186 $group = KTAPI_Group::getByName('System Administrators');
181 187 $user = KTAPI_User::getByUsername('anonymous');
  188 + $role = KTAPI_Role::getByName('Publisher');
182 189 $read = KTAPI_Permission::getByNamespace('ktcore.permissions.read');
183 190 $write = KTAPI_Permission::getByNamespace('ktcore.permissions.write');
184 191 $addFolder = KTAPI_Permission::getByNamespace('ktcore.permissions.addFolder');
... ... @@ -188,21 +195,22 @@ class APIAclTestCase extends KTUnitTestCase {
188 195 $allocation->add($user, $write);
189 196 $allocation->add($user, $addFolder);
190 197 $allocation->add($user, $security);
  198 + $allocation->add($role, $read);
  199 + $allocation->add($role, $write);
191 200 $allocation->remove($group, $write);
192 201  
193 202 $allocation->save();
194 203  
  204 + // refresh object and check permission allocations
  205 + $folder2 = $this->ktapi->get_folder_by_name('test123');
195 206  
196   - $root2 = $this->ktapi->get_root_folder();
197   -
198   - $allocation = KTAPI_PermissionAllocation::getAllocation($this->ktapi, $root2);
  207 + $allocation = KTAPI_PermissionAllocation::getAllocation($this->ktapi, $folder2);
199 208 $this->assertTrue($allocation->isMemberPermissionSet($user, $read));
200 209 $this->assertTrue($allocation->isMemberPermissionSet($user, $write));
201   -
  210 + $this->assertTrue($allocation->isMemberPermissionSet($role, $write));
202 211 $this->assertFalse($allocation->isMemberPermissionSet($group, $write));
203 212  
  213 + $folder->delete('Testing permission allocation');
204 214 }
205   -
206 215 }
207   -?>
208   -
  216 +?>
209 217 \ No newline at end of file
... ...
tests/api/testDocument.php
... ... @@ -271,6 +271,31 @@ class APIDocumentTestCase extends KTUnitTestCase {
271 271 }
272 272  
273 273 /**
  274 + * Test role allocation and permission allocation
  275 + */
  276 + function testPermissions()
  277 + {
  278 + $randomFile = APIDocumentHelper::createRandomFile();
  279 + $this->assertTrue(is_file($randomFile));
  280 +
  281 + $document = $this->root->add_document('testtitle', 'testname', 'Default', $randomFile);
  282 + @unlink($randomFile);
  283 + $this->assertNotError($document);
  284 + if(PEAR::isError($document)) return;
  285 +
  286 + $permAllocation = $document->getPermissionAllocation();
  287 + $this->assertNotNull($permAllocation);
  288 + $this->assertEntity($permAllocation, KTAPI_PermissionAllocation);
  289 +
  290 + $roleAllocation = $document->getRoleAllocation();
  291 + $this->assertNotNull($roleAllocation);
  292 + $this->assertEntity($roleAllocation, KTAPI_RoleAllocation);
  293 +
  294 + $document->delete('Testing');
  295 + $document->expunge();
  296 + }
  297 +
  298 + /**
274 299 * Tests the adding of a duplicate document title
275 300 *
276 301 function testAddingDuplicateTitle()
... ...
tests/api/testFolder.php
1 1 <?php
2   -require_once (dirname(__FILE__) . '/../test.php');
  2 +require_once (KT_DIR . '/tests/test.php');
3 3 require_once (KT_DIR . '/ktapi/ktapi.inc.php');
4 4 class APIFolderTestCase extends KTUnitTestCase {
5 5 /**
... ... @@ -26,36 +26,36 @@ class APIFolderTestCase extends KTUnitTestCase {
26 26 $folder2->delete('because');
27 27 }
28 28 }
29   -
  29 +
30 30 function testAddDocument() {
31 31 $tmpfname = tempnam("/tmp", "KTUNIT");
32 32 $fp = fopen($tmpfname, "w");
33 33 fwrite($fp, "Hello");
34 34 fclose($fp);
35   -
  35 +
36 36 $folder = $this->ktapi->get_root_folder();
37 37 $res = $folder->add_document("Test Document", "test.txt", "Default", $tmpfname);
38 38 $this->assertEntity($res, 'KTAPI_Document');
39   -
40   -
41   -
  39 +
  40 +
  41 +
42 42 $res = $res->delete("Test deletion");
43   -
44   -
45   -
  43 +
  44 +
  45 +
46 46 }
47   -
  47 +
48 48 function testDeleteFolder() {
49 49 $folder = $this->ktapi->get_root_folder();
50 50 $folder = $folder->add_folder('temp1');
51 51 $this->assertEntity($folder, 'KTAPI_Folder');
52 52 $folder->delete('because');
53   -
  53 +
54 54 $folder = $this->ktapi->get_folder_by_name('temp1');
55 55 $this->assertError($folder);
56 56 }
57   -
58   -
  57 +
  58 +
59 59 /* function testRename() {
60 60 $root = $this->ktapi->get_root_folder();
61 61 $this->assertEntity($root, 'KTAPI_Folder');
... ... @@ -77,26 +77,26 @@ class APIFolderTestCase extends KTUnitTestCase {
77 77 $root = $this->ktapi->get_root_folder();
78 78 $folder = $root->get_folder();
79 79 $this->assertEntity($folder, 'Folder');
80   -
  80 +
81 81 $folder = $this->ktapi->get_folder_by_name("NONAMEFOLDER");
82 82 $this->assertError($folder);
83   -
  83 +
84 84 $junk = pack("H*", "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
85 85 $junk = $junk.$junk.$junk.$junk.$junk.$junk.$junk.$junk.$junk;
86 86 $folder = $this->ktapi->get_folder_by_name($junk);
87 87 $this->assertError($folder);
88   -
  88 +
89 89 }
90   -
  90 +
91 91 function testListing() {
92 92 $root = $this->ktapi->get_root_folder();
93 93 $listing = $root->get_listing();
94 94 $this->assertExpectedResults(true, is_array($listing));
95 95 foreach($listing as $key => $val) {
96   -
  96 +
97 97 }
98 98 }
99   -
  99 +
100 100 function testCreateFolders() {
101 101 $root = $this->ktapi->get_root_folder();
102 102 $this->assertEntity($root, 'KTAPI_Folder');
... ... @@ -132,8 +132,8 @@ class APIFolderTestCase extends KTUnitTestCase {
132 132 $this->assertEntity($folder, 'PEAR_Error');
133 133 }
134 134 }
135   -
136   -
  135 +
  136 +
137 137 function testPermission() {
138 138 $root = $this->ktapi->get_root_folder();
139 139 $perm = $root->get_permissions();
... ... @@ -142,43 +142,63 @@ class APIFolderTestCase extends KTUnitTestCase {
142 142  
143 143 function getSystemListing() {
144 144 // TODO .. can do anything as admin...
145   -
  145 +
146 146 }
147 147 function getAnonymousListing() {
148 148 // TODO
149 149 // probably won't be able to do unless the api caters for setting up anonymous...
150   -
  150 +
151 151 }
152 152 function getUserListing() {
153 153 // TODO
154   -
  154 +
155 155 }
156 156 function testCopy() {
157 157 $root = $this->ktapi->get_root_folder();
158 158 $folder = $root->add_folder("Test folder2");
159 159 $new_folder = $root->add_folder("New test folder2");
160 160 $res = $folder->copy($new_folder, "Unit test copy2");
161   -
  161 +
162 162 $folder->delete("Clean up test");
163 163 $new_folder->delete("Clean up test");
164   -
  164 +
165 165 $this->assertNull($res, "Error returned");
166   -
167   -
  166 +
  167 +
168 168 }
169 169 function testMove() {
170 170 $root = $this->ktapi->get_root_folder();
171 171 $folder = $root->add_folder("Test folder2");
172 172 $new_folder = $root->add_folder("New test folder2");
173 173 $res = $folder->move($new_folder, "Unit test copy2");
174   -
  174 +
175 175 $folder->delete("Clean up test");
176 176 $new_folder->delete("Clean up test");
177   -
  177 +
178 178 $this->assertNull($res, "Error returned");
179   -
180   -
  179 +
  180 +
181 181 }
182 182  
  183 + /**
  184 + * Test role allocation and permission allocation
  185 + */
  186 + function testPermissions()
  187 + {
  188 + $root = $this->ktapi->get_root_folder();
  189 + $folder = $root->add_folder('testX');
  190 + $this->assertEntity($folder, 'KTAPI_Folder');
  191 + if(PEAR::isError($folder)) return;
  192 +
  193 + $permAllocation = $folder->getPermissionAllocation();
  194 + $this->assertNotNull($permAllocation);
  195 + $this->assertEntity($permAllocation, KTAPI_PermissionAllocation);
  196 +
  197 + $roleAllocation = $folder->getRoleAllocation();
  198 + $this->assertNotNull($roleAllocation);
  199 + $this->assertEntity($roleAllocation, KTAPI_RoleAllocation);
  200 +
  201 + $folder->delete('Testing');
  202 + }
183 203 }
184 204 ?>
... ...