[WIP] Fix ergonomics rules
This commit is contained in:
66
app/Repositories/Core/Auth/NewUser.php
Normal file
66
app/Repositories/Core/Auth/NewUser.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\User\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class NewUser extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
$currentUser = \Auth::user();
|
||||
|
||||
return (new MailMessage())
|
||||
->markdown('notifications.email')
|
||||
->greeting(__('notifications.greeting', ['firstname' => $notifiable->first_name]))
|
||||
->subject(__('notifications.newuser.subject', ['name' => config('app.name')]))
|
||||
->line(__('notifications.newuser.intro', [
|
||||
'name' => $currentUser->first_name.' '.$currentUser->last_name,
|
||||
]))
|
||||
->action(
|
||||
__('notifications.newuser.button'),
|
||||
route('users.firstlogin', $notifiable->remember_token)
|
||||
)
|
||||
->salutation(__('notifications.salutation', [
|
||||
'name' => $currentUser->first_name.' '.$currentUser->last_name,
|
||||
]))
|
||||
->line(__('notifications.newuser.outro'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
85
app/Repositories/Core/Auth/Permissions.php
Normal file
85
app/Repositories/Core/Auth/Permissions.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Core\Auth\Permission;
|
||||
|
||||
class Permissions
|
||||
{
|
||||
public static function getModules()
|
||||
{
|
||||
return Permission::select('module')->distinct('module')->get()->pluck('module');
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Permission::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getInfo($id)
|
||||
{
|
||||
return Permission::find($id);
|
||||
}
|
||||
|
||||
public static function select_all()
|
||||
{
|
||||
return self::getAll()->toArray();
|
||||
}
|
||||
|
||||
public static function select_by_id($id)
|
||||
{
|
||||
return Permission::find($id)->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Permission::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getByName($name)
|
||||
{
|
||||
return Permission::where('name', $name)->first();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Permission::find($id);
|
||||
}
|
||||
|
||||
public static function getTable($id)
|
||||
{
|
||||
$datas = Permission::withCount(['users']);
|
||||
return Datatables::of($datas)->make(true);
|
||||
}
|
||||
|
||||
public static function delete($id)
|
||||
{
|
||||
Users::destroyByUniquePermission($id);
|
||||
return Permission::destroy($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
return (isset($data['id']) && $data['id']) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Permission::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return Permission::find($data['id'])->update($data);
|
||||
}
|
||||
|
||||
public static function count()
|
||||
{
|
||||
return Permission::count();
|
||||
}
|
||||
}
|
||||
31
app/Repositories/Core/Auth/ResetPassword.php
Normal file
31
app/Repositories/Core/Auth/ResetPassword.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\User\Notifications;
|
||||
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
|
||||
class ResetPassword extends \Illuminate\Auth\Notifications\ResetPassword
|
||||
{
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
/*
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
return (new MailMessage())
|
||||
->markdown('notifications.email')
|
||||
->greeting(__('notifications.greeting', ['firstname' => $notifiable->first_name]))
|
||||
->subject(__('notifications.resetpassword.subject'))
|
||||
->line(__('notifications.resetpassword.intro'))
|
||||
->action(
|
||||
__('notifications.resetpassword.button'),
|
||||
route('password.reset', $this->token)
|
||||
)
|
||||
->line(__('notifications.resetpassword.outro'));
|
||||
}
|
||||
*/
|
||||
}
|
||||
147
app/Repositories/Core/Auth/Roles.php
Normal file
147
app/Repositories/Core/Auth/Roles.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Core\Auth\Role;
|
||||
use App\Models\Core\Auth\RoleUser;
|
||||
|
||||
class Roles
|
||||
{
|
||||
use LaratrustUserTrait;
|
||||
|
||||
public static function store($input)
|
||||
{
|
||||
if (isset($input['id']) && $input['id']) {
|
||||
return self::update($input);
|
||||
} else {
|
||||
return self::insert($input);
|
||||
}
|
||||
}
|
||||
|
||||
// ajoute une forme juridique
|
||||
public static function insert($input)
|
||||
{
|
||||
$permissions = array_keys($input['permissions']);
|
||||
$name = $input['name'];
|
||||
$translated = $input['translated'];
|
||||
self::setTranslation($name, $translated);
|
||||
$role = Role::create(['name' => $name, 'display_name' => $name, 'translated' => $translated, 'description' => '', 'active' => true]);
|
||||
$role->attachPermissions($permissions);
|
||||
return $role;
|
||||
}
|
||||
|
||||
// met à jour les informations d'une forme juridique
|
||||
public static function update($input, $id = false)
|
||||
{
|
||||
$id = ($id) ? $id : $input['id'];
|
||||
$permissions = array_keys($input['permissions']);
|
||||
$name = $input['name'];
|
||||
$translated = $input['translated'];
|
||||
self::setTranslation($name, $translated);
|
||||
$role = Role::find($id);
|
||||
$role->update(['name' => $name, 'translated' => $translated]);
|
||||
$role->syncPermissions($permissions);
|
||||
return $role;
|
||||
}
|
||||
|
||||
// supprime une forme juridique
|
||||
public static function delete($id)
|
||||
{
|
||||
$old = self::select_by_id($id);
|
||||
self::deleteTranslation($old->translated);
|
||||
return Role::destroy($id);
|
||||
}
|
||||
|
||||
// met à jour le statut actif/inactif d'une forme juridique
|
||||
public static function toggle_active($id, $active)
|
||||
{
|
||||
return Role::find($id)->update(['active' => $active]);
|
||||
}
|
||||
|
||||
// compte le nombre de formes juridiques
|
||||
public static function count()
|
||||
{
|
||||
return Role::count();
|
||||
}
|
||||
|
||||
// récupère toutes les infos sur les formes juridiques
|
||||
public static function select_all()
|
||||
{
|
||||
return Role::all()->toArray();
|
||||
}
|
||||
|
||||
public static function select_by_id($id)
|
||||
{
|
||||
return Role::find($id)->toArray();
|
||||
}
|
||||
|
||||
public static function getWithPermissions($id)
|
||||
{
|
||||
$role = Role::find($id)->toArray();
|
||||
$role['permissions'] = Role::find($id)->permissions->pluck('id')->toArray();
|
||||
return $role;
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Role::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getByName($name)
|
||||
{
|
||||
return Role::where('name', $name)->first();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Role::find($id);
|
||||
}
|
||||
|
||||
public static function getTable($id)
|
||||
{
|
||||
$datas = Role::orderBy('name', 'asc');
|
||||
return Datatables::of($datas)->make(true);
|
||||
}
|
||||
|
||||
public static function getRolesByUser($user_id = false)
|
||||
{
|
||||
$user_id = $user_id ? $user_id : Users::getId();
|
||||
return RoleUser::byUser($user_id);
|
||||
}
|
||||
|
||||
public static function getUsersByRole($id)
|
||||
{
|
||||
return RoleUser::byTeam($id)->get();
|
||||
}
|
||||
|
||||
public static function getUsersIdByRole($id)
|
||||
{
|
||||
return self::getUsersByRole($id)->pluck('user_id');
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Role::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function setTranslation($name, $translated)
|
||||
{
|
||||
$lang = Translate::getLang();
|
||||
$appli = 1; // ContractDrive
|
||||
$client = 1; // Client
|
||||
Translations::setTranslation($name, $translated, $lang, $appli, $client);
|
||||
}
|
||||
|
||||
public static function deleteTranslation($translated)
|
||||
{
|
||||
$lang = Translate::getLang();
|
||||
$appli = 1; // ContractDrive
|
||||
$client = 1; // Client
|
||||
Translations::deleteTranslation($translated, $lang, $appli, $client);
|
||||
}
|
||||
}
|
||||
80
app/Repositories/Core/Auth/Teams.php
Normal file
80
app/Repositories/Core/Auth/Teams.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace App\Repositories\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
use Yajra\Datatables\Datatables;
|
||||
|
||||
use App\Models\Core\Auth\Team;
|
||||
use App\Models\Core\Auth\TeamUser;
|
||||
|
||||
use App\Repositories\Core\User\Users;
|
||||
|
||||
class Teams
|
||||
{
|
||||
use LaratrustUserTrait;
|
||||
|
||||
public static function getTeamsByUser($user_id = false)
|
||||
{
|
||||
$user_id = $user_id ? $user_id : Users::getId();
|
||||
return TeamUser::byUser($user_id);
|
||||
}
|
||||
|
||||
public static function getUsersByTeam($id)
|
||||
{
|
||||
return TeamUser::byTeam($id)->get();
|
||||
}
|
||||
|
||||
public static function getUsersIdByTeam($id)
|
||||
{
|
||||
return self::getUsersByTeam($id)->pluck('user_id');
|
||||
}
|
||||
|
||||
public static function getUsersByTeam2($id)
|
||||
{
|
||||
return Team::find($id)->users();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Team::get()->pluck('name', 'id');
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Team::find($id);
|
||||
}
|
||||
|
||||
public static function getTable($id)
|
||||
{
|
||||
$datas = Team::with(['societe'])->withCount(['users']);
|
||||
return Datatables::of($datas)->make(true);
|
||||
}
|
||||
|
||||
public static function delete($id)
|
||||
{
|
||||
Users::destroyByUniqueTeam($id);
|
||||
return Team::destroy($id);
|
||||
}
|
||||
|
||||
public static function destroyBySociete($id)
|
||||
{
|
||||
$teams = Team::bySociete($id)->get();
|
||||
foreach ($teams as $team) {
|
||||
self::delete($team->id);
|
||||
}
|
||||
}
|
||||
|
||||
// ajoute une équipe/service/direction
|
||||
public static function create($data)
|
||||
{
|
||||
return Team::create($data);
|
||||
}
|
||||
|
||||
// met à jour les informations d'une équipe/service/direction
|
||||
public static function update($data)
|
||||
{
|
||||
return Team::find($data['id'])->update($data);
|
||||
}
|
||||
}
|
||||
136
app/Repositories/Core/Auth/Users.php
Normal file
136
app/Repositories/Core/Auth/Users.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
|
||||
use App\Models\Core\Auth\User;
|
||||
use App\Models\Core\Auth\RoleUser;
|
||||
|
||||
class Users
|
||||
{
|
||||
use LaratrustUserTrait;
|
||||
|
||||
public static function isAdmin()
|
||||
{
|
||||
return (self::hasRole('admin')) ? true : false;
|
||||
}
|
||||
|
||||
public static function getInfo($id = false)
|
||||
{
|
||||
return self::getWithDetail($id);
|
||||
}
|
||||
|
||||
public static function getWithDetail($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
return User::where('id', $id)->with(['user_detail'])->first();
|
||||
}
|
||||
|
||||
public static function getEmailsByRole($role) {
|
||||
return User::select('id','email')->whereRoleIs($role)->get()->toArray();
|
||||
}
|
||||
|
||||
public static function getIdsByRole($role) {
|
||||
return User::select('id')->whereRoleIs($role)->get()->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getListByRole($role)
|
||||
{
|
||||
return self::selectOptions()->orderBy('nom', 'asc')->whereRoleIs($role)->get();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return self::selectOptions()->get();
|
||||
}
|
||||
|
||||
public static function selectOptions()
|
||||
{
|
||||
return User::select('id', DB::raw("concat(last_name,' ',first_name) as nom"));
|
||||
}
|
||||
|
||||
public static function hasRole($role)
|
||||
{
|
||||
$user = self::get();
|
||||
return $user ? $user->hasRole($role) : false;
|
||||
}
|
||||
|
||||
public static function getId()
|
||||
{
|
||||
return self::getUser()->id;
|
||||
}
|
||||
|
||||
public static function get($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
return User::find($id);
|
||||
}
|
||||
|
||||
public static function getUser()
|
||||
{
|
||||
return Auth::user();
|
||||
}
|
||||
|
||||
public static function isConnected()
|
||||
{
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
public static function delete($id)
|
||||
{
|
||||
$t = RoleUser::byUser($id)->delete();
|
||||
return User::destroy($id);
|
||||
}
|
||||
|
||||
public static function getByTeam($id)
|
||||
{
|
||||
return User::byTeam($id)->get();
|
||||
}
|
||||
|
||||
public static function getByUniqueTeam($id)
|
||||
{
|
||||
return User::byTeam($id)->byUniqueTeam()->get();
|
||||
}
|
||||
|
||||
public static function destroyByUniqueTeam($id)
|
||||
{
|
||||
return User::byTeam($id)->byUniqueTeam()->delete();
|
||||
}
|
||||
|
||||
// récupère les champs de la table
|
||||
public static function get_field_table()
|
||||
{
|
||||
return $this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable());
|
||||
}
|
||||
|
||||
// ajoute un utilisateur
|
||||
public static function insert($data)
|
||||
{
|
||||
return User::create($data);
|
||||
}
|
||||
|
||||
// récupère tous les utilisateurs
|
||||
public static function select_all()
|
||||
{
|
||||
return User::all()->toArray();
|
||||
}
|
||||
|
||||
|
||||
// met à jour les informations d'un utilisateur
|
||||
public static function update(Request $request)
|
||||
{
|
||||
return User::find($data['id'])->update($data);
|
||||
}
|
||||
|
||||
// met à jour le mot de passe d'un utilisateur
|
||||
public static function update_password($id, $password)
|
||||
{
|
||||
$user = User::find($id);
|
||||
$user->password = Hash::make($password);
|
||||
return $user->save();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user