Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject reason complete [B: 1647] #493

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) }))
droberts-ctrlo marked this conversation as resolved.
Show resolved Hide resolved
{
$audit->login_change("User ID $delete_id deleted");
return forwardHome(
Expand Down
37 changes: 30 additions & 7 deletions lib/GADS/Schema/Result/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,24 @@ 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;
}
my $notes = $self->account_request_notes || '';
$text =~ s/\{notes\}/$notes/g;
}

return $text;
}

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

Expand All @@ -1023,14 +1041,19 @@ sub retire
# Properly delete if account request - no record needed
if ($self->account_request)
{
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 => $email_body,
});
}
$self->delete;
return unless $options{send_reject_email};
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",
});

return;
}
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'
droberts-ctrlo marked this conversation as resolved.
Show resolved Hide resolved

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')
droberts-ctrlo marked this conversation as resolved.
Show resolved Hide resolved
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;
droberts-ctrlo marked this conversation as resolved.
Show resolved Hide resolved
this.frame.isValid = true

this.frame.requiredFields.each((i, field) => {
Expand Down
23 changes: 21 additions & 2 deletions src/frontend/components/modal/modals/user/lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class UserModalComponent extends ModalComponent {

// Toggle the right content (add user or approve account)
toggleContent(ev) {
if ($(ev.relatedTarget).hasClass('btn-add')) {
this.target = $(ev.relatedTarget)
if (this.target.hasClass('btn-add')) {
modal.clear()
this.el.find('.js-approve-account').hide()
this.el.find('.js-add-user').show()
Expand All @@ -33,7 +34,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 Expand Up @@ -90,6 +93,22 @@ class UserModalComponent extends ModalComponent {
super.handleClose()
this.emailText.html("USER")
}

handleBack() {
super.handleBack()
if(this.target.hasClass('btn-add')) return;
this.el.find('.btn-js-reject-request').off().on("click", ()=>{
this.activateFrame(4);
});
}

handleNext() {
super.handleNext()
if(this.target.hasClass('btn-add')) return;
this.el.find('.btn-js-reject-request').off().on("click", ()=>{
this.activateFrame(4);
});
}
}

export default UserModalComponent
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>
droberts-ctrlo marked this conversation as resolved.
Show resolved Hide resolved
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}'>
droberts-ctrlo marked this conversation as resolved.
Show resolved Hide resolved
<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
Loading