@@ -32,19 +32,14 @@ public function get($key)
3232 case 'legalPageFileFields ' :
3333 return $ this ->module ->$ key ;
3434 case 'legalViewTemplates ' :
35- if ($ super ) return $ this ->getLegalTemplates ();
3635 return $ this ->getLegalTemplatesForPermission ('page-view ' );
3736 case 'legalCreateTemplates ' :
38- if ($ super ) return $ this ->getLegalTemplates ();
3937 return $ this ->getLegalTemplatesForPermission ('page-create ' );
4038 case 'legalEditTemplates ' :
41- if ($ super ) return $ this ->getLegalTemplates ();
4239 return $ this ->getLegalTemplatesForPermission ('page-edit ' );
4340 case 'legalViewFields ' :
44- if ($ super ) return $ this ->getLegalFields ();
4541 return $ this ->getLegalFieldsForPermission ('view ' );
4642 case 'legalEditFields ' :
47- if ($ super ) return $ this ->getLegalFields ();
4843 return $ this ->getLegalFieldsForPermission ('edit ' );
4944 default :
5045 return parent ::get ($ key );
@@ -59,12 +54,33 @@ protected function getLegalTemplates()
5954
6055 protected function getLegalTemplatesForPermission ($ permission = 'page-view ' )
6156 {
62- $ templates = $ this ->getLegalTemplates ()->find ("useRoles=1 " );
63- foreach ($ templates as $ template ) {
64- if (!Utils::user ()->hasTemplatePermission ($ permission , $ template )) {
65- $ templates ->remove ($ template );
57+ $ user = Utils::user ();
58+ $ templates = $ this ->getLegalTemplates ();
59+
60+ // if superuser give access to everything
61+ if ($ user ->isSuperuser ()) return $ templates ;
62+
63+ // if access is granted then templates are accessable by default
64+ // but if a template has Access settings, user should have relevant
65+ // permissions
66+ if (Utils::moduleConfig ()->grantTemplateAccess ) {
67+ foreach ($ templates as $ template ) {
68+ if ($ template ->useRoles && !$ user ->hasTemplatePermission ($ permission , $ template )) {
69+ $ templates ->remove ($ template );
70+ }
71+ }
72+
73+ // if access is not granted then user can see only those templates that
74+ // she has explicit access to.
75+ } else {
76+ $ templates ->filter ("useRoles=1 " );
77+ foreach ($ templates as $ template ) {
78+ if (!$ user ->hasTemplatePermission ($ permission , $ template )) {
79+ $ templates ->remove ($ template );
80+ }
6681 }
6782 }
83+
6884 return $ templates ;
6985 }
7086
@@ -76,17 +92,27 @@ protected function getLegalFields()
7692
7793 protected function getLegalFieldsForPermission ($ permission = 'view ' )
7894 {
79- $ fields = $ this ->getLegalFields ()->find ("useRoles=1 " );
80- $ rolesType = $ permission . "Roles " ;
81- foreach ($ fields as $ field ) {
82- if (!$ this ->userHasPermission ($ field ->$ rolesType )) {
83- $ fields ->remove ($ field );
95+ $ fields = $ this ->getLegalFields ();
96+ $ roles = $ permission . "Roles " ;
97+
98+ if (Utils::moduleConfig ()->grantFieldAccess ) {
99+ foreach ($ fields as $ field ) {
100+ if ($ field ->useRoles && !$ this ->userHasRoleIn ($ field ->$ roles )) {
101+ $ fields ->remove ($ field );
102+ }
103+ }
104+ } else {
105+ $ fields ->find ("useRoles=1 " );
106+ foreach ($ fields as $ field ) {
107+ if (!$ this ->userHasRoleIn ($ field ->$ roles )) {
108+ $ fields ->remove ($ field );
109+ }
84110 }
85111 }
86112 return $ fields ;
87113 }
88114
89- protected function userHasPermission ($ rolesID )
115+ protected function userHasRoleIn ($ rolesID )
90116 {
91117 $ userRolesID = Utils::user ()->roles ->explode ('id ' );
92118 foreach ($ userRolesID as $ userRoleID ) {
0 commit comments