Add visibility to component groups (#2027)
Implement visibility for the components groups. Closes #1892 Add functional test that asserts a guest can only see public items. * Fix tests not running due to hitting the Setup page. The missing `boostrap/cachet/testing.php` file is now generated the first time tests are ran. * Add a functional test that asserts logged in users can see all items. Add constants for possible values for the visible column/field of the ComponentGroup model. Code review changes. * Add API tests for component group visibility feature. * Implement the visibility hidden option for a component group. Fixes #1892. Add migration for the created_by column, in component_groups table. Add methods to the ComponentGroup and User models to be able to work with the created_by column. Hidden component groups are no longer displayed on the index page for loggedin users. Add functional test for the dashboard page. Save owner on create/edit component group. Update the API tests for Component group visibility feature. * Replace auth() usage with app(Guard::class). * Apply StyleCI fixes. * Drop the hidden visibility feature and fix all tests. Some code review fixes too. * Rename public to visible since it's a reserved keyword. Apply StyleCI fixes and correct typo. * Code review changes. * Tidy up component and component groups gathering. * Code review changes and StyleCI fixes. * Code review changes. * Remove extra whitespace * Remove useless method.
This commit is contained in:
committed by
James Brooks
parent
bf769e1470
commit
ad0954eb20
@@ -15,13 +15,29 @@ use AltThree\Validator\ValidatingTrait;
|
||||
use CachetHQ\Cachet\Models\Traits\SearchableTrait;
|
||||
use CachetHQ\Cachet\Models\Traits\SortableTrait;
|
||||
use CachetHQ\Cachet\Presenters\ComponentGroupPresenter;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use McCool\LaravelAutoPresenter\HasPresenter;
|
||||
|
||||
class ComponentGroup extends Model implements HasPresenter
|
||||
{
|
||||
use SearchableTrait, SortableTrait, ValidatingTrait;
|
||||
|
||||
/**
|
||||
* Viewable only authenticated users.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const VISIBLE_AUTHENTICATED = 0;
|
||||
|
||||
/**
|
||||
* Viewable by public.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const VISIBLE_GUEST = 1;
|
||||
|
||||
/**
|
||||
* The model's attributes.
|
||||
*
|
||||
@@ -30,6 +46,7 @@ class ComponentGroup extends Model implements HasPresenter
|
||||
protected $attributes = [
|
||||
'order' => 0,
|
||||
'collapsed' => 0,
|
||||
'visible' => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -41,6 +58,7 @@ class ComponentGroup extends Model implements HasPresenter
|
||||
'name' => 'string',
|
||||
'order' => 'int',
|
||||
'collapsed' => 'int',
|
||||
'visible' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -48,7 +66,7 @@ class ComponentGroup extends Model implements HasPresenter
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['name', 'order', 'collapsed'];
|
||||
protected $fillable = ['name', 'order', 'collapsed', 'visible'];
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
@@ -59,6 +77,7 @@ class ComponentGroup extends Model implements HasPresenter
|
||||
'name' => 'required|string',
|
||||
'order' => 'int',
|
||||
'collapsed' => 'int',
|
||||
'visible' => 'bool',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -71,6 +90,7 @@ class ComponentGroup extends Model implements HasPresenter
|
||||
'name',
|
||||
'order',
|
||||
'collapsed',
|
||||
'visible',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -83,6 +103,7 @@ class ComponentGroup extends Model implements HasPresenter
|
||||
'name',
|
||||
'order',
|
||||
'collapsed',
|
||||
'visible',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -141,4 +162,30 @@ class ComponentGroup extends Model implements HasPresenter
|
||||
{
|
||||
return ComponentGroupPresenter::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all component groups which are visible to public.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeVisible(Builder $query)
|
||||
{
|
||||
return $query->where('visible', self::VISIBLE_GUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all used component groups.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Support\Collection $usedComponentGroups
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeUsed(Builder $query, Collection $usedComponentGroups)
|
||||
{
|
||||
return $query->whereIn('id', $usedComponentGroups)
|
||||
->orderBy('order');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user