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 +48 -6 2.0.0 → 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 }
@@ -237,8 +262,20 @@
237 262 });
238 263 }
239 264
240 265 /**
266 + * Limit boards to types supported by the currently loaded plugins.
267 + */
268 + public function scopeAvailableInCurrentInstall($query)
269 + {
270 + if (!defined('FLUENT_ROADMAP')) {
271 + return $query->where('type', 'to-do');
272 + }
273 +
274 + return $query;
275 + }
276 +
277 + /**
241 278 * Only template boards (inverse of scopeExcludeTemplates).
242 279 */
243 280 public function scopeOnlyTemplates($query)
244 281 {
@@ -289,8 +326,9 @@
289 326 }
290 327
291 328 public function updateMeta($key, $value)
292 329 {
330 + $this->unsetRelation('boardMeta');
293 331 $meta = Meta::where('object_id', $this->id)
294 332 ->where('object_type', Constant::OBJECT_TYPE_BOARD)
295 333 ->where('key', $key)
296 334 ->first();
@@ -323,12 +361,16 @@
323 361 $userId = get_current_user_id();
324 362 if(PermissionManager::isAdmin()) {
325 363 return false;
326 364 }
327 - $boardPermissions = Relation::where('object_id', $this->id)
328 - ->where('foreign_id', $userId)
329 - ->where('object_type', Constant::OBJECT_TYPE_BOARD_USER)
330 - ->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 + }
331 373
332 374 return $boardPermissions->settings['is_viewer_only'] ?? false;
333 375 }
334 376