Skip to content

Commit

Permalink
(web admin) add front end markup to admin
Browse files Browse the repository at this point in the history
(back end) rename choose_access_duration to set_access_durations to match current set_access_duration
  • Loading branch information
satkunas committed Aug 21, 2019
1 parent 9ffb48e commit 60f3d3a
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,19 @@ sub login : Private {
);
}

=head2 choose_access_duration
=head2 set_access_durations
=cut

sub choose_access_duration : Private {
sub set_access_durations : Private {
my ( $self, $c ) = @_;
if ( $c->has_errors ) {
$c->stash->{txt_auth_error} = join(' ', grep { ref ($_) eq '' } @{$c->error});
$c->clear_errors;
}
$c->stash(
title => "Choose the access duration",
template => $pf::web::guest::SPONSOR_CHOOSE_ACCESS_DURATION_TEMPLATE,
template => $pf::web::guest::SPONSOR_SET_ACCESS_DURATIONS_TEMPLATE,
);
}

Expand Down Expand Up @@ -190,13 +190,13 @@ sub doSponsorRegistration : Private {
$self->showError($c,"does not have permission to sponsor a user");
$c->detach('login');
}
if ($values->{$Actions::CHOOSE_ACCESS_DURATION}) {
if ($values->{$Actions::SET_ACCESS_DURATIONS}) {
if ($request->param("access_duration")) {
pf::activation::set_unregdate('sponsor',$activation_record->{'activation_code'}, pf::config::access_duration($request->param("access_duration")));
} else {
my @options_duration = map { { value => $_, label => $_ } } split(',', $values->{$Actions::CHOOSE_ACCESS_DURATION});
$c->stash->{choose_access_duration} = \@options_duration;
$c->detach('choose_access_duration');
my @options_duration = map { { value => $_, label => $_ } } split(',', $values->{$Actions::SET_ACCESS_DURATIONS});
$c->stash->{set_access_durations} = \@options_duration;
$c->detach('set_access_durations');
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<div class="o-layout o-layout--center u-padding">

<div class="o-layout__item u-1/1 u-2/3@tablet u-3/5@desktop">
[% IF choose_access_duration.size > 1 %]
[% IF set_access_durations.size > 1 %]
<div class="input-container">
<label>[% i18n("Access duration") %]</label>
<select name="access_duration">
<option value="">[% i18n('Select access duration') %]</option>
[% FOREACH access_duration IN choose_access_duration %]
[% FOREACH access_duration IN set_access_durations %]
<option value='[% access_duration.value %]'>[% access_duration.label %]</option>
[% END %]
</select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ our %ACTION_FIELD_OPTIONS = (
type => 'Hidden',
default => '1'
},
$Actions::CHOOSE_ACCESS_DURATION => {
$Actions::SET_ACCESS_DURATIONS => {
type => 'Select',
do_label => 0,
wrapper => 0,
multiple => 1,
element_class => ['chzn-select'],
element_attr => {'data-placeholder' => 'Click to add a access duration'},
element_attr => {'data-placeholder' => 'Click to add an access duration'},
options_method => \&options_durations,
},
$Actions::SET_ACCESS_LEVEL => {
Expand All @@ -76,7 +76,7 @@ our %ACTION_FIELD_OPTIONS = (
wrapper => 0,
multiple => 1,
element_class => ['chzn-select'],
element_attr => {'data-placeholder' => 'Click to add a access right'},
element_attr => {'data-placeholder' => 'Click to add an access right'},
options_method => \&options_access_level,
},
$Actions::SET_TENANT_ID => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
</b-col>
<b-col sm="6" align-self="start" class="pl-1">

<!-- Types: OPTIONS, ADMINROLE, ROLE, ROLE_BY_NAME, TENANT, DURATION, TIME_BALANCE -->
<!-- Types: OPTIONS, ADMINROLE, ROLE, ROLE_BY_NAME, TENANT, DURATION, DURATIONS, TIME_BALANCE -->
<pf-form-chosen v-if="
isFieldType(optionsType) ||
isFieldType(adminroleValueType) ||
isFieldType(roleValueType) ||
isFieldType(roleByNameValueType) ||
isFieldType(tenantValueType) ||
isFieldType(durationValueType) ||
isFieldType(durationsValueType) ||
isFieldType(timeBalanceValueType)
"
v-model="localValue"
Expand All @@ -41,6 +42,7 @@
ref="localValue"
label="name"
track-by="value"
:multiple="isFieldType(durationsValueType)"
:placeholder="placeholder"
:vuelidate="valueVuelidateModel"
:invalid-feedback="valueInvalidFeedback"
Expand Down Expand Up @@ -153,6 +155,7 @@ export default {
/* Promise based field types */
adminroleValueType: fieldType.ADMINROLE,
durationValueType: fieldType.DURATION,
durationsValueType: fieldType.DURATIONS,
roleValueType: fieldType.ROLE,
roleByNameValueType: fieldType.ROLE_BY_NAME,
tenantValueType: fieldType.TENANT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,20 @@ export const pfConfigurationActions = {
}
}
},
set_access_durations: {
value: 'set_access_durations',
text: i18n.t('Access durations'),
types: [fieldType.DURATIONS],
validators: {
type: {
/* Don't allow elsewhere */
[i18n.t('Duplicate action.')]: limitSiblingFields('type', 0)
},
value: {
[i18n.t('Value required.')]: required
}
}
},
set_access_level: {
value: 'set_access_level',
text: i18n.t('Access level'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,15 @@ export const pfConfigurationAuthenticationSourceFields = {
typeLabel: i18n.t('Select action type'),
valueLabel: i18n.t('Select action value'),
fields: [
pfConfigurationActions.set_access_level,
pfConfigurationActions.mark_as_sponsor,
pfConfigurationActions.set_tenant_id
...((['AD', 'LDAP'].includes(sourceType))
? [pfConfigurationActions.set_access_durations]
: []
),
...[
pfConfigurationActions.set_access_level,
pfConfigurationActions.mark_as_sponsor,
pfConfigurationActions.set_tenant_id
]
]
},
invalidFeedback: [
Expand Down Expand Up @@ -1654,6 +1660,20 @@ export const pfConfigurationAuthenticationSourceFields = {
]
}
},
sources: ({ options: { meta = {} } } = {}) => {
return {
label: i18n.t('Associated Sources'),
text: i18n.t('Sources that will be associated with this source (For the Sponsor)'),
fields: [
{
key: 'sources',
component: pfFormChosen,
attrs: pfConfigurationAttributesFromMeta(meta, 'sources'),
validators: pfConfigurationValidatorsFromMeta(meta, 'sources', i18n.t('Sources'))
}
]
}
},
sp_cert_path: ({ options: { meta = {} } } = {}) => {
return {
label: i18n.t('Path to Service Provider cert (x509)'),
Expand Down Expand Up @@ -2318,6 +2338,7 @@ export const pfConfigurationAuthenticationSourceViewFields = (context) => {
fields: [
pfConfigurationAuthenticationSourceFields.id(context),
pfConfigurationAuthenticationSourceFields.description(context),
pfConfigurationAuthenticationSourceFields.sources(context),
pfConfigurationAuthenticationSourceFields.allow_localdomain(context),
pfConfigurationAuthenticationSourceFields.banned_domains(context),
pfConfigurationAuthenticationSourceFields.allowed_domains(context),
Expand Down
5 changes: 5 additions & 0 deletions html/pfappserver/root/static.alt/src/globals/pfField.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const pfFieldType = {
/* Promise based field types */
ADMINROLE: 'adminrole',
DURATION: 'duration',
DURATIONS: 'durations',
OPTIONS: 'options',
REALM: 'realm',
ROLE: 'role',
Expand All @@ -43,6 +44,10 @@ pfFieldTypeValues[pfFieldType.DURATION] = ({ $store }) => {
$store.dispatch('config/getBaseGuestsAdminRegistration')
return $store.getters['config/accessDurationsList']
}
pfFieldTypeValues[pfFieldType.DURATIONS] = ({ $store }) => {
$store.dispatch('config/getBaseGuestsAdminRegistration')
return $store.getters['config/accessDurationsList']
}
pfFieldTypeValues[pfFieldType.OPTIONS] = ({ field }) => {
let options = []
if (field === undefined) {
Expand Down
12 changes: 6 additions & 6 deletions lib/pf/Authentication/constants.pm
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Constants related to actions rules.

package Actions;

=item MARK_AS_SPONSOR, CHOOSE_ACCESS_DURATION, SET_ACCESS_LEVEL, SET_ROLE, SET_ACCESS_DURATION, SET_UNREG_DATE SET_TIME_BALANCE, SET_BANDWIDTH_BALANCE
=item MARK_AS_SPONSOR, SET_ACCESS_LEVEL, SET_ROLE, SET_ACCESS_DURATION, SET_ACCESS_DURATIONS, SET_UNREG_DATE SET_TIME_BALANCE, SET_BANDWIDTH_BALANCE
Available actions
Expand All @@ -158,10 +158,10 @@ Readonly::Scalar our $SET_ACCESS_LEVEL => "set_access_level";
Readonly::Scalar our $SET_TENANT_ID => "set_tenant_id";
Readonly::Scalar our $SET_ROLE => "set_role";
Readonly::Scalar our $SET_ACCESS_DURATION => "set_access_duration";
Readonly::Scalar our $SET_ACCESS_DURATIONS => "set_access_durations";
Readonly::Scalar our $SET_UNREG_DATE => "set_unreg_date";
Readonly::Scalar our $SET_TIME_BALANCE => "set_time_balance";
Readonly::Scalar our $SET_BANDWIDTH_BALANCE => "set_bandwidth_balance";
Readonly::Scalar our $CHOOSE_ACCESS_DURATION => "choose_access_duration";
=item ACTIONS
List of available actions
Expand All @@ -170,7 +170,7 @@ List of available actions

Readonly::Hash our %ACTIONS => (
$Rules::AUTH => [ $SET_ROLE, $SET_ACCESS_DURATION, $SET_UNREG_DATE, $SET_TIME_BALANCE, $SET_BANDWIDTH_BALANCE ],
$Rules::ADMIN => [ $SET_ACCESS_LEVEL, $MARK_AS_SPONSOR, $SET_TENANT_ID, $CHOOSE_ACCESS_DURATION ],
$Rules::ADMIN => [ $SET_ACCESS_LEVEL, $MARK_AS_SPONSOR, $SET_TENANT_ID, $SET_ACCESS_DURATIONS ],
);

Readonly::Hash our %ACTION_CLASS_TO_TYPE => (
Expand All @@ -183,7 +183,7 @@ Readonly::Hash our %ACTION_CLASS_TO_TYPE => (
$SET_ACCESS_LEVEL => $Rules::ADMIN,
$SET_TENANT_ID => $Rules::ADMIN,
$MARK_AS_SPONSOR => $Rules::ADMIN,
$CHOOSE_ACCESS_DURATION => $Rules::ADMIN,
$SET_ACCESS_DURATIONS => $Rules::ADMIN,
);

Readonly::Hash our %ALLOWED_ACTIONS => (
Expand All @@ -197,17 +197,17 @@ Readonly::Hash our %ALLOWED_ACTIONS => (
},
$SET_TIME_BALANCE => {$SET_TIME_BALANCE => 1},
$SET_BANDWIDTH_BALANCE => {$SET_BANDWIDTH_BALANCE => 1},
$CHOOSE_ACCESS_DURATION => {$CHOOSE_ACCESS_DURATION => 1},
$SET_ACCESS_DURATIONS => {$SET_ACCESS_DURATIONS => 1},
);

Readonly::Hash our %MAPPED_ACTIONS => (
$MARK_AS_SPONSOR => $MARK_AS_SPONSOR,
$SET_ACCESS_LEVEL => $SET_ACCESS_LEVEL,
$CHOOSE_ACCESS_DURATION => $CHOOSE_ACCESS_DURATION,
$SET_TENANT_ID => $SET_TENANT_ID,
$SET_ROLE => $SET_ROLE,
$SET_UNREG_DATE => $SET_UNREG_DATE,
$SET_ACCESS_DURATION => $SET_UNREG_DATE,
$SET_ACCESS_DURATIONS => $SET_ACCESS_DURATIONS,
);

=back
Expand Down
2 changes: 1 addition & 1 deletion lib/pf/web/guest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ our $VERSION = 1.41;

our $SPONSOR_CONFIRMED_TEMPLATE = "activation/sponsor_accepted.html";
our $SPONSOR_LOGIN_TEMPLATE = "activation/sponsor_login.html";
our $SPONSOR_CHOOSE_ACCESS_DURATION_TEMPLATE = "activation/sponsor_choose_access_duration.html";
our $SPONSOR_SET_ACCESS_DURATIONS_TEMPLATE = "activation/sponsor_set_access_durations.html";

# flag used in URLs
Readonly our $GUEST_REGISTRATION => "guest-register";
Expand Down

0 comments on commit 60f3d3a

Please sign in to comment.