Skip to content

Commit

Permalink
Merge branch '3.x' into fix-nested-repeaters
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofandel authored Mar 31, 2024
2 parents 49ecfad + 8611299 commit 60fcf11
Show file tree
Hide file tree
Showing 37 changed files with 170 additions and 142 deletions.
195 changes: 115 additions & 80 deletions CHANGELOG.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ return new class extends Migration
```

This file will create the minimum required tables and columns that Twill uses to provide the CMS functionality. Later in
the guide we may add some more fields to the database, but will will do that in a new migration.
the guide we may add some more fields to the database, but we will do that in a new migration.

Once you are more experienced with Twill, you may want to add fields at this moment, before you run the migrate command.
That way, you do not have to immediately add a new migration file.
Expand Down
2 changes: 1 addition & 1 deletion frontend/js/store/modules/buckets.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const actions = {
content_type: state.dataSources.selected.value,
page: state.page,
offset: state.offset,
filter: state.filter
filter: JSON.stringify(state.filter)
}, resp => {
commit(BUCKETS.UPDATE_BUCKETS_DATA, resp.source)
commit(BUCKETS.UPDATE_BUCKETS_MAX_PAGE, resp.maxPage)
Expand Down
2 changes: 1 addition & 1 deletion frontend/js/store/modules/datatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ const actions = {
page: state.page,
offset: state.offset,
columns: getters.visibleColumnsNames,
filter: state.filter
filter: JSON.stringify(state.filter)
}

api.get(params, function (resp) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@area17/twill",
"version": "3.1.0",
"version": "3.2.1",
"private": true,
"scripts": {
"inspect": "vue-cli-service inspect --mode production",
Expand Down
3 changes: 1 addition & 2 deletions src/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace A17\Twill;

use A17\Twill\Facades\TwillPermissions;
use A17\Twill\Models\User;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;

Expand Down Expand Up @@ -159,7 +158,7 @@ public function boot()

$this->define('publish-user', function ($user) {
return $this->authorize($user, function ($user) {
$editedUserObject = User::find(request('id'));
$editedUserObject = twillModel('user')::find(request('id'));
return $this->userHasRole(
$user,
[TwillPermissions::roles()::ADMIN]
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ListBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected function getBlocks(): Collection
// We do not render this.
unset($data['rules'], $data['rulesForTranslatedFields']);

$data['block class'] = $block::class !== 'A17\Twill\Services\Blocks\Block' ? get_class($block) : 'default';
$data['block class'] = $block::class !== Block::class ? get_class($block) : 'default';

$list[] = $data;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use A17\Twill\Facades\TwillBlocks;
use A17\Twill\Facades\TwillCapsules;
use A17\Twill\Models\Model;
use A17\Twill\Services\Blocks\Block;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
Expand Down Expand Up @@ -208,6 +209,7 @@ function fix_directory_separator($path)
}

if (! function_exists('twillModel')) {
/** @return class-string<Model>|Model It returns a class string but this is for the correct type hints */
function twillModel($model): string
{
return config("twill.models.$model")
Expand Down
3 changes: 1 addition & 2 deletions src/Http/Controllers/Admin/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use A17\Twill\Models\Behaviors\HasSlug;
use A17\Twill\Models\Contracts\TwillModelContract;
use A17\Twill\Models\Contracts\TwillSchedulableModel;
use A17\Twill\Models\Group;
use A17\Twill\Repositories\ModuleRepository;
use A17\Twill\Services\Breadcrumbs\Breadcrumbs;
use A17\Twill\Services\Forms\Fields\BaseFormField;
Expand Down Expand Up @@ -2674,7 +2673,7 @@ protected function respondWithJson($message, $variant)
protected function getGroupUserMapping()
{
if (config('twill.enabled.permissions-management')) {
return Group::with('users')->get()
return twillModel('group')::with('users')->get()
->mapWithKeys(function ($group) {
return [$group->id => $group->users()->pluck('id')->toArray()];
})->toArray();
Expand Down
7 changes: 3 additions & 4 deletions src/Http/Controllers/Admin/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace A17\Twill\Http\Controllers\Admin;

use A17\Twill\Models\User;
use Illuminate\Config\Repository as Config;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -82,7 +81,7 @@ public function broker()

protected function sendResetResponse(Request $request, $response)
{
$user = User::where('email', $request->input('email'))->first();
$user = twillModel('user')::where('email', $request->input('email'))->first();
if (!$user->isActivated()) {
$user->registered_at = Carbon::now();
$user->save();
Expand Down Expand Up @@ -156,12 +155,12 @@ private function getUserFromToken($token)
$clearToken = DB::table($this->config->get('auth.passwords.twill_users.table', 'twill_password_resets'))->where('token', $token)->first();

if ($clearToken) {
return User::where('email', $clearToken->email)->first();
return twillModel('user')::where('email', $clearToken->email)->first();
}

foreach (DB::table($this->config->get('auth.passwords.twill_users.table', 'twill_password_resets'))->get() as $passwordReset) {
if (Hash::check($token, $passwordReset->token)) {
return User::where('email', $passwordReset->email)->first();
return twillModel('user')::where('email', $passwordReset->email)->first();
}
}

Expand Down
13 changes: 5 additions & 8 deletions src/Http/Controllers/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
use A17\Twill\Enums\PermissionLevel;
use A17\Twill\Facades\TwillPermissions;
use A17\Twill\Models\Contracts\TwillModelContract;
use A17\Twill\Models\Group;
use A17\Twill\Models\Permission;
use A17\Twill\Models\Role;
use A17\Twill\Models\User;
use A17\Twill\Services\Listings\Columns\Image;
use A17\Twill\Services\Listings\Columns\Text;
use A17\Twill\Services\Listings\Filters\QuickFilter;
Expand Down Expand Up @@ -99,7 +96,7 @@ public function __construct(Application $app, Request $request, AuthFactory $aut

TwillPermissions::showUserSecondaryNavigation();

$this->filters['role'] = User::getRoleColumnName();
$this->filters['role'] = twillModel('user')::getRoleColumnName();
}

public function getIndexTableColumns(): TableColumns
Expand Down Expand Up @@ -137,7 +134,7 @@ public function getIndexTableColumns(): TableColumns
);
$tableColumns->add(
Text::make()
->field(User::getRoleColumnName())
->field(twillModel('user')::getRoleColumnName())
->title('Role')
->customRender(function (TwillModelContract $user) {
if (TwillPermissions::enabled()) {
Expand Down Expand Up @@ -325,7 +322,7 @@ public function resendRegistrationEmail($userId)
private function getGroupPermissionMapping()
{
if (config('twill.enabled.permissions-management')) {
return Group::with('permissions')->get()
return twillModel('group')::with('permissions')->get()
->mapWithKeys(function ($group) {
return [$group->id => $group->permissions];
})->toArray();
Expand All @@ -338,7 +335,7 @@ private function getGroups()
{
if (config('twill.enabled.permissions-management')) {
// Forget first one because it's the "Everyone" group and we don't want to show it inside admin.
return Group::with('permissions')->pluck('name', 'id')->forget(1);
return twillModel('group')::with('permissions')->pluck('name', 'id')->forget(1);
}

return [];
Expand All @@ -347,7 +344,7 @@ private function getGroups()
private function getRoleList()
{
if (config('twill.enabled.permissions-management')) {
return Role::accessible()->published()->get()->map(function ($role) {
return twillModel('role')::accessible()->published()->get()->map(function ($role) {
return ['value' => $role->id, 'label' => $role->name];
})->toArray();
}
Expand Down
8 changes: 3 additions & 5 deletions src/Http/Requests/Admin/UserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace A17\Twill\Http\Requests\Admin;

use A17\Twill\Models\Role;
use A17\Twill\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;
use PragmaRX\Google2FA\Google2FA;
Expand Down Expand Up @@ -58,7 +56,7 @@ public function rules(): array
}
},
'force-2fa-disable-challenge' => function ($attribute, $value, $fail) {
$user = User::findOrFail($this->route('user'));
$user = twillModel('user')::findOrFail($this->route('user'));
if ($this->get('google_2fa_enabled') || ! $user->google_2fa_enabled) {
return;
}
Expand Down Expand Up @@ -95,12 +93,12 @@ private function getRoleValidator($baseRule = [])
{
if (config('twill.enabled.permissions-management')) {
// Users can't assign roles above their own
$accessibleRoleIds = Role::accessible()->pluck('id')->toArray();
$accessibleRoleIds = twillModel('role')::accessible()->pluck('id')->toArray();
$baseRule[] = Rule::in($accessibleRoleIds);
} else {
$baseRule[] = 'not_in:SUPERADMIN';
}

return [User::getRoleColumnName() => $baseRule];
return [twillModel('user')::getRoleColumnName() => $baseRule];
}
}
2 changes: 1 addition & 1 deletion src/Models/Revision.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(array $attributes = [])

public function user()
{
return $this->belongsTo(User::class);
return $this->belongsTo(twillModel('user'));
}

public function getByUserAttribute()
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function scopeOnlyTrashed($query): Builder

public function users(): HasMany
{
return $this->hasMany(User::class);
return $this->hasMany(twillModel('user'));
}

public function getCreatedAtAttribute($value): string
Expand Down
4 changes: 2 additions & 2 deletions src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function sendPasswordResetByAdminNotification($password)

public function groups()
{
return $this->belongsToMany(Group::class, 'group_twill_user', 'twill_user_id', 'group_id');
return $this->belongsToMany(twillModel('group'), 'group_twill_user', 'twill_user_id', 'group_id');
}

public function publishedGroups()
Expand All @@ -254,7 +254,7 @@ public function publishedGroups()

public function role()
{
return $this->belongsTo(Role::class);
return $this->belongsTo(twillModel('role'));
}

public function allPermissions()
Expand Down
3 changes: 1 addition & 2 deletions src/Models/UserOauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace A17\Twill\Models;

use A17\Twill\Models\User;
use Illuminate\Database\Eloquent\Model as BaseModel;

class UserOauth extends BaseModel
Expand All @@ -24,6 +23,6 @@ public function __construct(array $attributes = [])

public function user()
{
$this->belongsTo(User::class, 'user_id');
$this->belongsTo(twillModel('user'), 'user_id');
}
}
6 changes: 3 additions & 3 deletions src/Repositories/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use A17\Twill\Facades\TwillPermissions;
use A17\Twill\Models\Contracts\TwillModelContract;
use A17\Twill\Models\User;
use A17\Twill\Models\Group;
use A17\Twill\Repositories\Behaviors\HandleMedias;
use A17\Twill\Repositories\Behaviors\HandleOauth;
use A17\Twill\Repositories\Behaviors\HandleUserPermissions;
Expand Down Expand Up @@ -79,10 +78,11 @@ public function getFormFieldsForBrowser(
$browserFields = parent::getFormFieldsForBrowser($object, $relation, $routePrefix, $titleKey, $moduleName);

if (TwillPermissions::enabled()) {
$everyoneGroup = twillModel('group')::getEveryoneGroup();
foreach ($browserFields as $index => $browserField) {
if (
$browserField['id'] === Group::getEveryoneGroup()->id &&
$browserField['name'] === Group::getEveryoneGroup()->name
$browserField['id'] === $everyoneGroup->id &&
$browserField['name'] === $everyoneGroup->name
) {
$browserFields[$index]['edit'] = false;
$browserFields[$index]['deletable'] = false;
Expand Down
2 changes: 1 addition & 1 deletion src/TwillServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class TwillServiceProvider extends ServiceProvider
*
* @var string
*/
public const VERSION = '3.1.0';
public const VERSION = '3.2.1';

/**
* Service providers to be registered.
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit 60fcf11

Please sign in to comment.