| @@ -3,8 +3,9 @@ | ||
| 3 | 3 | namespace FluentCommunity\App\Http\Policies; |
| 4 | 4 | |
| 5 | 5 | use FluentCommunity\App\Models\User; |
| 6 | 6 | use FluentCommunity\App\Models\Space; |
| 7 | +use FluentCommunity\App\Models\BaseSpace; | |
| 7 | 8 | use FluentCommunity\App\Services\Helper; |
| 8 | 9 | use FluentCommunity\Framework\Http\Request\Request; |
| 9 | 10 | |
| 10 | 11 | class SpacePolicy extends BasePolicy |
| @@ -35,26 +36,68 @@ | ||
| 35 | 36 | } |
| 36 | 37 | |
| 37 | 38 | public function join(Request $request) |
| 38 | 39 | { |
| 39 | - return !!get_current_user_id(); | |
| 40 | + $xProfile = Helper::getCurrentProfile(true); | |
| 41 | + | |
| 42 | + return $xProfile && $xProfile->status == 'active'; | |
| 40 | 43 | } |
| 41 | 44 | |
| 42 | 45 | public function leave(Request $request) |
| 43 | 46 | { |
| 44 | - return !!get_current_user_id(); | |
| 47 | + $xProfile = Helper::getCurrentProfile(true); | |
| 48 | + | |
| 49 | + return $xProfile && $xProfile->status == 'active'; | |
| 45 | 50 | } |
| 46 | 51 | |
| 47 | - public function deleteBySlug(Request $request) | |
| 52 | + public function create(Request $request) | |
| 48 | 53 | { |
| 54 | + return $this->canManageCommunity($request, null); | |
| 55 | + } | |
| 56 | + | |
| 57 | + public function searchProduct(Request $request) | |
| 58 | + { | |
| 49 | 59 | return $this->canManageCommunity($request); |
| 50 | 60 | } |
| 51 | 61 | |
| 52 | - public function deleteById(Request $request) | |
| 62 | + public function patchBySlug(Request $request, $slug) | |
| 53 | 63 | { |
| 54 | - return $this->canManageCommunity($request); | |
| 64 | + return $this->canManageCommunity($request, Space::where('slug', $slug)->first()); | |
| 55 | 65 | } |
| 56 | 66 | |
| 67 | + public function patchById(Request $request, $id) | |
| 68 | + { | |
| 69 | + return $this->canManageCommunity($request, Space::find($id)); | |
| 70 | + } | |
| 71 | + | |
| 72 | + public function updateLinks(Request $request, $slug) | |
| 73 | + { | |
| 74 | + return $this->canManageCommunity($request, Space::where('slug', $slug)->first()); | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * The manager listing exposes disabled and hidden rows, so it is not a plain portal read. | |
| 79 | + */ | |
| 80 | + public function getPrimaryMenu(Request $request, $slug) | |
| 81 | + { | |
| 82 | + return $this->canManageCommunity($request, Space::where('slug', $slug)->first()); | |
| 83 | + } | |
| 84 | + | |
| 85 | + public function updatePrimaryMenu(Request $request, $slug) | |
| 86 | + { | |
| 87 | + return $this->canManageCommunity($request, Space::where('slug', $slug)->first()); | |
| 88 | + } | |
| 89 | + | |
| 90 | + public function deleteBySlug(Request $request, $slug) | |
| 91 | + { | |
| 92 | + return $this->canManageCommunity($request, Space::where('slug', $slug)->first()); | |
| 93 | + } | |
| 94 | + | |
| 95 | + public function deleteById(Request $request, $id) | |
| 96 | + { | |
| 97 | + return $this->canManageCommunity($request, Space::find($id)); | |
| 98 | + } | |
| 99 | + | |
| 57 | 100 | public function addMember(Request $request, $slug) |
| 58 | 101 | { |
| 59 | 102 | $space = Space::where('slug', $slug)->first(); |
| 60 | 103 | |
| @@ -74,36 +117,61 @@ | ||
| 74 | 117 | |
| 75 | 118 | public function getSpaceGroups(Request $request) |
| 76 | 119 | { |
| 77 | 120 | if ($request->get('options_only')) { |
| 78 | - return true; | |
| 121 | + return !!Helper::canAccessPortal(get_current_user_id()); | |
| 79 | 122 | } |
| 80 | 123 | |
| 81 | - return $this->canManageSpace($request); | |
| 124 | + return $this->canManageSpace($request, null); | |
| 82 | 125 | } |
| 83 | 126 | |
| 84 | 127 | public function createSpaceGroup(Request $request) |
| 85 | 128 | { |
| 86 | - return $this->canManageSpace($request); | |
| 129 | + return $this->canManageSpace($request, null); | |
| 87 | 130 | } |
| 88 | 131 | |
| 89 | 132 | public function updateSpaceGroup(Request $request) |
| 90 | 133 | { |
| 91 | - return $this->canManageSpace($request); | |
| 134 | + return $this->canManageSpace($request, null); | |
| 92 | 135 | } |
| 93 | 136 | |
| 94 | 137 | public function deleteSpaceGroup(Request $request) |
| 95 | 138 | { |
| 96 | - return $this->canManageSpace($request); | |
| 139 | + return $this->canManageSpace($request, null); | |
| 97 | 140 | } |
| 98 | 141 | |
| 99 | - public function getMetaSettings(Request $request) | |
| 142 | + public function updateSpaceGroupIndexes(Request $request) | |
| 100 | 143 | { |
| 101 | - return $this->canManageSpace($request); | |
| 144 | + return $this->canManageSpace($request, null); | |
| 102 | 145 | } |
| 103 | 146 | |
| 104 | - protected function canManageCommunity(Request $request) | |
| 147 | + public function updateSpaceIndexes(Request $request) | |
| 105 | 148 | { |
| 149 | + return $this->canManageSpace($request, null); | |
| 150 | + } | |
| 151 | + | |
| 152 | + public function moveSpace(Request $request) | |
| 153 | + { | |
| 154 | + return $this->canManageCommunity($request); | |
| 155 | + } | |
| 156 | + | |
| 157 | + public function getMetaSettings(Request $request, $spaceSlug) | |
| 158 | + { | |
| 159 | + return $this->canManageSpace($request, Space::where('slug', $spaceSlug)->first()); | |
| 160 | + } | |
| 161 | + | |
| 162 | + public function addPaywall(Request $request, $spaceId) | |
| 163 | + { | |
| 164 | + return $this->canManageCommunity($request, BaseSpace::withoutGlobalScopes()->find((int) $spaceId)); | |
| 165 | + } | |
| 166 | + | |
| 167 | + public function removePaywall(Request $request, $spaceId) | |
| 168 | + { | |
| 169 | + return $this->canManageCommunity($request, BaseSpace::withoutGlobalScopes()->find((int) $spaceId)); | |
| 170 | + } | |
| 171 | + | |
| 172 | + protected function canManageCommunity(Request $request, $space = false) | |
| 173 | + { | |
| 106 | 174 | $user = User::find(get_current_user_id()); |
| 107 | 175 | |
| 108 | 176 | if (!$user) { |
| 109 | 177 | return false; |
| @@ -112,14 +180,16 @@ | ||
| 112 | 180 | if ($user->hasCommunityAdminAccess()) { |
| 113 | 181 | return true; |
| 114 | 182 | } |
| 115 | 183 | |
| 116 | - $space = Space::find($request->get('space_id')); | |
| 184 | + if ($space === false) { | |
| 185 | + $space = Space::find((int) $request->get('space_id')); | |
| 186 | + } | |
| 117 | 187 | |
| 118 | 188 | return $space && $user->getSpaceRole($space) === 'admin'; |
| 119 | 189 | } |
| 120 | 190 | |
| 121 | - protected function canManageSpace(Request $request) | |
| 191 | + protected function canManageSpace(Request $request, $space = false) | |
| 122 | 192 | { |
| 123 | 193 | $user = User::find(get_current_user_id()); |
| 124 | 194 | |
| 125 | 195 | if (!$user) { |
| @@ -129,9 +199,11 @@ | ||
| 129 | 199 | if ($user->hasSpaceManageAccess()) { |
| 130 | 200 | return true; |
| 131 | 201 | } |
| 132 | 202 | |
| 133 | - $space = Space::find($request->get('space_id')); | |
| 203 | + if ($space === false) { | |
| 204 | + $space = Space::find((int) $request->get('space_id')); | |
| 205 | + } | |
| 134 | 206 | |
| 135 | 207 | return $space && $user->getSpaceRole($space) === 'admin'; |
| 136 | 208 | } |
| 137 | 209 | } |