Skip to content

Commit

Permalink
Update: Various corrections,improvements and filesystems cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Todd Cytra committed Jan 21, 2024
1 parent 2856e86 commit 29e23b1
Show file tree
Hide file tree
Showing 25 changed files with 215 additions and 353 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Release Notes

2024-01-21 : 0.3.6
Update: Security update for axios,vite; Other minor updates

- Added service provider macros to handle model tracking columns
- Corrected issue in the MenuBuilder when submenus are defined
- Corrected issue preventing user changing password
- Force box-shadow to inset in the page action buttons
- Provided means of adding route parameter through ActionBuilder
- Updated axios package for newest follow-redirects package
- Updated vite package to patch server.fs.deny bypass issue

---

2023-12-14 : 0.3.5
Update: Cleanup,improvements in the user actions system

Expand Down
9 changes: 9 additions & 0 deletions app/Enums/FileTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace App\Enums;

use Enraiged\Enums\FileTypes as Enum;

class FileTypes extends Enum
{
}
29 changes: 22 additions & 7 deletions app/Http/Requests/Auth/LoginRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public function rules()
}

/**
* Execute the attempt to authenticate the request's credentials.
* Prepare the credentials form authentication attempts.
*
* @return boolean
* @return bool
*/
private function attempt()
private function attempt(): bool
{
$primary_credentials = collect($this->only('email', 'password'))
->merge(['is_active' => true])
Expand All @@ -50,13 +50,28 @@ private function attempt()
->except('email')
->toArray();

return Auth::attempt($primary_credentials, $this->boolean('remember'))
|| (config('enraiged.auth.allow_secondary_credential') === true
&& Auth::attempt($secondary_credentials, $this->boolean('remember')));
$allow_secondary_credentials = config('enraiged.auth.allow_secondary_credential') === true;

return $this->attemptLoginWith($primary_credentials)
|| ($allow_secondary_credentials && $this->attemptLoginWith($secondary_credentials));
}

/**
* Execute an attempt to authenticate the provided credentials.
*
* @param array $credentials
* @param bool $validate_company = false
* @return bool
*/
private function attemptLoginWith($credentials, $validate_company = false): bool
{
return $validate_company
? Auth::attemptWhen($credentials, fn ($user) => $user->company->is_active, $this->boolean('remember'))
: Auth::attempt($credentials, $this->boolean('remember'));
}

/**
* Prepare for and handle the attempt to authenticate the request's credentials.
* Handle the attempt to authenticate the request's credentials.
*
* @return void
*
Expand Down
3 changes: 2 additions & 1 deletion database/seeders/UserSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function run()
'name' => env('ADMIN_NAME', 'Application Administrator'),
'password' => env('ADMIN_PASSWORD', $this->insecure_password),
'role' => 'Administrator',
'timezone' => config('enraiged.app.timezone'),
'username' => env('ADMIN_USERNAME', 'administrator'),
];

Expand Down Expand Up @@ -81,7 +82,7 @@ protected function createFactoryUser(array $parameters): User

$user = User::factory()->create(
collect($parameters)
->merge(['profile_id' => $profile->id])
->merge(['profile_id' => $profile->id, 'timezone' => config('enraiged.app.timezone')])
->toArray()
);

Expand Down
2 changes: 1 addition & 1 deletion packages/enraiged/src/Images/Models/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Enraiged\Images\Models;

use App\Enums\FileTypes;
use Enraiged\Enums\FileTypes;
use Enraiged\Files\Traits\Attachable;
use Enraiged\Support\Database\Traits\Created;
use Enraiged\Support\Database\Traits\Updated;
Expand Down
3 changes: 2 additions & 1 deletion packages/enraiged/src/Profiles/Models/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ public function getFillable()
'first_name',
'last_name',
'gender',
'phone',
'salut',
'title'
'title',
];
}
}
2 changes: 1 addition & 1 deletion packages/enraiged/src/Roles/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Role extends Model
public $timestamps = false;

/** @var array The attributes that aren't mass assignable. */
protected $guarded = [];
protected $guarded = ['id', 'rank'];

/**
* Find a role by its id or name.
Expand Down
11 changes: 11 additions & 0 deletions packages/enraiged/src/Support/Builders/Security/AssertSecure.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@

namespace Enraiged\Support\Builders\Security;

use Enraiged\Enums\Roles;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;

trait AssertSecure
{
/**
* Assert a user is authenticated.
*
* @return bool
*/
protected function assertIsAdministrator(): bool
{
return Auth::check() && Auth::user()->role->is(Roles::Administrator);
}

/**
* Assert a user is authenticated.
*
Expand Down
4 changes: 3 additions & 1 deletion packages/enraiged/src/Users/Actions/Builders/UserActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public function preprocess(RequestCollection $request, $item, $index): array
$item['confirm'] = __('Warning! This cannot be undone. Are you certain you want to delete your account?');
}

$classes = explode(' ', $item['class']);
$classes = key_exists('class', $item)
? explode(' ', $item['class'])
: [];

if (key_exists('severity', $item) && in_array($index, ['delete', 'restore'])) {
$classes[] = 'p-button-'.$item['severity'];
Expand Down
7 changes: 7 additions & 0 deletions packages/enraiged/src/Users/Forms/Validation/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Enraiged\Users\Forms\Validation;

use Enraiged\Enums\Roles;
use Illuminate\Support\Collection;

trait Rules
Expand Down Expand Up @@ -34,6 +35,12 @@ trait Rules
*/
public function rules()
{
if (!$this->user()->role->atLeast(Roles::Administrator)) {
$this->rules = collect($this->rules)
->except(['role_id'])
->toArray();
}

if ($this->route()->hasParameter('attribute')) {
return $this
->uniqueUserRules()
Expand Down
16 changes: 16 additions & 0 deletions packages/enraiged/src/Users/Models/Traits/HasContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public function getIsActiveAttribute(): bool
return $this->attributes['is_active'] === 1;
}

/**
* @return bool
*/
public function getIsDeletedAttribute(): bool
{
return !is_null($this->deleted_at);
}

/**
* @return bool
*/
Expand All @@ -47,6 +55,14 @@ public function getIsMyselfAttribute(): bool
return $this->id === Auth::id();
}

/**
* @return bool
*/
public function getIsNotMyselfAttribute(): bool
{
return !$this->isMyself;
}

/**
* @return bool
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Enraiged\Users\Services;
namespace Enraiged\Users\Services\Support;

use Enraiged\Roles\Models\Role;
use Enraiged\Support\Services\AttributeHandler;
Expand Down
2 changes: 1 addition & 1 deletion packages/enraiged/src/Users/Services/UpdateUserProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class UpdateUserProfile
public function __construct(User $user, array $attributes)
{
$this->user = $user;
$this->attributes = UserProfileAttributes::from($attributes)->toArray();
$this->attributes = Support\UserProfileAttributes::from($attributes)->toArray();
}

/**
Expand Down
10 changes: 5 additions & 5 deletions packages/enraiged/src/Users/Tables/Resources/IndexResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

class IndexResource extends UserResource
{
/** @var bool Whether or not to include the role with this resource. */
protected $with_role = false;

/** @var bool Whether or not to include the deleted at,by with this resource. */
protected $deleted = true;
protected bool $with_deleted = false;

/** @var bool Whether or not to include the role with this resource. */
protected bool $with_role = false;

/** @var bool Whether or not to include a severity level. */
protected $severity = true;
protected bool $with_severity = false;

/**
* Transform the resource collection into an array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"impersonate": {
"class": "p-button-secondary",
"icon": "pi pi-sync",
"icon": "pi pi-user",
"secure": {"method": "isNotDeleted"},
"tooltip": "Impersonate",
"type": "row"
Expand Down
1 change: 0 additions & 1 deletion resources/js/components/tables/VueTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ export default {
methods: {
async fetch() {
console.log('fetch')
this.loading = true;
return this.axios.get(this.template.uri, { params: this.params() })
.then(response => this.fetched(response))
Expand Down
120 changes: 120 additions & 0 deletions resources/js/components/ui/actions/RowActions.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<template>
<div class="actions flex">
<span class="action" v-for="(action, index) in actions" :key="index">
<primevue-button class="p-button-rounded p-button-sm p-button-text"
:class="action.class"
:disabled="action.disabled || disabled"
:icon="action.icon"
:key="index"
v-tooltip.top="i18n(action.tooltip || index)"
@click="actionHandler(action, index)"/>
</span>
</div>
</template>

<script>
import PrimevueButton from 'primevue/button/Button.vue';
import PrimevueTooltip from 'primevue/tooltip/tooltip.esm.js';
export default {
components: {
PrimevueButton,
},
directives: {
tooltip: PrimevueTooltip,
},
inject: [
'back',
'errorHandler',
'flash',
'flashSuccess',
'i18n',
'isSuccess',
'initState',
'meta',
],
props: {
actions: {
type: Object,
required: true,
},
disabled: {
type: Boolean,
default: false,
},
},
methods: {
actionHandler(action, index, confirmed) {
if (typeof action.uri === 'object') {
const method = typeof action.uri.method !== 'undefined'
? action.uri.method
: 'get';
if (action.confirm && confirmed !== true) {
this.$confirm.require({
message: typeof action.confirm === 'string'
? this.i18n(action.confirm)
: this.i18n('Are you sure you want to proceed?'),
header: this.i18n('Please confirm'),
icon: 'pi pi-exclamation-triangle',
acceptClass: 'p-button-danger',
acceptLabel: this.i18n('Yes'),
rejectLabel: this.i18n('No'),
accept: () => this.actionHandler(action, index, true),
});
} else if (typeof action.method !== 'undefined' && action.method === 'emit') {
const emit = action.emit || `action:${index}`;
this.$emit(emit, action);
} else if (typeof action.uri.api !== 'undefined' && action.uri.api === true) {
this.axios[method](action.uri.route)
.then(({ data, status }) => {
if (this.isSuccess(status)) {
if (action.emit) {
this.$emit('action', action);
}
if (data.success) {
this.flashSuccess(data.success);
} else
if (data.message) {
this.flash(data.message);
}
if (status === 205) {
this.initState();
}
if (data.redirect) {
this.$inertia.get(data.redirect);
} else
if (action.uri.redirect) {
if (action.uri.redirect === 'back') {
this.back();
}
if (action.uri.redirect === 'default') {
this.actionHandler(this.default);
}
//if (action.uri.redirect.match(/[a-z]+/)) {
//
//}
}
}
})
.catch((error) => this.errorHandler(error));
}
} else {
if (action.emit) {
this.$emit('action', action);
}
if (typeof action.uri === 'string') {
this.$inertia.get(action.uri);
}
}
},
},
};
</script>
Loading

0 comments on commit 29e23b1

Please sign in to comment.