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

Prevent reload of user object during logout for specific user role. #3579

Merged
merged 1 commit into from
Feb 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion contribs/gmf/src/controllers/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ gmf.AbstractController.prototype.setDefaultBackground_ = function(theme) {
// get the background from the permalink
layer = this.permalink_.getBackgroundLayer(layers);

if (!layer) {
if (!layer && this.gmfUser.functionalities) {
// get the background from the user settings
layer = gmf.AbstractController.getLayerByLabels(layers, this.gmfUser.functionalities.default_basemap);
}
Expand Down
29 changes: 24 additions & 5 deletions contribs/gmf/src/services/authenticationservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ ol.inherits(gmf.AuthenticationEvent, ol.events.Event);
* @struct
* @extends {ol.events.EventTarget}
* @param {angular.$http} $http Angular http service.
* @param {angular.$injector} $injector Main injector.
* @param {string} authenticationBaseUrl URL to "authentication" web service.
* @param {gmfx.User} gmfUser User.
* @ngInject
*/
gmf.Authentication = function($http, authenticationBaseUrl, gmfUser) {
gmf.Authentication = function($http, $injector, authenticationBaseUrl, gmfUser) {

ol.events.EventTarget.call(this);

Expand All @@ -133,6 +134,16 @@ gmf.Authentication = function($http, authenticationBaseUrl, gmfUser) {
*/
this.user_ = gmfUser;

/**
* Don't request a new user object from the back-end after
* logging out if the logged-in user's role has this role.
* @type {?string}
* @private
*/
this.noReloadRole_ = $injector.has('gmfAuthenticationNoReloadRole')
? $injector.get('gmfAuthenticationNoReloadRole')
: null;

this.load_();
};
ol.inherits(gmf.Authentication, ol.events.EventTarget);
Expand Down Expand Up @@ -197,9 +208,11 @@ gmf.Authentication.prototype.login = function(login, pwd) {
* @export
*/
gmf.Authentication.prototype.logout = function() {
const noReload = this.user_['role_name'] === this.noReloadRole_;
const url = `${this.baseUrl_}/${gmf.AuthenticationRouteSuffix.LOGOUT}`;
return this.$http_.get(url, {withCredentials: true}).then(
this.resetUser_.bind(this));
return this.$http_.get(url, {withCredentials: true}).then(() => {
this.resetUser_(noReload);
});
};


Expand Down Expand Up @@ -278,14 +291,20 @@ gmf.Authentication.prototype.setUser_ = function(respData, emitEvent) {

/**
* @private
* @param {boolean} noReload Don't request a new user object from
* the back-end after logging out, defaults to false.
*/
gmf.Authentication.prototype.resetUser_ = function() {
gmf.Authentication.prototype.resetUser_ = function(noReload) {
noReload = noReload || false;
for (const key in this.user_) {
this.user_[key] = null;
}
this.dispatchEvent(new gmf.AuthenticationEvent(
gmf.AuthenticationEventType.LOGOUT, this.user_));
this.load_();

if (!noReload) {
this.load_();
}
};


Expand Down