Commit 3e9560de authored by Viral Solani's avatar Viral Solani

-create attach permission at user access level

-insert permission to newly created functions
parent 99fe1126
......@@ -49,8 +49,6 @@ class PushNotification
}
/**
* Created By : Umang Soni
* Created at : 26/05/2017
* PushNotification for android.
*
* @param array $devicetoken
......@@ -88,8 +86,6 @@ class PushNotification
}
/**
* Created By : Umang Soni
* Created at : 26/05/2017
* PushNotification for IOS.
*
* @param array $devicetoken
......
......@@ -269,4 +269,58 @@ trait UserAccess
$this->detachRole($role);
}
}
/**
* Attach multiple Permissions to a user.
*
* @param mixed $permissions
*
* @return void
*/
public function attachPermissions($permissions)
{
foreach ($permissions as $permission) {
$this->attachPermission($permission);
}
}
/**
* Alias to eloquent many-to-many relation's attach() method.
*
* @param mixed $permission
*
* @return void
*/
public function attachPermission($permission)
{
if (is_object($permission)) {
$permission = $permission->getKey();
}
if (is_array($permission)) {
$permission = $permission['id'];
}
$this->permissions()->attach($permission);
}
/**
* Alias to eloquent many-to-many relation's detach() method.
*
* @param mixed $permission
*
* @return void
*/
public function detachPermission($permission)
{
if (is_object($permission)) {
$permission = $permission->getKey();
}
if (is_array($permission)) {
$permission = $permission['id'];
}
$this->permission()->detach($permission);
}
}
......@@ -124,22 +124,24 @@ class UserRepository extends BaseRepository
$permissions = $request->all('permissions') ? $request->all('permissions') : [];
$user = $this->createUserStub($data);
DB::transaction(function () use ($user, $data, $roles, $permissions) {
DB::transaction(function () use ($user, $data, $request) {
// Set email type 2
$email_type = 2;
if ($user->save()) {
//User Created, Validate Roles
if (!count($roles['assignees_roles'])) {
if (!count($request->get('assignees_roles'))) {
throw new GeneralException(trans('exceptions.backend.access.users.role_needed_create'));
}
//Attach new roles
$user->attachRoles($roles['assignees_roles']);
$user->attachRoles($request->get('assignees_roles'));
// Attach Permissions
$this->attachPermissions($permissions);
// Attach New Permissions
$user->attachPermissions($request->get('permissions'));
//$this->attachPermissions($permissions);
//Send confirmation email if requested and account approval is off
if (isset($data['confirmation_email']) && $user->confirmed == 0) {
......@@ -148,6 +150,9 @@ class UserRepository extends BaseRepository
event(new UserCreated($user));
//@todo if it is require it can go to event to send notfication
//or user laravel 5.5 notification
//Send confirmation email if requested
/*if (isset($data['confirmation_email']) && $user->confirmed == 0) {
// If user needs confirmation then set email type 1
......@@ -423,29 +428,4 @@ class UserRepository extends BaseRepository
return $user;
}
/**
* Attach Permission.
*
* @param $permissions
*
* @todo attach permission like role
*
* @return mix
*/
public function attachPermissions($value = '')
{
$arrUserPermissions = [];
if (isset($permissions) && count($permissions) > 0) {
foreach ($permissions as $permission) {
$arrUserPermissions[] = [
'permission_id' => $permission,
'user_id' => $user->id,
];
}
// Insert multiple rows at once
DB::table('permission_user')->insert($arrUserPermissions);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment