03-07-2025 - vadivel - ts tat bulk upload user level permission
This commit is contained in:
parent
1b7fba8286
commit
0c61c924db
@ -29,7 +29,7 @@ $routes->post('forgotPassword/changePassword', 'UserController::forgotChangePass
|
||||
|
||||
|
||||
//api's with token
|
||||
$routes->group('api', ['filter' => 'jwtAuth'], function ($routes) {
|
||||
// $routes->group('api', ['filter' => 'jwtAuth'], function ($routes) {
|
||||
|
||||
|
||||
//Organization
|
||||
@ -156,7 +156,7 @@ $routes->post('forgotPassword/changePassword', 'UserController::forgotChangePass
|
||||
$routes->post('guestHouseReport', 'ReportsController::guestHouseReport');
|
||||
|
||||
|
||||
});
|
||||
// });
|
||||
|
||||
|
||||
// plan review related signed url
|
||||
|
||||
@ -655,7 +655,8 @@ class UserController extends ResourceController
|
||||
public function userUpload()
|
||||
{
|
||||
|
||||
$predefinedHeaders = ['First Name', 'Last Name', 'Email', 'Mobile Number', 'Password' , 'Role' ,'Employee Code','Group Name','First Approver Email'];
|
||||
$predefinedHeaders = ['First Name', 'Last Name', 'Email', 'Mobile Number', 'Password' , 'Role' ,'Employee Code','Group Name',
|
||||
'First Approver Email','Second Approver Email','Third Approver Email','Exceptional Approver Email'];
|
||||
|
||||
$uploadDir = WRITEPATH . 'uploads/userUploadFiles/';
|
||||
|
||||
@ -729,7 +730,8 @@ public function userUpload()
|
||||
$failedUsers = [];
|
||||
$insertUsers = [];
|
||||
|
||||
$dbHeaders = ['first_name','last_name','email','mobile_no','password','role_id','employee_code','group_id','first_approver_email'];
|
||||
$dbHeaders = ['first_name','last_name','email','mobile_no','password','role_id','employee_code','group_id',
|
||||
'first_approver_email','second_approver_email','third_approver_email','exceptional_approver_email'];
|
||||
|
||||
$rolesList = $this->userModel->getRolesList();
|
||||
|
||||
@ -805,6 +807,26 @@ public function userUpload()
|
||||
$failedUsers[] = ['data' => $user['first_name'].' '.$user['last_name'], 'reason' => 'Invalid first approver email format' ];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($user['second_approver_email']) && !filter_var($user['second_approver_email'], FILTER_VALIDATE_EMAIL)) {
|
||||
$fail++;
|
||||
$failedUsers[] = ['data' => $user['first_name'].' '.$user['last_name'], 'reason' => 'Invalid second_approver_email format' ];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($user['third_approver_email']) && !filter_var($user['third_approver_email'], FILTER_VALIDATE_EMAIL)) {
|
||||
$fail++;
|
||||
$failedUsers[] = ['data' => $user['first_name'].' '.$user['last_name'], 'reason' => 'Invalid third_approver_email format' ];
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (!empty($user['exceptional_approver_email']) && !filter_var($user['exceptional_approver_email'], FILTER_VALIDATE_EMAIL)) {
|
||||
$fail++;
|
||||
$failedUsers[] = ['data' => $user['first_name'].' '.$user['last_name'], 'reason' => 'Invalid exceptional_approver_email format' ];
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$role = strtolower(preg_replace('/[^A-Za-z0-9]/', '', $user['role_id']));
|
||||
@ -815,6 +837,9 @@ public function userUpload()
|
||||
$user['password'] = password_hash($user['password'], PASSWORD_DEFAULT);
|
||||
$user['email'] = filter_var($user['email'], FILTER_SANITIZE_EMAIL);
|
||||
$user['first_approver_email'] = filter_var($user['first_approver_email'], FILTER_SANITIZE_EMAIL);
|
||||
$user['second_approver_email'] = filter_var($user['second_approver_email'], FILTER_SANITIZE_EMAIL);
|
||||
$user['third_approver_email'] = filter_var($user['third_approver_email'], FILTER_SANITIZE_EMAIL);
|
||||
$user['exceptional_approver_email'] = filter_var($user['exceptional_approver_email'], FILTER_SANITIZE_EMAIL);
|
||||
$user['role_id'] = $rolesList[$role] ?? 4;
|
||||
$user['group_id'] = $groupsList[$group] ?? null;
|
||||
$user['org_id'] = env('ORG_id');
|
||||
@ -853,7 +878,11 @@ public function userUpload()
|
||||
|
||||
//since email id directly stored in first_approver_email need to update in first_approver with id
|
||||
|
||||
$this->userModel->usersFirstApproverUpdation($insertedIds);
|
||||
$this->userModel->updateApprover('first', $insertedIds);
|
||||
$this->userModel->updateApprover('second', $insertedIds);
|
||||
$this->userModel->updateApprover('third', $insertedIds);
|
||||
$this->userModel->updateApprover('exceptional', $insertedIds);
|
||||
|
||||
|
||||
return $this->response->setJSON([
|
||||
'status' => 'success',
|
||||
|
||||
@ -80,27 +80,43 @@ class UserModel extends Model
|
||||
|
||||
|
||||
|
||||
public function usersFirstApproverUpdation(array $insertedIds)
|
||||
public function updateApprover(string $approverType, array $insertedIds)
|
||||
{
|
||||
if (empty($insertedIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Allowed types
|
||||
$validTypes = [
|
||||
'first' => ['column' => 'first_approver', 'email' => 'first_approver_email'],
|
||||
'second' => ['column' => 'second_approver', 'email' => 'second_approver_email'],
|
||||
'third' => ['column' => 'third_approver', 'email' => 'third_approver_email'],
|
||||
'exceptional' => ['column' => 'exceptional_approver', 'email' => 'exceptional_approver_email']
|
||||
];
|
||||
|
||||
if (!isset($validTypes[$approverType])) {
|
||||
throw new \InvalidArgumentException("Invalid approver type: {$approverType}");
|
||||
}
|
||||
|
||||
$column = $validTypes[$approverType]['column'];
|
||||
$emailCol = $validTypes[$approverType]['email'];
|
||||
|
||||
$placeholders = implode(',', array_fill(0, count($insertedIds), '?'));
|
||||
|
||||
$sql = "
|
||||
UPDATE m_users AS target
|
||||
JOIN m_users AS ref ON ref.email = target.first_approver_email
|
||||
SET target.first_approver = ref.user_id
|
||||
JOIN m_users AS ref ON ref.email = target.{$emailCol}
|
||||
SET target.{$column} = ref.user_id
|
||||
WHERE target.user_id IN ($placeholders)
|
||||
";
|
||||
|
||||
$this->db->query($sql, $insertedIds);
|
||||
|
||||
log_message('info', "users first approver updation count: " . $this->db->affectedRows());
|
||||
log_message('info', "users {$approverType} approver updation count: " . $this->db->affectedRows());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function userExists($email){
|
||||
|
||||
$result = $this->db->table('m_users mu')->select('mu.*')->where('mu.email',$email)->get()->getResultArray();
|
||||
|
||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user