Skip to content

Commit

Permalink
✨ Refresh & document OIDC support (#407)
Browse files Browse the repository at this point in the history
Parent issue: sequentech/meta#256
  • Loading branch information
edulix authored Nov 13, 2023
1 parent db10b15 commit 727c2f1
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 30 deletions.
4 changes: 4 additions & 0 deletions avAdmin/admin-directives/dashboard/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ angular.module('avAdmin')
}
}
}
if (el.oidc_providers && el.census) {
el.census.oidc_providers = el.oidc_providers;
delete el.oidc_providers;
}
if (
el.scheduled_events &&
el.scheduled_events.start_voting &&
Expand Down
14 changes: 7 additions & 7 deletions avAdmin/admin-directives/dashboard/send-auth-codes-modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h4 class="modal-title">
</p>
<!-- SMS conf -->
<div class="container-fluid form-group">
<div class="row" ng-if="selectable_auth_method">
<div class="row" ng-if="available_sending_methods.length > 1">
<!-- Auth method -->
<div class="form-group">
<label
Expand All @@ -35,17 +35,17 @@ <h4 class="modal-title">
<div class="col-xs-9">
<div
class="radio"
ng-repeat="a in auth"
ng-repeat="sending_method in available_sending_methods"
>
<label>
<input
type="radio"
name="auth"
ng-value="a"
id="{{a}}"
ng-value="sending_method"
id="{{sending_method}}"
ng-model="selected_auth_method.ref"
/>
<span ng-i18next="avAdmin.auth.auths.{{ a }}">
<span ng-i18next="avAdmin.auth.auths.{{ sending_method }}">
</span>
</label>
</div>
Expand All @@ -54,7 +54,7 @@ <h4 class="modal-title">
</div>
<div class="row">
<div
ng-if="'sms' === selected_auth_method.ref || 'sms-otp' === selected_auth_method.ref"
ng-if="'sms' === selected_auth_method.ref"
>
<div class="form-group">
<label
Expand All @@ -75,7 +75,7 @@ <h4 class="modal-title">
</div>
</div>
<!-- Email conf -->
<div ng-if="'email' === selected_auth_method.ref || 'email-otp' === selected_auth_method.ref">
<div ng-if="'email' === selected_auth_method.ref">
<div class="form-group">
<label
class="col-xs-3 control-label text-right padding-top-input"
Expand Down
11 changes: 8 additions & 3 deletions avAdmin/admin-directives/dashboard/send-auth-codes-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ angular
user_ids
) {
$scope.election = election;
$scope.auth = ['email', 'sms'];
$scope.selectable_auth_method = SendMsg.selectable_auth_method;
$scope.selected_auth_method = { ref: SendMsg.selected_auth_method };
$scope.available_sending_methods = SendMsg.getAvailableSendingMethods();
$scope.selected_auth_method = {
ref: (
$scope.available_sending_methods.length > 0 ?
$scope.available_sending_methods[0] :
election.census.auth_method
)
};
$scope.user_ids = user_ids;
$scope.steps = SendMsg.steps;
$scope.censusConfig = SendMsg.censusConfig;
Expand Down
1 change: 1 addition & 0 deletions avAdmin/elections-api-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ angular.module('avAdmin')
el.hide_default_login_lookup_field = electionAuth.hide_default_login_lookup_field;
el.allow_public_census_query = electionAuth.allow_public_census_query;
el.scheduled_events = electionAuth.scheduled_events;
el.oidc_providers = electionAuth.oidc_providers;

el.census.extra_fields = electionAuth.extra_fields;
el.census.admin_fields = electionAuth.admin_fields;
Expand Down
4 changes: 1 addition & 3 deletions avAdmin/must-extra-fields-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ angular.module('avAdmin')
mustFields = [{
"must": true,
"name": "sub",
"type": "text",
"type": "email",
"required": true,
"min": 1,
"max": 255,
Expand Down Expand Up @@ -145,8 +145,6 @@ angular.module('avAdmin')
extra_field.type = 'text';
} else if ('password' === extra_field.name) {
extra_field.type = 'password';
} else if ('sub' === extra_field.name) {
extra_field.type = 'text';
}
} else {
extra_field.must = false;
Expand Down
59 changes: 42 additions & 17 deletions avAdmin/send-messages-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,32 +108,59 @@ angular
service.sendAuthCodesModal();
};


/**
* Checks whether the extra_field of an election allows other auth methods.
* Returns a list of available methods of sending messages, which depends on
* election extra_fields and auth_methods configuration.
*
* Example return: ['email', 'sms']
*/
service.authMethodIsSelectable = function () {
service.getAvailableSendingMethods = function ()
{
var sendingMethods = [];

function getExtraField(name) {
function containsExtraFieldType(extraFieldType) {
for (var i = 0; i < service.election.census.extra_fields.length; i++) {
if(service.election.census.extra_fields[i].type === name) {
if(service.election.census.extra_fields[i].type === extraFieldType) {
return service.election.census.extra_fields[i];
}
}
return false;
}

if(_.contains(['sms', 'sms-otp'], service.election.census.auth_method)) {
var email_field = getExtraField('email');
if(email_field && 'email' === email_field.type) {
return true;
}
} else if(_.contains(['email', 'email-otp'], service.election.census.auth_method)) {
var tlf_field = getExtraField('tlf');
if(tlf_field && 'tlf' === tlf_field.type) {
return true;
}
if(
_.contains(['sms', 'sms-otp'], service.election.census.auth_method) ||
(
service.election.census.alternative_auth_methods &&
_.find(
service.election.census.alternative_auth_methods,
function (alternative_auth_method) {
return _.contains(
['sms', 'sms-otp'], alternative_auth_method.auth_method_name
);
}
)
) || containsExtraFieldType('tlf')
) {
sendingMethods.push('sms');
}
if(
_.contains(['email', 'email-otp'], service.election.census.auth_method) ||
(
service.election.census.alternative_auth_methods &&
_.find(
service.election.census.alternative_auth_methods,
function (alternative_auth_method) {
return _.contains(
['email', 'email-otp'], alternative_auth_method.auth_method_name
);
}
)
) || containsExtraFieldType('email')
) {
sendingMethods.push('email');
}
return false;
return sendingMethods;
};

/**
Expand All @@ -152,8 +179,6 @@ angular
return;
}

service.selectable_auth_method = service.authMethodIsSelectable();
service.selected_auth_method = angular.copy(service.election.census.auth_method);
// If skip dialog flag is activated, then we jump directly to the
// confirmation step
if (service.skipEditDialogFlag)
Expand Down

0 comments on commit 727c2f1

Please sign in to comment.