PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 2.2.0
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v2.2.0
2.2.0 2.1.0 2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 All 43 releases
← All changes | app/Models/Board.php +36 -6 2.0.15 → 2.2.0 View file →
@@ -5,9 +5,9 @@
5 5 use FluentBoards\App\Services\Constant;
6 6 use FluentBoards\App\Services\PermissionManager;
7 7 use FluentBoards\App\Services\UserService;
8 8 use FluentBoards\Framework\Database\Orm\Builder;
9 -use FluentBoardsPro\App\Models\CustomField;
9 +use FluentBoards\App\Models\CustomField;
10 10
11 11 class Board extends Model
12 12 {
13 13 protected $table = 'fbs_boards';
@@ -16,8 +16,10 @@
16 16
17 17 protected $hidden = [
18 18 'created_at',
19 19 'updated_at',
20 + 'boardMeta',
21 + 'viewerMembership',
20 22 ];
21 23
22 24 protected $fillable = [
23 25 'parent_id',
@@ -81,11 +83,34 @@
81 83 }
82 84
83 85 public function getMetaAttribute()
84 86 {
85 - return $this->getMeta();
87 + if (!$this->relationLoaded('boardMeta')) {
88 + return $this->getMeta();
89 + }
90 +
91 + $meta = [];
92 + foreach ($this->getRelation('boardMeta') as $item) {
93 + $meta[$item->key] = $item->value;
94 + }
95 + return $meta;
86 96 }
87 97
98 + /** Internal eager-loaded metadata for board-list serialization. */
99 + public function boardMeta()
100 + {
101 + return $this->hasMany(Meta::class, 'object_id')
102 + ->where('object_type', Constant::OBJECT_TYPE_BOARD);
103 + }
104 +
105 + /** Internal membership snapshot for the current board-list reader. */
106 + public function viewerMembership()
107 + {
108 + return $this->hasOne(Relation::class, 'object_id')
109 + ->where('object_type', Constant::OBJECT_TYPE_BOARD_USER)
110 + ->where('foreign_id', get_current_user_id());
111 + }
112 +
88 113 public function setBackgroundAttribute($background)
89 114 {
90 115 $this->attributes['background'] = \maybe_serialize($background);
91 116 }
@@ -301,8 +326,9 @@
301 326 }
302 327
303 328 public function updateMeta($key, $value)
304 329 {
330 + $this->unsetRelation('boardMeta');
305 331 $meta = Meta::where('object_id', $this->id)
306 332 ->where('object_type', Constant::OBJECT_TYPE_BOARD)
307 333 ->where('key', $key)
308 334 ->first();
@@ -335,12 +361,16 @@
335 361 $userId = get_current_user_id();
336 362 if(PermissionManager::isAdmin()) {
337 363 return false;
338 364 }
339 - $boardPermissions = Relation::where('object_id', $this->id)
340 - ->where('foreign_id', $userId)
341 - ->where('object_type', Constant::OBJECT_TYPE_BOARD_USER)
342 - ->first();
365 + $boardPermissions = $this->relationLoaded('viewerMembership') ? $this->getRelation('viewerMembership') : null;
366 + // Never reuse another user's eagerly loaded membership.
367 + if (!$boardPermissions || (int) $boardPermissions->foreign_id !== (int) $userId) {
368 + $boardPermissions = Relation::where('object_id', $this->id)
369 + ->where('foreign_id', $userId)
370 + ->where('object_type', Constant::OBJECT_TYPE_BOARD_USER)
371 + ->first();
372 + }
343 373
344 374 return $boardPermissions->settings['is_viewer_only'] ?? false;
345 375 }
346 376