Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sampoyigi committed Oct 15, 2021
2 parents 8960d1e + d227ec6 commit 9e1491f
Show file tree
Hide file tree
Showing 60 changed files with 1,048 additions and 715 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
max-parallel: 6
matrix:
# os: [ubuntu-latest, windows-latest]
php: ['7.3', '7.4']
php: ['7.4', '8.0']
db: ['mysql:5.7', mariadb]
include:
- db: 'mysql:5.7'
Expand Down
17 changes: 16 additions & 1 deletion app/admin/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Admin\Classes\Navigation;
use Admin\Classes\OnboardingSteps;
use Admin\Classes\PermissionManager;
use Admin\Classes\UserState;
use Admin\Classes\Widgets;
use Admin\Facades\AdminLocation;
use Admin\Facades\AdminMenu;
Expand All @@ -13,6 +14,7 @@
use Igniter\Flame\Foundation\Providers\AppServiceProvider;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Event;
use System\Classes\MailManager;
use System\Libraries\Assets;
Expand Down Expand Up @@ -278,7 +280,20 @@ protected function registerMainMenuItems()
'user' => [
'type' => 'partial',
'path' => 'top_nav_user_menu',
'markAsRead' => ['Admin\Classes\Location', 'setStaffCurrent'],
'options' => ['Admin\Classes\UserPanel', 'listMenuLinks'],
],
]);
});

Event::listen('admin.menu.extendUserMenuLinks', function (Collection $items) {
$items->put('userState', [
'priority' => 10,
'label' => 'admin::lang.text_set_status',
'iconCssClass' => 'fa fa-circle fa-fw text-'.UserState::forUser()->getStatusColorName(),
'attributes' => [
'data-toggle' => 'modal',
'data-target' => '#editStaffStatusModal',
'role' => 'button',
],
]);
});
Expand Down
15 changes: 9 additions & 6 deletions app/admin/assets/css/admin.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@charset "UTF-8";
/*!
* Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
*/
@charset "UTF-8";
.fa, .fas, .far, .fa-star-o, .fal, .fad, .fab {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
Expand Down Expand Up @@ -10755,12 +10755,12 @@ a.btn.disabled, fieldset:disabled a.btn {
}
.btn-info:hover {
color: #FFFFFF;
background-color: #3b4bd1;
background-color: #3b4ad1;
border-color: #3141ce;
}
.btn-info:focus, .btn-info.focus {
color: #FFFFFF;
background-color: #3b4bd1;
background-color: #3b4ad1;
border-color: #3141ce;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 1px 1px rgba(0, 3, 41, 0.075) 0 0 0 0.2rem rgba(115, 126, 222, 0.5);
}
Expand Down Expand Up @@ -16561,7 +16561,7 @@ a.text-success:hover, a.panel-success:hover, a.text-success:focus, a.panel-succe
color: #5A67D8 !important;
}
a.text-info:hover, a.panel-info:hover, a.text-info:focus, a.panel-info:focus {
color: #2c3bba !important;
color: #2c3aba !important;
}
.text-warning, .panel-warning {
color: #FD7E14 !important;
Expand Down Expand Up @@ -18317,12 +18317,12 @@ body.dragging .dragged {
}
.toolbar-action .btn-info:hover {
color: #FFFFFF;
background-color: #3b4bd1;
background-color: #3b4ad1;
border-color: #3141ce;
}
.toolbar-action .btn-info:focus, .toolbar-action .btn-info.focus {
color: #FFFFFF;
background-color: #3b4bd1;
background-color: #3b4ad1;
border-color: #3141ce;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 1px 1px rgba(0, 3, 41, 0.075) 0 0 0 0.2rem rgba(133, 143, 171, 0.5);
}
Expand Down Expand Up @@ -18735,6 +18735,9 @@ body.dragging .dragged {
.toolbar-action .btn-outline-white:not(:disabled):not(.disabled):active:focus, .toolbar-action .btn-outline-white:not(:disabled):not(.disabled).active:focus, .show > .toolbar-action .btn-outline-white.dropdown-toggle:focus {
box-shadow: 0 0 0 0.2rem rgba(111, 123, 156, 0.5);
}
.toolbar-search {
background-color: #D2D4DF;
}
.list-table .table thead, .list-table .markdown table thead, .markdown .list-table table thead {
position: relative;
}
Expand Down
4 changes: 2 additions & 2 deletions app/admin/assets/scss/components/_marketplace.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}

.fa-icon {
top: 12px;
top: 15px;
right: 15px;
position: absolute;
}
Expand Down Expand Up @@ -126,4 +126,4 @@
.card.disabled {
background-color: $gray-300;
}
}
}
3 changes: 3 additions & 0 deletions app/admin/assets/scss/components/_toolbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,6 @@
}
}
}
.toolbar-search {
background-color: $gray-300;
}
10 changes: 10 additions & 0 deletions app/admin/classes/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ public function pageAction()
$this->execPageAction($this->action, $this->params);
}

public function getClass()
{
return $this->class;
}

public function getAction()
{
return $this->action;
}

protected function execPageAction($action, $params)
{
$result = null;
Expand Down
5 changes: 5 additions & 0 deletions app/admin/classes/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public function getId()
return optional($this->getLocation())->getKey();
}

public function getName()
{
return optional($this->getLocation())->location_name;
}

public function getAll()
{
if ($this->getAuth()->isSuperUser())
Expand Down
10 changes: 6 additions & 4 deletions app/admin/classes/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function register(array $attributes, $activate = FALSE)
{
$model = $this->createModel();

$staff = $model->staff()->newInstance();
$staff = $model->staff()->getModel()->newInstance();
$staff->staff_email = $attributes['staff_email'];
$staff->staff_name = $attributes['staff_name'];
$staff->language_id = $attributes['language_id'] ?? null;
Expand All @@ -102,9 +102,11 @@ public function register(array $attributes, $activate = FALSE)

$staff->save();

if ($staff->groups->isEmpty())
$staff->groups()->attach($attributes['groups']);
$staff->groups()->attach($attributes['groups']);

return $model;
if (array_key_exists('locations', $attributes))
$staff->locations()->attach($attributes['locations']);

return $staff->reload()->user;
}
}
116 changes: 116 additions & 0 deletions app/admin/classes/UserPanel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

namespace Admin\Classes;

use Admin\Facades\AdminAuth;
use Admin\Facades\AdminLocation;
use Illuminate\Support\Facades\Event;

/**
* Admin User Panel
*/
class UserPanel
{
protected $user;

protected $location;

protected static $menuLinksCache = [];

public static function forUser($user = null, $location = null)
{
$instance = new static;
$instance->user = $user ?: AdminAuth::getUser();
$instance->location = $location ?: AdminLocation::current();

return $instance;
}

public static function listMenuLinks($menu, $item, $user)
{
if (self::$menuLinksCache)
return self::$menuLinksCache;

$items = collect([
'account' => [
'label' => 'admin::lang.text_edit_details',
'iconCssClass' => 'fa fa-user fa-fw',
'url' => admin_url('staffs/account'),
'priority' => 20,
],
'logout' => [
'label' => 'admin::lang.text_logout',
'cssClass' => 'text-danger',
'iconCssClass' => 'fa fa-power-off fa-fw',
'url' => admin_url('logout'),
],
]);

Event::fire('admin.menu.extendUserMenuLinks', [$items]);

$instance = self::forUser();

return self::$menuLinksCache = $items
->mapWithKeys(function ($item, $code) {
$item = array_merge([
'priority' => 999,
'label' => null,
'cssClass' => null,
'iconCssClass' => null,
'attributes' => [],
'permission' => null,
], $item);

if (array_key_exists('url', $item)) {
$item['attributes']['href'] = $item['url'];
}

return [
$code => (object)$item,
];
})
->filter(function ($item) use ($instance) {
if (!$permission = array_get($item, 'permission'))
return TRUE;

return $instance->user->hasPermission($permission);
})
->sortBy('priority');
}

public function getUserName()
{
return $this->user->staff->staff_name;
}

public function getLocationName()
{
return optional($this->location)->location_name;
}

public function getAvatarUrl()
{
return $this->user->staff->avatar_url;
}

public function hasActiveLocation()
{
return AdminLocation::check();
}

public function listGroupNames()
{
return $this->user->staff->groups->pluck('staff_group_name')->all();
}

public function listLocations()
{
return AdminLocation::listLocations()->map(function ($value, $key) {
return (object)[
'id' => $key,
'name' => $value,
'active' => $key === optional($this->location)->location_id,
];
});
}
}
27 changes: 12 additions & 15 deletions app/admin/controllers/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,21 @@ public function onRequestResetPassword()
$data = post();

$this->validate($data, [
['email', 'lang:admin::lang.label_email', 'required|email:filter|max:96|exists:staffs,staff_email'],
['email', 'lang:admin::lang.label_email', 'required|email:filter|max:96'],
]);

$staff = Staffs_model::whereStaffEmail(post('email'))->first();
if (!$staff OR !$user = $staff->user)
throw new ValidationException(['email' => lang('admin::lang.login.alert_email_not_sent')]);

if (!$user->resetPassword())
throw new ValidationException(['email' => lang('admin::lang.login.alert_failed_reset')]);

$data = [
'staff_name' => $staff->staff_name,
'reset_link' => admin_url('login/reset?code='.$user->reset_code),
];

Mail::queue('admin::_mail.password_reset_request', $data, function ($message) use ($staff) {
$message->to($staff->staff_email, $staff->staff_name);
});
if ($staff AND $user = $staff->user) {
if (!$user->resetPassword())
throw new ValidationException(['email' => lang('admin::lang.login.alert_failed_reset')]);
$data = [
'staff_name' => $staff->staff_name,
'reset_link' => admin_url('login/reset?code='.$user->reset_code),
];
Mail::queue('admin::_mail.password_reset_request', $data, function ($message) use ($staff) {
$message->to($staff->staff_email, $staff->staff_name);
});
}

flash()->success(lang('admin::lang.login.alert_email_sent'));

Expand Down
2 changes: 1 addition & 1 deletion app/admin/formwidgets/Repeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ protected function processExistingItems()
}
}

protected function makeItemFormWidget($index = 0, $model)
protected function makeItemFormWidget($index, $model)
{
$data = null;
if (!$model instanceof Model) {
Expand Down
Loading

0 comments on commit 9e1491f

Please sign in to comment.