-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathauth.php
More file actions
174 lines (144 loc) · 4.14 KB
/
Copy pathauth.php
File metadata and controls
174 lines (144 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
return array(
/*
|--------------------------------------------------------------------------
| Role Aliases
|--------------------------------------------------------------------------
|
| Shorter names for some of the longer named roles. That is all.
|
*/
'aliases' => array(
'admin' => 'administrator'
),
/*
|--------------------------------------------------------------------------
| Action Rules
|--------------------------------------------------------------------------
|
| Auth uses action rules when checking a user has permission to perform
| a given action.
|
| For example, a user may delete users but may not delete themselves. To
| do this we create a rule for that verb and action.
|
| Rules a placed within the verb for an action. The verbs are: 'access',
| 'use', 'start', 'edit', 'delete', 'approve', and 'moderate'.
|
*/
'rules' => array(
/*
|--------------------------------------------------------------------------
| Delete Verb
|--------------------------------------------------------------------------
*/
'delete' => array(
/*
|--------------------------------------------------------------------------
| Deleting Users
|--------------------------------------------------------------------------
|
| Users that can delete other users are not able to delete themselves.
|
*/
'users' => function($deleting)
{
return ($deleting->id != Feather\Auth::user()->id);
}
),
/*
|--------------------------------------------------------------------------
| Edit Verb
|--------------------------------------------------------------------------
*/
'edit' => array(
/*
|--------------------------------------------------------------------------
| Editing Discussion
|--------------------------------------------------------------------------
|
| Users can edit their own discussions, unless they are Administrator or
| Moderator, they can edit all.
|
*/
'discussion' => function($discussion)
{
$user = Feather\Auth::user();
if(Feather\Auth::is('admin'))
{
return true;
}
elseif(Feather\Auth::is('moderator'))
{
return true;
}
// The easy checks have been done, now to see if the user is a place specific
// moderator on the discussions place.
if($discussion->place->moderators)
{
foreach($discussion->place->moderators as $moderator)
{
if($user->id == $moderator->user_id)
{
return true;
}
}
}
// Lastly if this discussion belongs to this user and they have permission to
// edit their own discussions we'll allow them to edit this discussion.
if($user->id == $discussion->user_id and Feather\Auth::can('edit: own discussions'))
{
return true;
}
return false;
}
),
/*
|--------------------------------------------------------------------------
| View Verb
|--------------------------------------------------------------------------
*/
'view' => array(
/*
|--------------------------------------------------------------------------
| Viewing Discussion
|--------------------------------------------------------------------------
|
| Users can view all discussions unless it is either private or a draft.
|
*/
'discussion' => function($discussion)
{
$user = Feather\Auth::user();
// Private discussions can only be viewed by participants, the original
// poster, and administrators/moderators.
if($discussion->private)
{
if($discussion->user_id == $user->id or Feather\Auth::is(array('admin', 'moderator')))
{
return true;
}
foreach($discussion->participants as $participant)
{
if(Feather\Auth::online() and $participant->user_id == $user->id)
{
return true;
}
}
return false;
}
// Draft discussions can only be viewed by the original author and
// administrators/moderators.
elseif($discussion->draft)
{
if($discussion->user_id == $user->id or Feather\Auth::is(array('admin', 'moderator')))
{
return true;
}
return false;
}
return true;
}
)
)
);