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

Show login form when restricted layers in permalink #4256

Merged
merged 1 commit into from
Sep 28, 2018
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
4 changes: 3 additions & 1 deletion contribs/gmf/apps/desktop/index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@
{{'Login' | translate}}
<a class="btn close" ng-click="mainCtrl.loginActive = false">&times;</a>
</div>
<gmf-authentication></gmf-authentication>
<gmf-authentication
gmf-authentication-info-message="mainCtrl.loginInfoMessage"
></gmf-authentication>
</div>
</div>
<div ng-show="mainCtrl.printPanelActive" class="row">
Expand Down
1 change: 1 addition & 0 deletions contribs/gmf/apps/desktop_alt/index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<a class="btn close" ng-click="mainCtrl.loginActive = false">&times;</a>
</div>
<gmf-authentication
gmf-authentication-info-message="mainCtrl.loginInfoMessage"
gmf-authentication-allow-password-reset="::false"
gmf-authentication-allow-password-change="::false">
</gmf-authentication>
Expand Down
1 change: 1 addition & 0 deletions contribs/gmf/apps/mobile/index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
</ul>
</div>
<gmf-authentication id="login" class="gmf-mobile-nav-slide" data-header-title="{{'Login' | translate}}"
gmf-authentication-info-message="mainCtrl.loginInfoMessage"
gmf-mobile-nav-back="authCtrl.gmfUser.username !== null">
</gmf-authentication>
</nav>
Expand Down
1 change: 1 addition & 0 deletions contribs/gmf/apps/mobile_alt/index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
</ul>
</div>
<gmf-authentication id="login" class="gmf-mobile-nav-slide" data-header-title="{{'Login' | translate}}"
gmf-authentication-info-message="mainCtrl.loginInfoMessage"
gmf-mobile-nav-back="authCtrl.gmfUser.username !== null">
</gmf-authentication>
</nav>
Expand Down
5 changes: 5 additions & 0 deletions contribs/gmf/src/authentication/component.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ <h4 class="modal-title">
</div>

<div ng-if="!$ctrl.gmfUser.username">

<div class="alert alert-warning" ng-show="$ctrl.infoMessage">
<span>{{ $ctrl.infoMessage }}</span>
</div>

<form
name="loginForm"
role="form"
Expand Down
11 changes: 10 additions & 1 deletion contribs/gmf/src/authentication/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function gmfAuthenticationTemplateUrl($element, $attrs, gmfAuthenticationTemplat
* Example:
*
* <gmf-authentication
* gmf-authentication-info-message="mainCtrl.loginInfoMessage"
* gmf-authentication-allow-password-change="::true">
* </gmf-authentication>
*
Expand All @@ -80,6 +81,7 @@ function gmfAuthenticationTemplateUrl($element, $attrs, gmfAuthenticationTemplat
* should also allow the user to change its password. Don't add this option alone, use
* it in a dedicated authentication component, in a ngeo-modal, directly in
* your index.html (see example 2.)
* @htmlAttribute {string} gmf-authentication-info-message Message to show above the authentication form.
*
* Example 2:
*
Expand Down Expand Up @@ -107,7 +109,8 @@ exports.component_ = {
'allowPasswordReset': '<?gmfAuthenticationAllowPasswordReset',
'allowPasswordChange': '<?gmfAuthenticationAllowPasswordChange',
'passwordValidator': '<?gmfAuthenticationPasswordValidator',
'forcePasswordChange': '<?gmfAuthenticationForcePasswordChange'
'forcePasswordChange': '<?gmfAuthenticationForcePasswordChange',
'infoMessage': '=?gmfAuthenticationInfoMessage'
},
controller: 'GmfAuthenticationController',
templateUrl: gmfAuthenticationTemplateUrl
Expand Down Expand Up @@ -190,6 +193,12 @@ exports.AuthenticationController_ = class {
*/
this.forcePasswordChange;

/**
* @type {?string}
* @export
*/
this.infoMessage = null;

/**
* @type {boolean}
* @export
Expand Down
34 changes: 34 additions & 0 deletions contribs/gmf/src/controllers/AbstractAppController.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,44 @@ const exports = function(config, $scope, $injector) {
});
};

/**
* Url to redirect to after login success.
* @type {?string}
*/
this.loginRedirectUrl = null;

/**
* Information message for the login form.
* @type {?string}
*/
this.loginInfoMessage = null;

$scope.$on('authenticationrequired', (event, args) => {
/** @type {angularGettext.Catalog} */
const gettextCatalog = $injector.get('gettextCatalog');
this.loginInfoMessage = gettextCatalog.getString(
'Some layers in this link are not accessible to unauthenticated users. ' +
'Please log in to see whole data.');
this.loginRedirectUrl = args.url;
this.loginActive = true;

const unbind = $scope.$watch(() => this.loginActive, () => {
if (!this.loginActive) {
this.loginInfoMessage = null;
this.loginRedirectUrl = null;
unbind();
}
});
});

/**
* @param {gmfx.AuthenticationEvent} evt Event.
*/
const userChange = (evt) => {
if (this.loginRedirectUrl) {
window.location = this.loginRedirectUrl;
return;
}
const user = evt.detail.user;
const roleId = (user.username !== null) ? user.role_id : undefined;

Expand Down
25 changes: 24 additions & 1 deletion contribs/gmf/src/permalink/Permalink.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ import olLayerGroup from 'ol/layer/Group.js';
* @param {ngeo.misc.EventHelper} ngeoEventHelper Ngeo event helper service
* @param {ngeo.statemanager.Service} ngeoStateManager The ngeo statemanager service.
* @param {ngeo.statemanager.Location} ngeoLocation ngeo location service.
* @param {gmfx.User} gmfUser User.
* @ngInject
* @ngdoc service
* @ngname gmfPermalink
*/
const exports = function($q, $timeout, $rootScope, $injector, ngeoDebounce, gettextCatalog, ngeoEventHelper,
ngeoStateManager, ngeoLocation) {
ngeoStateManager, ngeoLocation, gmfUser) {

/**
* @type {!angular.$q}
Expand Down Expand Up @@ -216,6 +217,12 @@ const exports = function($q, $timeout, $rootScope, $injector, ngeoDebounce, gett
this.gmfTreeManager_ = $injector.has('gmfTreeManager') ?
$injector.get('gmfTreeManager') : null;

/**
* @type {gmfx.User}
* @private
*/
this.user_ = gmfUser;

// == other properties ==

/**
Expand Down Expand Up @@ -467,6 +474,7 @@ const exports = function($q, $timeout, $rootScope, $injector, ngeoDebounce, gett
this.initLayers_();
};


// === Map X, Y, Z ===

/**
Expand Down Expand Up @@ -910,6 +918,9 @@ exports.prototype.defaultThemeNameFromFunctionalities = function() {
* @private
*/
exports.prototype.initLayers_ = function() {
const initialUri = window.location.href;
let authenticationRequired = false;

if (!this.gmfThemes_) {
return;
}
Expand Down Expand Up @@ -939,6 +950,8 @@ exports.prototype.initLayers_ = function() {
const group = gmfThemeThemes.findGroupByName(themes, groupName);
if (group) {
firstLevelGroups.push(group);
} else {
authenticationRequired = true;
}
});
}
Expand Down Expand Up @@ -984,9 +997,15 @@ exports.prototype.initLayers_ = function() {
treeCtrl.traverseDepthFirst((treeCtrl) => {
if (treeCtrl.node.children === undefined) {
const enable = olArray.includes(groupLayersArray, treeCtrl.node.name);
if (enable) {
groupLayersArray.splice(groupLayersArray.indexOf(treeCtrl.node.name), 1);
}
treeCtrl.setState(enable ? 'on' : 'off', false);
}
});
if (groupLayersArray.length > 0) {
authenticationRequired = true;
}
}
}
});
Expand All @@ -999,6 +1018,10 @@ exports.prototype.initLayers_ = function() {
}
});
});

if (authenticationRequired && this.user_.role_id === null) {
this.rootScope_.$broadcast('authenticationrequired', {url: initialUri});
}
});
});
};
Expand Down