1
|
|
|
<?php namespace EvolutionCMS\Legacy; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @class: udperms |
5
|
|
|
*/ |
6
|
|
|
class Permissions |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* @var int |
10
|
|
|
*/ |
11
|
|
|
public $user; |
12
|
|
|
/** |
13
|
|
|
* @var int |
14
|
|
|
*/ |
15
|
|
|
public $document; |
16
|
|
|
/** |
17
|
|
|
* @var int |
18
|
|
|
*/ |
19
|
|
|
public $role; |
20
|
|
|
/** |
21
|
|
|
* @var bool |
22
|
|
|
*/ |
23
|
|
|
public $duplicateDoc = false; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return bool |
27
|
|
|
*/ |
28
|
|
|
public function checkPermissions() |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
global $udperms_allowroot; |
|
|
|
|
32
|
|
|
$modx = evolutionCMS(); |
33
|
|
|
|
34
|
|
|
$tblsc = $modx->getFullTableName('site_content'); |
35
|
|
|
$tbldg = $modx->getFullTableName('document_groups'); |
36
|
|
|
$tbldgn = $modx->getFullTableName('documentgroup_names'); |
37
|
|
|
|
38
|
|
|
$document = $this->document; |
39
|
|
|
$role = $this->role; |
40
|
|
|
|
41
|
|
|
if ($role == 1) { |
42
|
|
|
return true; // administrator - grant all document permissions |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if ($modx->config['use_udperms'] == 0 || $modx->config['use_udperms'] == "" || !isset($modx->config['use_udperms'])) { |
46
|
|
|
return true; // permissions aren't in use |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$parent = $modx->db->getValue($modx->db->select('parent', $tblsc, "id='{$this->document}'")); |
50
|
|
View Code Duplication |
if ($document == 0 && $parent == null && $udperms_allowroot == 1) { |
51
|
|
|
return true; |
52
|
|
|
} // User is allowed to create new document in root |
53
|
|
View Code Duplication |
if (($this->duplicateDoc == true || $document == 0) && $parent == 0 && $udperms_allowroot == 0) { |
|
|
|
|
54
|
|
|
return false; // deny duplicate || create new document at root if Allow Root is No |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// get document groups for current user |
58
|
|
|
$docgrp = empty($_SESSION['mgrDocgroups']) ? '' : implode(' || dg.document_group = ', |
59
|
|
|
$_SESSION['mgrDocgroups']); |
60
|
|
|
|
61
|
|
|
/* Note: |
62
|
|
|
A document is flagged as private whenever the document group that it |
63
|
|
|
belongs to is assigned or links to a user group. In other words if |
64
|
|
|
the document is assigned to a document group that is not yet linked |
65
|
|
|
to a user group then that document will be made public. Documents that |
66
|
|
|
are private to the manager users will not be private to web users if the |
67
|
|
|
document group is not assigned to a web user group and visa versa. |
68
|
|
|
*/ |
69
|
|
|
$permissionsok = false; // set permissions to false |
70
|
|
|
|
71
|
|
|
$rs = $modx->db->select( |
|
|
|
|
72
|
|
|
'count(DISTINCT sc.id)', |
73
|
|
|
"{$tblsc} AS sc |
74
|
|
|
LEFT JOIN {$tbldg} AS dg on dg.document = sc.id |
75
|
|
|
LEFT JOIN {$tbldgn} dgn ON dgn.id = dg.document_group", |
76
|
|
|
"sc.id='{$this->document}' AND (" . (empty($docgrp) ? '' : "dg.document_group = " . $docgrp . " ||") . " sc.privatemgr = 0)" |
77
|
|
|
); |
78
|
|
|
$limit = $modx->db->getValue($rs); |
79
|
|
|
if ($limit == 1) { |
80
|
|
|
$permissionsok = true; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $permissionsok; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: