1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-18 12:54:27 +01:00

163 lines
5.2 KiB
JavaScript
Raw Normal View History

/* eslint-disable
camelcase,
no-return-assign,
no-undef,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
2018-11-21 11:08:53 +01:00
'use strict';
/* COMMON CODE */
2018-11-19 16:17:49 +01:00
// list of supported authentication methods
const METHODS = {
2021-07-01 11:23:58 +02:00
DatabaseProvider: 'local_database',
OAuth2Provider: 'o_auth2',
OpenIdConnectProvider: 'openid_connect'
2018-11-21 11:08:53 +01:00
};
2018-11-19 16:17:49 +01:00
/**
* Iterate through the provided array and return the index of the requested element
* @param elements {Array<{id:*}>}
* @param id {*} id of the element to retrieve in the list
* @returns {number} index of the requested element, in the provided array
*/
2018-11-20 12:26:06 +01:00
const findIdxById = function (elements, id) {
2018-11-21 11:08:53 +01:00
return (elements.map(function (elem) { return elem.id; })).indexOf(id);
};
2018-11-19 16:17:49 +01:00
/**
* Page listing all authentication providers
*/
Application.Controllers.controller('AuthentificationController', ['$scope', '$state', '$rootScope', 'dialogs', 'growl', 'authProvidersPromise', 'AuthProvider', '_t',
function ($scope, $state, $rootScope, dialogs, growl, authProvidersPromise, AuthProvider, _t) {
/* PUBLIC SCOPE */
2018-11-19 16:17:49 +01:00
// full list of authentication providers
2018-11-21 11:08:53 +01:00
$scope.providers = authProvidersPromise;
2018-11-19 16:17:49 +01:00
/**
* Translate the classname into an explicit textual message
* @param type {string} Ruby polymorphic model classname
* @returns {string}
*/
$scope.getType = function (type) {
2018-11-21 11:08:53 +01:00
const text = METHODS[type];
if (typeof text !== 'undefined') {
return _t(`app.admin.members.authentication_form.${text}`);
} else {
return _t('app.admin.members.authentication_form.unknown') + type;
}
2018-11-21 11:08:53 +01:00
};
2018-11-19 16:17:49 +01:00
/**
* Translate the status string into an explicit textual message
* @param status {string} active | pending | previous
* @returns {string}
*/
$scope.getState = function (status) {
switch (status) {
case 'active': return _t('app.admin.members.authentication_form.active');
case 'pending': return _t('app.admin.members.authentication_form.pending');
case 'previous': return _t('app.admin.members.authentication_form.previous_provider');
default: return _t('app.admin.members.authentication_form.unknown') + status;
}
2018-11-21 11:08:53 +01:00
};
2018-11-19 16:17:49 +01:00
/**
* Ask for confirmation then delete the specified provider
* @param providers {Array} full list of authentication providers
* @param provider {Object} provider to delete
*/
2018-11-20 12:26:06 +01:00
$scope.destroyProvider = function (providers, provider) {
dialogs.confirm(
{
resolve: {
object () {
return {
title: _t('app.admin.members.authentication_form.confirmation_required'),
msg: _t('app.admin.members.authentication_form.do_you_really_want_to_delete_the_TYPE_authentication_provider_NAME', { TYPE: $scope.getType(provider.providable_type), NAME: provider.name })
2018-11-21 11:08:53 +01:00
};
}
}
2018-11-20 12:26:06 +01:00
},
2018-11-21 10:59:07 +01:00
function () {
2018-11-20 12:26:06 +01:00
// the admin has confirmed, delete
AuthProvider.delete(
{ id: provider.id },
function () {
2018-11-21 11:08:53 +01:00
providers.splice(findIdxById(providers, provider.id), 1);
growl.success(_t('app.admin.members.authentication_form.authentication_provider_successfully_deleted'));
2018-11-20 12:26:06 +01:00
},
function () { growl.error(_t('app.admin.members.authentication_form.an_error_occurred_unable_to_delete_the_specified_provider')); }
2018-11-21 11:08:53 +01:00
);
}
2018-11-21 11:08:53 +01:00
);
};
}
2016-03-23 18:39:41 +01:00
2018-11-21 11:08:53 +01:00
]);
2016-03-23 18:39:41 +01:00
2018-11-19 16:17:49 +01:00
/**
* Page to add a new authentication provider
*/
Application.Controllers.controller('NewAuthenticationController', ['$scope', '$state', 'growl',
function ($scope, $state, growl) {
2022-04-04 18:19:59 +02:00
/**
* Shows a success message forwarded from a child react component
*/
$scope.onSuccess = function (message) {
growl.success(message);
$scope.cancel();
2022-04-04 18:19:59 +02:00
};
/**
* Callback triggered by react components
*/
$scope.onError = function (message) {
growl.error(message);
};
$scope.cancel = function () { $state.go('app.admin.members'); };
}
2018-11-21 11:08:53 +01:00
]);
2016-03-23 18:39:41 +01:00
2018-11-19 16:17:49 +01:00
/**
* Page to edit an already added authentication provider
*/
Application.Controllers.controller('EditAuthenticationController', ['$scope', '$state', 'growl', 'providerPromise',
function ($scope, $state, growl, providerPromise) {
2018-11-19 16:17:49 +01:00
// parameters of the currently edited authentication provider
$scope.provider = cleanProvider(providerPromise);
2016-03-23 18:39:41 +01:00
/**
* Shows a success message forwarded from a child react component
*/
$scope.onSuccess = function (message) {
growl.success(message);
};
/**
* Callback triggered by react components
*/
$scope.onError = function (message) {
growl.error(message);
};
$scope.cancel = function () { $state.go('app.admin.members'); };
// prepare the provider for the react-hook-form
function cleanProvider (provider) {
delete provider.$promise;
delete provider.$resolved;
return provider;
}
}
2018-11-21 11:08:53 +01:00
]);