Skip to content

Commit

Permalink
Prevent reload of user object during logout for specific user role. (c…
Browse files Browse the repository at this point in the history
  • Loading branch information
pfirpfel authored and Gabathuler committed Mar 1, 2018
1 parent 40bae6e commit 66101bf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
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

0 comments on commit 66101bf

Please sign in to comment.