fix devops error
This commit is contained in:
@@ -6,7 +6,7 @@ class Passwords
|
||||
{
|
||||
public static function validator()
|
||||
{
|
||||
$validator = new \Password\Validator(new \Password\StringHelper);
|
||||
$validator = new \Password\Validator(new \Password\StringHelper());
|
||||
$validator->setMinLength(5);
|
||||
$validator->setMinLowerCaseLetters(2);
|
||||
$validator->setMinUpperCaseLetters(1);
|
||||
|
||||
@@ -3,83 +3,24 @@
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use App\Models\Core\Auth\Permission;
|
||||
use Yajra\DataTables\DataTables;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class Permissions
|
||||
{
|
||||
use Basic;
|
||||
|
||||
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)
|
||||
public static function getModel()
|
||||
{
|
||||
return Permission::findOrFail($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)
|
||||
{
|
||||
$permission = Permission::create($data);
|
||||
|
||||
return $permission;
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return self::get($data['id'])->update($data);
|
||||
}
|
||||
|
||||
public static function count()
|
||||
{
|
||||
return Permission::count();
|
||||
return Permission::query();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,26 +4,21 @@ namespace App\Repositories\Core\Auth;
|
||||
|
||||
use App\Models\Core\Auth\Role;
|
||||
use App\Models\Core\Auth\RoleUser;
|
||||
use App\Traits\Model\Basic;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
class Roles
|
||||
{
|
||||
use LaratrustUserTrait;
|
||||
use Basic, LaratrustUserTrait;
|
||||
|
||||
public static function getListByRights()
|
||||
{
|
||||
$data = (! Auth::user()->hasRole('admin')) ? Role::whereNotIn('name', ['admin'])->get() : Role::all();
|
||||
$data = ! Auth::user()->hasRole('admin') ? Role::whereNotIn('name', ['admin'])->get() : Role::all();
|
||||
|
||||
return $data->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function store($input)
|
||||
{
|
||||
return (isset($input['id']) && $input['id']) ? self::update($input) : self::create($input);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$permissions = array_keys($data['permissions']);
|
||||
@@ -35,10 +30,9 @@ class Roles
|
||||
return $role;
|
||||
}
|
||||
|
||||
// met à jour les informations d'une forme juridique
|
||||
public static function update($input, $id = false)
|
||||
{
|
||||
$id = ($id) ? $id : $input['id'];
|
||||
$id = $id ? $id : $input['id'];
|
||||
$permissions = array_keys($input['permissions']);
|
||||
$role = self::get($id);
|
||||
$role->update(['name' => $input['name']]);
|
||||
@@ -47,24 +41,11 @@ class Roles
|
||||
return $role;
|
||||
}
|
||||
|
||||
// supprime une forme juridique
|
||||
public static function delete($id)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
public static function getWithPermissions($id)
|
||||
{
|
||||
$role = self::get($id)->toArray();
|
||||
@@ -73,28 +54,11 @@ class Roles
|
||||
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::findOrFail($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();
|
||||
@@ -112,8 +76,8 @@ class Roles
|
||||
return self::getUsersByRole($id)->pluck('user_id');
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
public static function getModel()
|
||||
{
|
||||
return Role::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
return RoleUser::query();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use App\Models\Core\Auth\User;
|
||||
use App\Models\Core\Auth\UserClient;
|
||||
use App\Repositories\Clients;
|
||||
|
||||
class UserClients
|
||||
{
|
||||
public static function associate($user_id, $clients_list)
|
||||
{
|
||||
$clients_existing = self::getClientsByUser($user_id)->toArray();
|
||||
$clients_list = is_array($clients_list) ? $clients_list : [];
|
||||
|
||||
if (is_array($clients_existing)) {
|
||||
$clients_new = array_diff($clients_list, $clients_existing);
|
||||
$clients_to_delete = array_diff($clients_existing, $clients_list);
|
||||
} else {
|
||||
$clients_new = $clients_list;
|
||||
$clients_to_delete = $clients_existing;
|
||||
}
|
||||
|
||||
$history_element_infos = (! empty($clients_new)) ? self::associateClients($user_id, $clients_new) : false;
|
||||
$history_element_infos2 = (! empty($clients_to_delete)) ? self::dissociateClients($user_id, $clients_to_delete) : false;
|
||||
|
||||
// $history_element = $old_translated_name['name'];
|
||||
// $history_element_id = $documentation_category_id;
|
||||
// Histories::insert(190, $history_element_id, $history_element);
|
||||
|
||||
$data['nb'] = self::countByUser($user_id);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function countByUser($id)
|
||||
{
|
||||
return UserClient::byUser($id)->count();
|
||||
}
|
||||
|
||||
public static function associateClients($user_id, $clients)
|
||||
{
|
||||
$history = '';
|
||||
foreach ($clients as $key => $client_id) {
|
||||
$client = Clients::get($client_id);
|
||||
if ($client) {
|
||||
self::associate_client($user_id, $client_id);
|
||||
$history .= $client['name'].'| ';
|
||||
}
|
||||
}
|
||||
|
||||
return $history;
|
||||
}
|
||||
|
||||
public static function associate_client($user_id, $client_id)
|
||||
{
|
||||
self::copyUser($user_id, $client_id);
|
||||
|
||||
return UserClient::create(['user_id' => $user_id, 'client_id' => $client_id]);
|
||||
}
|
||||
|
||||
public static function changePasswordsByUser($user_id, $password)
|
||||
{
|
||||
try {
|
||||
$username = User::find($user_id)->username;
|
||||
$connection = app(Connection::class);
|
||||
$clients = self::getClientsByUser($user_id);
|
||||
foreach ($clients as $client_id) {
|
||||
Clients::switchClient($client_id);
|
||||
$client_user = User::on($connection->tenantName())->withTrashed()->where('username', $username)->first();
|
||||
if ($client_user) {
|
||||
$client_user->update(['password' => $password]);
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
// Partners::switchPartner();
|
||||
}
|
||||
|
||||
public static function copyUser($user_id, $client_id)
|
||||
{
|
||||
$connection = app(Connection::class);
|
||||
$user = User::on($connection->systemName())->find($user_id);
|
||||
$password = $user->password;
|
||||
Clients::switchClient($client_id);
|
||||
$client_user = User::on($connection->tenantName())->withTrashed()->where('username', $user->username)->first();
|
||||
if (! $client_user) {
|
||||
$user = $user->toArray();
|
||||
$user['password'] = $password;
|
||||
unset($user['id']);
|
||||
unset($user['created_at']);
|
||||
$client_user = User::on($connection->tenantName())->create($user);
|
||||
$client_user->attachRole('superadministrator');
|
||||
} else {
|
||||
if ($client_user->trashed()) {
|
||||
$client_user->restore();
|
||||
}
|
||||
$client_user->attachRole('superadministrator');
|
||||
}
|
||||
// TODO Copy avatar
|
||||
//
|
||||
// dump($client_user->toArray());
|
||||
// exit;
|
||||
// $client_user = User::on($connection->tenantName())->firstOrCreate(['username' => $user->username], $user->toArray());
|
||||
Partners::switchPartner();
|
||||
}
|
||||
|
||||
public static function dissociateClients($user_id, $clients)
|
||||
{
|
||||
$history = '';
|
||||
foreach ($clients as $key => $client_id) {
|
||||
self::dissociate_client($user_id, $client_id);
|
||||
$history .= $client['name'].'| ';
|
||||
}
|
||||
|
||||
return $history;
|
||||
}
|
||||
|
||||
public static function dissociate_client($user_id, $client_id)
|
||||
{
|
||||
self::deleteUser($user_id, $client_id);
|
||||
|
||||
return UserClient::byUser($user_id)->byClient($client_id)->delete();
|
||||
}
|
||||
|
||||
public static function deleteUser($user_id, $client_id)
|
||||
{
|
||||
$connection = app(Connection::class);
|
||||
$user = User::on($connection->systemName())->find($user_id);
|
||||
Clients::switchClient($client_id);
|
||||
$user = User::on($connection->tenantName())->where('username', $user->username)->get();
|
||||
$user->detachRole('superadministrator');
|
||||
$user->delete();
|
||||
Partners::switchPartner();
|
||||
}
|
||||
|
||||
public static function delete_associate_clients($id)
|
||||
{
|
||||
return UserClient::byUser($id)->delete();
|
||||
}
|
||||
|
||||
public static function select_clients_by_id($id)
|
||||
{
|
||||
return UserClient::byUser($id)->get()->pluck('client_id')->toArray();
|
||||
}
|
||||
|
||||
public static function getClientsByUser($id)
|
||||
{
|
||||
return UserClient::byUser($id)->get()->pluck('client_id');
|
||||
}
|
||||
|
||||
public static function getUsersByClient($id)
|
||||
{
|
||||
return UserClient::byClient($id)->get()->pluck('user_id');
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ class Users
|
||||
|
||||
public static function isAdmin()
|
||||
{
|
||||
return (self::hasRole('admin')) ? true : false;
|
||||
return self::hasRole('admin');
|
||||
}
|
||||
|
||||
public static function getInfo($id = false)
|
||||
@@ -42,7 +42,7 @@ class Users
|
||||
if ($data['id'] ?? false) {
|
||||
unset($data['password']);
|
||||
}
|
||||
$user = ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
$user = $data['id'] ?? false ? self::update($data) : self::create($data);
|
||||
$user->roles()->sync(array_keys($data['roles'] ?? []));
|
||||
|
||||
return $user;
|
||||
@@ -243,9 +243,10 @@ class Users
|
||||
$data = Upload::getData($file);
|
||||
$file_uploaded = Upload::store($file, $targetDir);
|
||||
$tab = pathinfo($file_uploaded);
|
||||
$response['name'] = $tab['basename'];
|
||||
|
||||
return $response;
|
||||
return [
|
||||
'name' => $tab['basename'],
|
||||
];
|
||||
}
|
||||
|
||||
public static function update_avatar($id, $avatar)
|
||||
|
||||
Reference in New Issue
Block a user