| @@ -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 = []; |
| @@ -246,9 +283,9 @@ | ||
| 246 | 283 | } |
| 247 | 284 | |
| 248 | 285 | /** |
| 249 | 286 | * Get array of board Ids for logged-in user |
| 250 | - * @param null $userId | |
| 287 | + * @param int $userId | |
| 251 | 288 | * @return array |
| 252 | 289 | */ |
| 253 | 290 | public static function getBoardIdsForUser($userId = null, $boardId = null) |
| 254 | 291 | { |
| @@ -307,9 +344,9 @@ | ||
| 307 | 344 | { |
| 308 | 345 | return !!is_user_logged_in(); |
| 309 | 346 | } |
| 310 | 347 | |
| 311 | - public static function getAll_WP_Admins($searchquery = '') | |
| 348 | + public static function getAll_WP_Admins($searchquery = '', $number = null) | |
| 312 | 349 | { |
| 313 | 350 | $args = array( |
| 314 | 351 | 'role' => '', |
| 315 | 352 | 'capability' => 'manage_options', |
| @@ -315,8 +352,14 @@ | ||
| 315 | 352 | 'capability' => 'manage_options', |
| 316 | 353 | 'search' => '*' . $searchquery . '*', |
| 317 | 354 | ); |
| 318 | 355 | |
| 356 | + // Optionally bound the result set (e.g. for selector popovers) so an | |
| 357 | + // empty search can't serialize every admin-capable user on large sites. | |
| 358 | + if ($number !== null) { | |
| 359 | + $args['number'] = (int) $number; | |
| 360 | + } | |
| 361 | + | |
| 319 | 362 | return get_users($args); |
| 320 | 363 | } |
| 321 | 364 | |
| 322 | 365 | public static function isWPAdmin($userId = null) |
| @@ -346,9 +389,9 @@ | ||
| 346 | 389 | return false; // Return false if no board ID is provided |
| 347 | 390 | } |
| 348 | 391 | |
| 349 | 392 | // Admins have full permissions, allow access immediately |
| 350 | - if (static::isAdmin()) { | |
| 393 | + if (static::isAdmin($userId)) { | |
| 351 | 394 | return true; |
| 352 | 395 | } |
| 353 | 396 | |
| 354 | 397 | // Fetch user permissions for the given board |
| @@ -368,6 +411,28 @@ | ||
| 368 | 411 | } |
| 369 | 412 | |
| 370 | 413 | // Deny access if the user is a viewer only and trying to modify data |
| 371 | 414 | return !($boardPermissions->settings['is_viewer_only'] ?? false); |
| 415 | + } | |
| 416 | + | |
| 417 | + public static function userHasBoardCreationPermission($userId = null) | |
| 418 | + { | |
| 419 | + if (!$userId) { | |
| 420 | + $userId = get_current_user_id(); | |
| 421 | + if (!$userId) { | |
| 422 | + return false; | |
| 423 | + } | |
| 424 | + } | |
| 425 | + | |
| 426 | + if (static::isAdmin($userId)) { | |
| 427 | + return apply_filters('fluent_boards/can_create_board', true, $userId); | |
| 428 | + } | |
| 429 | + | |
| 430 | + // Check if "allow members to create boards" setting is enabled | |
| 431 | + $generalSettings = fluent_boards_get_option('general_settings', []); | |
| 432 | + if (!empty($generalSettings['allow_members_to_create_boards']) && $generalSettings['allow_members_to_create_boards'] !== 'false' && static::userHasAnyBoardAccess($userId)) { | |
| 433 | + return apply_filters('fluent_boards/can_create_board', true, $userId); | |
| 434 | + } | |
| 435 | + | |
| 436 | + return apply_filters('fluent_boards/can_create_board', false, $userId); | |
| 372 | 437 | } |
| 373 | 438 | } |