Skip to content

Commit

Permalink
Merge pull request #29033 from JonBendtsen/allow_adding_bank_account
Browse files Browse the repository at this point in the history
allow user self + useradministrator to modify a users bank account
  • Loading branch information
eldy authored Mar 23, 2024
2 parents 8906df3 + 0ce6e01 commit 48b9e78
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions htdocs/user/bank.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,21 @@
}

// Define value to know what current user can do on users
$canadduser = (!empty($user->admin) || $user->hasRight('user', 'user', 'creer') || $user->rights->hrm->write_personal_information->write);
$canreaduser = (!empty($user->admin) || $user->rights->user->user->lire || $user->rights->hrm->read_personal_information->read);
$permissiontoaddbankaccount = ($user->hasRight('salaries', 'write') || $user->hasRight('hrm', 'employee', 'write') || $user->hasRight('user', 'creer'));
$selfpermission = ($user->id == $id && $user->hasRight('user', 'self', 'creer'));
$canadduser = (!empty($user->admin) || $user->hasRight('user', 'user', 'creer') || $user->hasRight('hrm', 'write_personal_information', 'write') );
$canreaduser = (!empty($user->admin) || $user->hasRight('user', 'user', 'lire') || $user->hasRight('hrm', 'read_personal_information', 'read') );
$permissiontoaddbankaccount = ($user->hasRight('salaries', 'write') || $user->hasRight('hrm', 'employee', 'write') || $user->hasRight('user', 'user', 'creer') || $selfpermission);
$permissiontoreadhr = $user->hasRight('hrm', 'read_personal_information', 'read') || $user->hasRight('hrm', 'write_personal_information', 'write');
$permissiontowritehr = $user->hasRight('hrm', 'write_personal_information', 'write');
$permissiontosimpleedit = ($selfpermission || $canadduser);

// Ok if user->hasRight('salaries', 'read') or user->hasRight('hrm', 'read')
// Ok if user->hasRight('salaries', 'readall') or user->hasRight('hrm', 'read')
//$result = restrictedArea($user, 'salaries|hrm', $object->id, 'user&user', $feature2);
$ok = false;
if ($user->id == $id) {
$ok = true; // A user can always read its own card
}
if ($user->hasRight('salaries', 'read')) {
if ($user->hasRight('salaries', 'readall')) {
$ok = true;
}
if ($user->hasRight('hrm', 'read')) {
Expand Down Expand Up @@ -201,7 +203,7 @@
}

// update personal email
if ($action == 'setpersonal_email' && $canadduser && !$cancel) {
if ($action == 'setpersonal_email' && $permissiontosimpleedit && !$cancel) {
$object->personal_email = (string) GETPOST('personal_email', 'alphanohtml');
$result = $object->update($user);
if ($result < 0) {
Expand All @@ -210,7 +212,7 @@
}

// update personal mobile
if ($action == 'setpersonal_mobile' && $canadduser && !$cancel) {
if ($action == 'setpersonal_mobile' && $permissiontosimpleedit && !$cancel) {
$object->personal_mobile = (string) GETPOST('personal_mobile', 'alphanohtml');
$result = $object->update($user);
if ($result < 0) {
Expand Down Expand Up @@ -282,7 +284,7 @@

$head = user_prepare_head($object);

if ($id && $bankid && $action == 'edit' && ($user->hasRight('user', 'user', 'creer') || $user->hasRight('hrm', 'write_personal_information', 'write'))) {
if ($id && $bankid && $action == 'edit' && !$cancel && $permissiontoaddbankaccount) {
if ($conf->use_javascript_ajax) {
print "\n<script>";
print 'jQuery(document).ready(function () {
Expand All @@ -303,7 +305,7 @@
print '<input type="hidden" name="id" value="'.GETPOSTINT("id").'">';
print '<input type="hidden" name="bankid" value="'.$bankid.'">';
}
if ($id && $action == 'create' && $user->hasRight('user', 'user', 'creer')) {
if ($id && $action == 'create' && !$cancel && $permissiontoaddbankaccount) {
if ($conf->use_javascript_ajax) {
print "\n<script>";
print 'jQuery(document).ready(function () {
Expand Down Expand Up @@ -493,7 +495,7 @@
}

// Personal email
if ($user->hasRight('hrm', 'read_personal_information', 'read') || $user->hasRight('hrm', 'write_personal_information', 'write')) {
if ($user->hasRight('hrm', 'read_personal_information', 'read') || $user->hasRight('hrm', 'write_personal_information', 'write') || ) {
print '<tr class="nowrap">';
print '<td>';
print $form->editfieldkey("UserPersonalEmail", 'personal_email', $object->personal_email, $object, $user->hasRight('user', 'user', 'creer') || $user->hasRight('hrm', 'write_personal_information', 'write'));
Expand All @@ -504,7 +506,7 @@
}

// Personal phone
if ($user->hasRight('hrm', 'read_personal_information', 'read') || $user->hasRight('hrm', 'write_personal_information', 'write')) {
if ($user->hasRight('hrm', 'read_personal_information', 'read') || $user->hasRight('hrm', 'write_personal_information', 'write') || ) {
print '<tr class="nowrap">';
print '<td>';
print $form->editfieldkey("UserPersonalMobile", 'personal_mobile', $object->personal_mobile, $object, $user->hasRight('user', 'user', 'creer') || $user->hasRight('hrm', 'write_personal_information', 'write'));
Expand Down Expand Up @@ -895,7 +897,7 @@
}

// Edit
if ($id && ($action == 'edit' || $action == 'create') && $user->hasRight('user', 'user', 'creer')) {
if ($id && ($action == 'edit' || $action == 'create') && $permissiontoaddbankaccount) {
$title = $langs->trans("User");
print dol_get_fiche_head($head, 'bank', $title, 0, 'user');

Expand Down Expand Up @@ -1030,11 +1032,11 @@
print $form->buttonsSaveCancel($action == 'create' ? "Create" : "Modify");
}

if ($id && $action == 'edit' && $user->hasRight('user', 'user', 'creer')) {
if ($id && $action == 'edit' && $permissiontoaddbankaccount) {
print '</form>';
}

if ($id && $action == 'create' && $user->hasRight('user', 'user', 'creer')) {
if ($id && $action == 'create' && $permissiontoaddbankaccount) {
print '</form>';
}

Expand Down

0 comments on commit 48b9e78

Please sign in to comment.