Skip to content

Commit

Permalink
Merge pull request #867 from oceanzus/master_192_14783
Browse files Browse the repository at this point in the history
Updates scope rendering. (14783)
  • Loading branch information
oceanzus authored Jun 29, 2020
2 parents c242631 + af121a5 commit 6c5a19e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
9 changes: 7 additions & 2 deletions ooiui/static/js/partials/UserEditForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ <h3>Profile</h3>
<span class="help-block hidden"></span>
</div>
</div>
<div class="form-group" id="active_div">

<% if(isAdmin === true) { %>
<div class="form-group" id="active_div" hidden>
<label class="col-sm-3 control-label">Account Enabled</label>
<div class="col-sm-6">
<input type="checkbox" class="form-control" id="active" name="active" style="box-shadow:inset 0 1px 1px rgba(255, 255, 255, 0.075);" />
<span class="help-block hidden"></span>
</div>
</div>
<% } %>

<hr width ="80%">

Expand Down Expand Up @@ -116,7 +119,8 @@ <h3>Profile</h3>
<button type="button" id="refreshTokenButton" class="btn btn-success">Refresh API Token</button>
</div>

<div id="scope_div">
<% if(isAdmin === true) { %>
<div id="scope_div" hidden>
<h3> User Scopes </h3>
<div class="form-group">
<% scopes.each(function(scope) { %>
Expand All @@ -129,6 +133,7 @@ <h3> User Scopes </h3>
<% }); %>
</div>
</div>
<% } %>

<hr width="80%">

Expand Down
28 changes: 22 additions & 6 deletions ooiui/static/js/views/common/UserEditFormView.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,46 @@ var UserEditFormView = Backbone.View.extend({
},
template: JST['ooiui/static/js/partials/UserEditForm.html'],
render: function() {
this.$el.html(this.template({scopes: this.scopes}));
let self = this;
let isAdmin = false;
// Only allow scope modification if
var userModel = new UserModel();
let userModel = new UserModel();
userModel.url = '/api/current_user';

userModel.fetch({
success: function(collection, response, options) {
var scopes = response.scopes;
let scopes = response.scopes;
self.userScopes = scopes;

if(scopes.includes('user_admin')){
if(scopes.includes('user_admin')) {
isAdmin = true;
}

// Check if the user is an admin and only render the scopes if so.
if (isAdmin === true) {
self.$el.html(self.template({scopes: self.scopes, isAdmin: isAdmin}));
self.$el.append(self.modalDialog.el);
self.stickit();
} else {
self.$el.html(self.template({scopes: [], isAdmin: isAdmin}));
self.$el.append(self.modalDialog.el);
self.stickit();
}

if(isAdmin === true){
$("#scope_div").show();
$("#active_div").show();
} else {
$("#scope_div").hide();
$("#active_div").hide();
}

},
error:function(collection, response, options) {
console.log('Error getting user data');
}
});

this.$el.append(this.modalDialog.el);
this.stickit();

}
});
7 changes: 7 additions & 0 deletions ooiui/static/json/uiPatchNotes.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
[
{
"VersionNumber": "1.9.2",
"VersionDate": "2020-06-29",
"VersionDescription": [
"Security: Fixes user profile scope rendering. (14783)"
]
},
{
"VersionNumber": "1.9.1",
"VersionDate": "2020-06-09",
Expand Down

0 comments on commit 6c5a19e

Please sign in to comment.