Commit f036289c2ec0ed5a393a4d7c8f1a9a3c466896ef

Authored by michael
1 parent dae125a4

refactored page level access control

added distinction between guest user and normal user


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@549 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 49 additions and 50 deletions
lib/session/SiteMap.inc
... ... @@ -3,9 +3,11 @@
3 3 require_once("$default->owl_fs_root/lib/security/permission.inc");
4 4  
5 5 // define access constants
6   -define("SA", 0);
7   -define("UA", 1);
8   -define("A", 2);
  6 +define("None", -1);
  7 +define("Guest", 0);
  8 +define("User", 1);
  9 +define("UnitAdmin", 2);
  10 +define("SysAdmin", 3);
9 11  
10 12 /**
11 13 * $Id$
... ... @@ -59,27 +61,6 @@ class SiteMap {
59 61 "description" => $description,
60 62 "default" => true);
61 63 }
62   -
63   - /**
64   - * Returns the section name of the supplied page
65   - *
66   - * @param string the page to lookup the section for
67   - */
68   - function getSectionName($sRequiredPage) {
69   - global $default;
70   - // for each section
71   - foreach ($this->siteMapArray as $section => $valArr) {
72   - // for each access, page array combination
73   - foreach ($valArr as $requiredAccess => $pageArr) {
74   - // now loop through pages until we find the right one
75   - foreach ($pageArr as $action => $page) {
76   - if ($sRequiredPage == $page["page"]) {
77   - return $section;
78   - }
79   - }
80   - }
81   - }
82   - }
83 64  
84 65 /**
85 66 * Returns true if the user has the necessary rights to access
... ... @@ -89,33 +70,31 @@ class SiteMap {
89 70 * @return boolean true if the user has the access, else false.
90 71 */
91 72 function hasPermission($requiredAccess) {
92   -
93   - switch ($requiredAccess) {
94   - case A : // everyone has access to anonymous pages
95   - return true;
96   - break;
97   -
98   - case UA : // check that this user is in a group with unit admin access
99   - // or is a system adminstrator
100   - if (Permission::userIsSystemAdministrator() ||
101   - Permission::userIsUnitAdministrator()) {
102   - return true;
103   - } else {
104   - return false;
105   - }
106   - break;
107   -
108   - case SA : // check that this user is a system administrator
109   - if (Permission::userIsSystemAdministrator()) {
110   - return true;
111   - } else {
112   - return false;
113   - }
114   - break;
  73 + global $default;
  74 + // if no access control is required
  75 + if ($requiredAccess == None) {
  76 + return true;
  77 + } else {
  78 + // if you're a system administrator, you've got access to everything
  79 + if (Permission::userIsSystemAdministrator()) {
  80 + return true;
  81 + } else {
  82 + if (Permission::userIsUnitAdministrator()) {
  83 + // if you're a unit administrator, then you have access to everything
  84 + // including and less than UA
  85 + return ($requiredAccess <= UnitAdmin) ? true : false;
  86 + } else if (Permission::userIsGuest()) {
  87 + return ($requiredAccess == Guest) ? true : false;
  88 + } else {
  89 + // you're a "normal" unit user
  90 + return ($requiredAccess <= User) ? true : false;
  91 + }
  92 + }
115 93 }
116   - // if we haven't returned by here, $requiredAccess is unknown
117   -
118   - // TODO: add a check in addPage/addDefaultPage
  94 + // shouldn't ever get here
  95 + $default->log->error("SiteMap::hasPermission THERE IS A WHOLE IN THE PAGE LEVEL ACCESS SECURITY MODEL!!!");
  96 + $default->log->error("SiteMap::hasPermission requiredAccess=$requiredAccess; userID=" . $_SESSION["userID"]);
  97 + // return false anyway
119 98 return false;
120 99 }
121 100  
... ... @@ -187,6 +166,26 @@ class SiteMap {
187 166 return false;
188 167 }
189 168  
  169 + /**
  170 + * Returns the section name of the supplied page
  171 + *
  172 + * @param string the page to lookup the section for
  173 + */
  174 + function getSectionName($sRequiredPage) {
  175 + global $default;
  176 + // for each section
  177 + foreach ($this->siteMapArray as $section => $valArr) {
  178 + // for each access, page array combination
  179 + foreach ($valArr as $requiredAccess => $pageArr) {
  180 + // now loop through pages until we find the right one
  181 + foreach ($pageArr as $action => $page) {
  182 + if ($sRequiredPage == $page["page"]) {
  183 + return $section;
  184 + }
  185 + }
  186 + }
  187 + }
  188 + }
190 189  
191 190 /**
192 191 * Returns the default action for the supplied section
... ...