Skip to content

Commit

Permalink
Request reason complete
Browse files Browse the repository at this point in the history
  • Loading branch information
droberts-ctrlo committed Dec 2, 2024
1 parent 44d7f03 commit 695e566
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 16 deletions.
3 changes: 2 additions & 1 deletion lib/GADS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1556,8 +1556,9 @@ any ['get', 'post'] => '/user_requests/' => require_any_role [qw/useradmin super
if logged_in_user->id == $delete_id;

my $usero = rset('User')->find($delete_id);
my $email_reject_text = param('reject_reason');

if (process( sub { $usero->retire(send_reject_email => 1) }))
if (process( sub { $usero->retire(send_reject_email => 1, email_reject_text => $email_reject_text) }))
{
$audit->login_change("User ID $delete_id deleted");
return forwardHome(
Expand Down
35 changes: 29 additions & 6 deletions lib/GADS/Schema/Result/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,25 @@ sub permissions
}
}

sub _map_fields {
my ($self, $text) = @_;
my @fields = ('firstname', 'surname', 'email', 'title', 'organisation', 'department', 'team');

if($text) {
foreach my $field (@fields) {
my $value = $self->$field || '';
$text =~ s/\{$field\}/$value/g;
}
}

if($text) {
my $notes = $self->account_request_notes || '';
$text =~ s/\{notes\}/$notes/g;
}

return $text;
}

sub retire
{ my ($self, %options) = @_;

Expand All @@ -1023,16 +1042,20 @@ sub retire
# Properly delete if account request - no record needed
if ($self->account_request)
{
$self->delete;
return unless $options{send_reject_email};
if($options{send_reject_email}) {
my $email_body = $options{email_reject_text} || $site->email_reject_text || "Your account request has been rejected";
$email_body = $self->_map_fields($email_body);

my $email = GADS::Email->instance;
$email->send({
subject => $site->email_reject_subject || "Account request rejected",
emails => [$self->email],
text => $site->email_reject_text || "Your account request has been rejected",
subject => $site->email_reject_subject || "Account request rejected",
emails => [$self->email],
text => $email_body,
});
}
$self->delete;

return;
return;
}
else {
$self->search_related('user_graphs', {})->delete;
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/components/data-table/lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'datatables.net-rowreorder-bs4'
import { setupDisclosureWidgets, onDisclosureClick } from 'components/more-less/lib/disclosure-widgets'
import { moreLess } from 'components/more-less/lib/more-less'
import { bindToggleTableClickHandlers } from './toggle-table'
import TypeaheadBuilder from 'util/typeahead'

const MORE_LESS_TRESHOLD = 50

Expand Down Expand Up @@ -126,7 +125,7 @@ class DataTableComponent extends Component {

fillModalData(row) {
const fields = $(this.modal).find('input, textarea')
const btnReject = $(this.modal).find('.btn-js-reject-request')
const btnReject = $(this.modal).find('.btn-js-reject-request-send')
const id = parseInt($(row).find(`td[data-id]`).data('id'), 10)

if (id) $(this.modal).data('config').id = id
Expand Down
1 change: 1 addition & 0 deletions src/frontend/components/modal/lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class ModalComponent extends Component {

// Validate the required fields of the frame
validateFrame() {
if(!this.frame) return;
this.frame.isValid = true

this.frame.requiredFields.each((i, field) => {
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/components/modal/modals/user/lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class UserModalComponent extends ModalComponent {
} else {
this.el.find('.js-add-user').hide()
this.el.find('.js-approve-account').show()
this.el.find('.btn-js-reject-request').show()
this.el.find('.btn-js-reject-request').show().on("click", ()=>{
this.activateFrame(4);
})
this.el.find('.btn-js-save .btn__title').html('Approve account')
this.el.find('input[name="approve-account"]').val('true')
}
Expand Down
59 changes: 53 additions & 6 deletions views/wizard/user_add.tt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

<ol class="modal__steps">
<li class="modal__step modal__step--active" data-step="1">
<span>
User details
</span>
<span>
User details
</span>
</li>
<li class="modal__step " data-step="2">
<span>
Expand Down Expand Up @@ -140,7 +140,7 @@
dismiss = "modal"
}]
right_buttons = [{
type = "submit"
type = "button"
class = "btn-danger btn-js-reject-request"
name = "delete"
value = user.id
Expand Down Expand Up @@ -230,7 +230,7 @@
label = "Back"
}]
right_buttons = [{
type = "submit"
type = "button"
class = "btn-danger btn-js-reject-request"
name = "delete"
value = user.id
Expand Down Expand Up @@ -281,7 +281,7 @@
label = "Back"
}]
right_buttons = [{
type = "submit"
type = "button"
class = "btn-danger btn-js-reject-request"
name = "delete"
value = user.id
Expand All @@ -292,6 +292,53 @@
}];
-%]
</div>
<div class="modal-frame" data-config='{"step":4,"frame":4,"item":null,"count":null}'>
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col">
<div class="alert alert-danger alert-js-reject-details" role="alert" id="modal-alert-reject">
</div>
</div>
</div>

<div class="row mb-4">
<div class="col">
<p class="js-reject-account">In this window you can add a reason for the account request rejection.</p>
</div>
</div>

<div class="row">
<div class="col-lg-12">
[%-
INCLUDE fields/textarea.tt
id = "reject_reason"
name = "reject_reason"
label = "Reject reason"
placeholder = "Enter reject reason"
filter = "html"
rows = 2;
-%]
</div>

</div> <!-- container end -->
</div> <!-- modal body end -->
[%-
INCLUDE wizard/sub/modal_footer.tt
left_buttons = [{
class = "btn-cancel"
label = "Cancel"
dismiss = "modal"
}]
right_buttons = [{
type = "submit"
class = "btn-danger btn-js-reject-request-send"
name = "delete"
value = user.id
label = "Reject request"
}];
-%]
</div>
</form>
</div>
</div>
Expand Down

0 comments on commit 695e566

Please sign in to comment.