| @@ -106,9 +106,9 @@ | ||
| 106 | 106 | if (!$boardUser) { |
| 107 | 107 | return false; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - return (bool)$boardUser->settings ? $boardUser->settings['is_admin'] : null; | |
| 110 | + return (bool)($boardUser->settings[Constant::IS_BOARD_ADMIN] ?? false); | |
| 111 | 111 | |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | public static function userHasAnyBoardAccess($userId = null): bool |
| @@ -200,8 +200,45 @@ | ||
| 200 | 200 | |
| 201 | 201 | return true; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | + public static function userCanAccessMemberProfile($targetUserId, $userId = null): bool | |
| 205 | + { | |
| 206 | + $targetUserId = intval($targetUserId); | |
| 207 | + | |
| 208 | + if (!$userId) { | |
| 209 | + $userId = get_current_user_id(); | |
| 210 | + } | |
| 211 | + | |
| 212 | + $userId = intval($userId); | |
| 213 | + | |
| 214 | + if (!$targetUserId || !$userId) { | |
| 215 | + return false; | |
| 216 | + } | |
| 217 | + | |
| 218 | + if ($userId === $targetUserId || static::isAdmin($userId)) { | |
| 219 | + return true; | |
| 220 | + } | |
| 221 | + | |
| 222 | + if (!static::isFluentBoardsUser($targetUserId)) { | |
| 223 | + return false; | |
| 224 | + } | |
| 225 | + | |
| 226 | + $boardIds = Relation::where('foreign_id', $userId) | |
| 227 | + ->where('object_type', Constant::OBJECT_TYPE_BOARD_USER) | |
| 228 | + ->pluck('object_id') | |
| 229 | + ->toArray(); | |
| 230 | + | |
| 231 | + if (empty($boardIds)) { | |
| 232 | + return false; | |
| 233 | + } | |
| 234 | + | |
| 235 | + return Relation::where('foreign_id', $targetUserId) | |
| 236 | + ->where('object_type', Constant::OBJECT_TYPE_BOARD_USER) | |
| 237 | + ->whereIn('object_id', $boardIds) | |
| 238 | + ->exists(); | |
| 239 | + } | |
| 240 | + | |
| 204 | 241 | public static function isAdmin($userId = null, $useCache = true) |
| 205 | 242 | { |
| 206 | 243 | |
| 207 | 244 | static $cache = []; |
| @@ -352,9 +389,9 @@ | ||
| 352 | 389 | return false; // Return false if no board ID is provided |
| 353 | 390 | } |
| 354 | 391 | |
| 355 | 392 | // Admins have full permissions, allow access immediately |
| 356 | - if (static::isAdmin()) { | |
| 393 | + if (static::isAdmin($userId)) { | |
| 357 | 394 | return true; |
| 358 | 395 | } |
| 359 | 396 | |
| 360 | 397 | // Fetch user permissions for the given board |