Skip to content

Commit

Permalink
Merge branch 'release/0.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
hafijul233 committed Nov 8, 2021
2 parents 0ab8e54 + 5ccfe89 commit 3ded5df
Show file tree
Hide file tree
Showing 31 changed files with 758 additions and 312 deletions.
2 changes: 1 addition & 1 deletion Database/Seeders/RoleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Modules\Admin\Models\Authorization\Role;
use Modules\Admin\Models\Rbac\Role;

class RoleSeeder extends Seeder
{
Expand Down
79 changes: 33 additions & 46 deletions Http/Controllers/Rbac/RoleController.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<?php

namespace Modules\Backend\Http\Controllers\Authorization;
namespace Modules\Admin\Http\Controllers\Rbac;

use App\Http\Controllers\Controller;
use App\Services\Auth\AuthenticatedSessionService;
use Modules\Backend\Services\Authorization\PermissionService;
use Modules\Backend\Services\Authorization\RoleService;
use Modules\Backend\Services\Authorization\UserService;
use Exception;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Rbac\Http\Requests\RoleRequest;
use Modules\Admin\Http\Requests\Rbac\RoleRequest;
use Modules\Admin\Services\Rbac\RoleService;
use Modules\Core\Services\Auth\AuthenticatedSessionService;
use Modules\Core\Supports\Constant;
use Throwable;

class RoleController extends Controller
Expand All @@ -23,10 +22,6 @@ class RoleController extends Controller
*/
private $roleService;

/**
* @var PermissionService
*/
private $permissionService;
/**
* @var AuthenticatedSessionService
*/
Expand All @@ -37,14 +32,11 @@ class RoleController extends Controller
*
* @param AuthenticatedSessionService $authenticatedSessionService
* @param RoleService $roleService
* @param PermissionService $permissionService
*/
public function __construct(AuthenticatedSessionService $authenticatedSessionService,
RoleService $roleService,
PermissionService $permissionService)
RoleService $roleService)
{
$this->roleService = $roleService;
$this->permissionService = $permissionService;
$this->authenticatedSessionService = $authenticatedSessionService;
}

Expand All @@ -59,7 +51,7 @@ public function index(Request $request)
$filters = $request->except('_token');
$roles = $this->roleService->rolePaginate($filters);

return view('backend::role.index', [
return view('admin::rbac.role.index', [
'roles' => $roles
]);
}
Expand All @@ -71,11 +63,8 @@ public function index(Request $request)
*/
public function create()
{
$permissions = $this->permissionService->getAllPermissions();

return view('backend::role.create', [
'permissions' => $permissions
]);
return view('admin::rbac.role.create');
}

/**
Expand All @@ -87,14 +76,14 @@ public function create()
*/
public function store(RoleRequest $request): RedirectResponse
{
$inputs = $request->except('_token');
$confirm = $this->roleService->storeRole($request->except('_token'));

if ($this->roleService->storeRole($inputs)) {
toastr('New Role Created', 'success', 'Notification');
return redirect()->route('roles.index');
if ($confirm['status'] == true) {
notify($confirm['message'], $confirm['level'], $confirm['title']);
return redirect()->route('admin.roles.index');
}

toastr('Role Creation Failed', 'error', 'Alert');
notify($confirm['message'], $confirm['level'], $confirm['title']);
return redirect()->back()->withInput();
}

Expand All @@ -109,12 +98,12 @@ public function show(int $id)
{
$withTrashed = false;

if (\request()->has('with') && \request()->get('with') == \Constant::PURGE_MODEL_QSA) {
if (request()->has('with') && request()->get('with') == Constant::PURGE_MODEL_QSA) {
$withTrashed = true;
}

if ($role = $this->roleService->getRoleById($id, $withTrashed)) {
return view('backend::role.show', [
return view('admin::rbac.role.show', [
'role' => $role
]);
}
Expand All @@ -131,16 +120,15 @@ public function show(int $id)
*/
public function edit($id)
{
if ($role = $this->roleService->getRoleById($id)) {
$withTrashed = false;

$permissions = $this->permissionService->getAllPermissions();
$role_permissions = $role->permissions()->pluck('id')->toArray() ?? [];
if (request()->has('with') && request()->get('with') == Constant::PURGE_MODEL_QSA) {
$withTrashed = true;
}

return view('backend::role.edit', [
'role' => $role,
'permissions' => $permissions,
'role_permissions' => $role_permissions
]);
if ($role = $this->roleService->getRoleById($id, $withTrashed)) {

return view('admin::rbac.role.edit', ['role' => $role]);
}

abort(404);
Expand All @@ -156,14 +144,14 @@ public function edit($id)
*/
public function update(RoleRequest $request, $id): RedirectResponse
{
$inputs = $request->except('_token', 'submit', '_method');
$confirm = $this->roleService->updateRole($request->except('_token', 'submit', '_method'), $id);

if ($this->roleService->updateRole($inputs, $id)) {
toastr('Role Information Updated', 'success', 'Notification');
return redirect()->route('roles.index');
if ($confirm['status'] == true) {
notify($confirm['message'], $confirm['level'], $confirm['title']);
return redirect()->route('admin.roles.index');
}

toastr('Role Information Update Failed', 'error', 'Alert');
notify($confirm['message'], $confirm['level'], $confirm['title']);
return redirect()->back()->withInput();
}

Expand All @@ -175,18 +163,17 @@ public function update(RoleRequest $request, $id): RedirectResponse
* @return RedirectResponse
* @throws Throwable
*/
public function destroy($id, Request $request): RedirectResponse
public function destroy($id, Request $request)
{
if ($this->authenticatedSessionService->verifyUser($request)) {

if ($this->roleService->destroyRole($id)) {
toastr('Role Deleted', 'success', 'Notification');
$confirm = $this->roleService->destroyRole($id);
if ($confirm['status'] == true) {
notify($confirm['message'], $confirm['level'], $confirm['title']);
} else {
toastr('Role Removal Failed', 'error', 'Alert');
notify($confirm['message'], $confirm['level'], $confirm['title']);
}
return redirect()->route('roles.index');
return redirect()->route('admin.roles.index');
}

abort(403, 'Wrong user credentials');
}
}
5 changes: 3 additions & 2 deletions Http/Requests/Rbac/RoleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class RoleRequest extends FormRequest
*/
public function authorize(): bool
{
return request()->user()->can('roles.store') ||
request()->user()->can('roles.update');
/*return request()->user()->can('roles.store') ||
request()->user()->can('roles.update');*/
return true;
}

/**
Expand Down
20 changes: 13 additions & 7 deletions Models/Rbac/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Modules\Admin\Models\Rbac;

use Modules\Backend\Models\Authentication\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;
use Kyslik\ColumnSortable\Sortable;
use Modules\Core\Models\User;
use OwenIt\Auditing\Auditable as AuditableTrait;
use OwenIt\Auditing\Contracts\Auditable;
use Spatie\Permission\Models\Role as SpatieRole;
Expand Down Expand Up @@ -96,11 +96,17 @@ public function deletedBy(): BelongsTo
*/
public function getTotalPermissionsAttribute(): int
{
return $this->belongsToMany(
config('permission.models.permission'),
config('permission.table_names.role_has_permissions'),
'role_id',
'permission_id'
)->count();
return $this->permissions->count();
}

/**
* Count Total User Assigned to this role
*
* @return int
*/
public function getTotalUsersAttribute(): int
{
return $this->users->count();
}

}
3 changes: 3 additions & 0 deletions Providers/HtmlServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,8 @@ public function boot()

//Dropdown
Html::component('actionDropdown', 'admin::htmls.action-dropdowns', ['resourceRouteName', 'id', 'options' => []]);

//Selection
Html::component('selection', 'admin::htmls.selection', ['target']);
}
}
6 changes: 3 additions & 3 deletions Repositories/Eloquent/Rbac/RoleRepository.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php


namespace Modules\Backend\Repositories\Eloquent\Authorization;
namespace Modules\Admin\Repositories\Eloquent\Rbac;


use Modules\Rbac\Models\Role;
use App\Repositories\EloquentRepository;
use Exception;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Modules\Admin\Models\Rbac\Role;
use Modules\Core\Repositories\EloquentRepository;

class RoleRepository extends EloquentRepository
{
Expand Down
17 changes: 2 additions & 15 deletions Resources/assets/js/utility.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function initDeleteModal() {
* Modal Status Update
*/

/*function toggleEnabledStatus() {
function toggleEnabledStatus() {
$(".toggle-class").change(function () {
var toggle = $(this);

Expand All @@ -49,7 +49,7 @@ function initDeleteModal() {
}
}, "json");
});
}*/
}

/**
* mark search keyword in table
Expand Down Expand Up @@ -331,18 +331,5 @@ if (typeof $.validator === 'function') {
}

$(document).ready(function () {

initDeleteModal();

$("#select-all-checkbox").click(function () {
$(".mark-checkbox").each(function () {
$(this).prop("checked", true);
});
});

$("#unselect-all-checkbox").click(function () {
$(".mark-checkbox").each(function () {
$(this).prop("checked", false);
});
});
});
82 changes: 82 additions & 0 deletions Resources/plugins/bootstrap4-toggle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

## [3.7.0](https://github.com/gitbrent/bootstrap4-toggle/tree/v3.7.0) 2019-??-??
### [Full Changelog](https://github.com/gitbrent/bootstrap4-toggle/compare/v3.6.0...v3.7.0)

## [3.6.0](https://github.com/gitbrent/bootstrap4-toggle/tree/v3.6.0) 2019-10-17
### [Full Changelog](https://github.com/gitbrent/bootstrap4-toggle/compare/v3.5.0...v3.6.0)
### Added
- Added option to change toggle without triggering onChange event (silent toggle) [\#7](https://github.com/gitbrent/bootstrap4-toggle/issue/7) ([aswin1980](https://github.com/aswin1980))
- Added accessibility properties to labels [\#11](https://github.com/gitbrent/bootstrap4-toggle/issue/11) ([aproquot](https://github.com/aproquot))
### Changed
- Fixed URLs in js and css file top comment [\#5](https://github.com/gitbrent/bootstrap4-toggle/issue/5) ([wilecoyte78](https://github.com/wilecoyte78))
- Disable style is not working [\#18](https://github.com/gitbrent/bootstrap4-toggle/issue/18) ([rychlym](https://github.com/rychlym))

## [3.5.0](https://github.com/gitbrent/bootstrap4-toggle/tree/v3.5.0) 2019-07-02
### [Full Changelog](https://github.com/gitbrent/bootstrap4-toggle/compare/v3.4.0...v3.5.0)
### Added
- Added ARIA `role="button"` tag to toggle
- Added `cursor: pointer;` style to toggle
### Changed
- Fixed: Touch not working on mobile [\#2](https://github.com/gitbrent/bootstrap4-toggle/issue/2) ([wilecoyte78](https://github.com/wilecoyte78))
- Updated to Bootstrap version 4.3.1
- Updated README with better Yarn instructions

## [3.4.0](https://github.com/gitbrent/bootstrap4-toggle/tree/v3.4.0) 2019-01-03
### [Full Changelog](https://github.com/gitbrent/bootstrap4-toggle/compare/v3.3.0...v3.4.0)
### Added
- Outline button styles are now available
### Changed
- Updated to Bootstrap version 4.2.1

## [3.3.0](https://github.com/gitbrent/bootstrap4-toggle/tree/v3.3.0) 2018-12-19
### [Full Changelog](https://github.com/gitbrent/bootstrap4-toggle/compare/v3.2.0...v3.3.0)
### Added
- New test created to compare core bootstrap sizes to bootstrap4-toggle
### Changed
- Introduced new `size` values that mirror bootstrap 4: (`lg`, `sm`, `xs`)
- Converted all css units from `px` to `rem`
- Properly added border on `light` button (moved from .toggle class)
### Removed
**DEPRECATED** Classic `size` values (`large`, `small`, `mini`)


## [3.2.0](https://github.com/gitbrent/bootstrap4-toggle/tree/v3.2.0) 2018-11-27
### [Full Changelog](https://github.com/gitbrent/bootstrap4-toggle/compare/v3.1.0...v3.2.0)
### Added
### Changed
- Removed permanent `active` state from "Off" label so mouse-over highlighting works the same as "On"
### Removed



## [3.1.0](https://github.com/gitbrent/bootstrap4-toggle/tree/v3.1.0) 2018-10-25
### [Full Changelog](https://github.com/gitbrent/bootstrap4-toggle/compare/v3.0.0...v3.1.0)
### Added
- `index.html` includes new section with dark mode colors
### Changed
- `index.html` now fully responsive, better menu, rearranged sections
- Tweaked `border` property to work with all backgrounds and colors
### Removed



## [3.0.0](https://github.com/gitbrent/bootstrap4-toggle/tree/v3.0.0) 2018-10-21
### [Full Changelog](https://github.com/gitbrent/bootstrap4-toggle/compare/v2.2.2...v3.0.0)
### Added
- Touch support
### Changed
- Implements Bootstrap 4 colors/styles
### Removed
- Old Bootstrap 2 files

[Unreleased]: https://github.com/gitbrent/bootstrap4-toggle/compare/v1.9.0...HEAD
[3.2.0]: https://github.com/gitbrent/bootstrap4-toggle/compare/v3.1.0...v3.2.0
[3.1.0]: https://github.com/gitbrent/bootstrap4-toggle/compare/v3.0.0...v3.1.0
[3.0.0]: https://github.com/gitbrent/bootstrap4-toggle/compare/v2.2.2...v3.0.0
Loading

0 comments on commit 3ded5df

Please sign in to comment.