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

N21-1887 Rollback user from a user login migration #255

Merged
merged 4 commits into from
May 3, 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
28 changes: 28 additions & 0 deletions controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ const router = express.Router();
const authHelper = require('../helpers/authentication');
const { api } = require('../api');
const moment = require('moment');
const { isFeatureFlagTrue } = require('../helpers/featureFlagHelper');
moment.locale('de');

const USER_MIGRATION_ENABLED = isFeatureFlagTrue(process.env.FEATURE_SCHOOL_SANIS_USER_MIGRATION_ENABLED);

const getTableActions = (item, path) => {
let tableActions = [
{
Expand Down Expand Up @@ -48,6 +51,14 @@ const getTableActions = (item, path) => {
title: 'Registrierungslink generieren',
});
}
if (USER_MIGRATION_ENABLED) {
MarvinOehlerkingCap marked this conversation as resolved.
Show resolved Hide resolved
tableActions.push({
link: path + item._id,
class: 'btn-migration-rollback',
icon: 'rotate-left',
title: 'Migration rückgängig machen',
});
}
return tableActions;
};

Expand Down Expand Up @@ -577,4 +588,21 @@ const generateRegistrationLink = () => {

router.get('/registrationlink/:id', generateRegistrationLink());

router.post('/:id/rollback-migration', (req, res, next) => {
const userId = req.params.id;

api(req, { version: 'v3' }).post(`/user-login-migrations/users/${userId}/rollback-migration`)
.then(async () => {
req.session.notification = {
type: 'success',
message: `Die Migration für den Nutzer wurde erfolgreich zurückgesetzt`,
};

res.redirect(req.header('Referer'));
})
.catch((err) => {
next(err);
});
});

module.exports = router;
24 changes: 24 additions & 0 deletions static/scripts/users.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
"use strict";

$(document).ready(function () {
const $rollbackModal = $('.migration-rollback-modal');

$('.btn-migration-rollback').on('click', function (rollbackBtnClickEvent) {
rollbackBtnClickEvent.preventDefault();

const url = $(this).attr('href');
$.getJSON(url, function (user) {
populateModalForm($rollbackModal, {
action: url + '/rollback-migration',
title: 'Migration rückgängig machen',
closeLabel: 'Schließen',
submitLabel: 'Zurücksetzen',
fields: user
});

const $btnSubmit = $rollbackModal.find('.btn-submit');
$btnSubmit.prop('disabled', !user.lastLoginSystemChange);
MarvinOehlerkingCap marked this conversation as resolved.
Show resolved Hide resolved

$rollbackModal.modal('show');
});
});
});

function toggleSilentArea(status){
const area = document.querySelector('.silent-area');
const inputs = area.querySelectorAll('input, select');
Expand Down
42 changes: 42 additions & 0 deletions views/users/forms/rollback-user-migration.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<div class="form-group">
<label class="control-label" for="rollback-firstName">Vorname</label>
<input type="text" name="firstName" id="rollback-firstName" class="form-control" readonly>
</div>
<div class="form-group">
<label class="control-label" for="rollback-lastName">Nachname</label>
<input type="text" name="lastName" id="rollback-lastName" class="form-control" readonly>
</div>
<div class="form-group">
<label class="control-label" for="rollback-email">E-Mail</label>
<input type="text" name="email" id="rollback-email" class="form-control" readonly>
</div>
<div class="form-group">
<label class="control-label" for="rollback-ldapId">Externe ID</label>
<input type="text" name="ldapId" id="rollback-ldapId" class="form-control" readonly>
</div>
<div class="form-group">
<label class="control-label" for="rollback-previousExternalId">Vorherige externe ID</label>
<input type="text" name="previousExternalId" id="rollback-previousExternalId" class="form-control" readonly>
</div>
<div class="form-group">
<label class="control-label" for="rollback-ldapDn">LDAP DN</label>
<input type="text" name="ldapDn" id="rollback-ldapDn" class="form-control" readonly>
</div>
<div class="form-group">
<label class="control-label" for="rollback-lastLoginSystemChange">Letzte Anmeldesystemänderung</label>
<input type="text" name="lastLoginSystemChange" id="rollback-lastLoginSystemChange" class="form-control" readonly>
</div>
<div class="form-group">
<label class="control-label" for="rollback-outdatedSince">Veraltet seit</label>
<input type="text" name="outdatedSince" id="rollback-outdatedSince" class="form-control" readonly>
</div>

<hr/>

<h5><b>Warnung</b></h5>
<ul>
<li>Nach dem Zurücksetzten der Migration bei einem "E-Mail"-Account muss das Passwort manuell zurückgesetzt werden, um sich wieder anmelden zu können</li>
<li>Wenn die Migration an der Schule des Nutzers bereits abgeschlossen ist, wird dieser Account als veraltet markiert und der Nutzer kann sich ohne erneute Migration mit seinem neuen Anmeldesystem anmelden, wodurch ein neuer Account erstellt wird</li>
</ul>

<p>Möchten sie die Migration dieses Nutzers wirklich rückgängig machen?</p>
5 changes: 5 additions & 0 deletions views/users/users.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,10 @@
{{> "users/forms/form-invitation"}}
{{/content}}
{{/embed}}
{{#embed "lib/components/modal-form" method="post" class="migration-rollback-modal"}}
{{#content "fields"}}
{{> "users/forms/rollback-user-migration"}}
{{/content}}
{{/embed}}
{{/content}}
{{/extend}}