Skip to content

Commit

Permalink
#768 Fixes user access management
Browse files Browse the repository at this point in the history
  • Loading branch information
lawal-olaotan committed Aug 10, 2023
1 parent d42c53b commit e13bc19
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
2 changes: 0 additions & 2 deletions client-base/src/main/webapp/html/javascript/data-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ function searchKeyword() {
function setupGenesSearch()
{
userAccessMgr.setUserPlan();
const geneListLimit = userAccessMgr.getGenesListLimit();
$('.genesCount').html(`0/${geneListLimit}`);
geneCounter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ function knetSpaceProfile() {
return jsonVal;
});
setupGenesSearch();
exampleQuery.renderQueryHtml()
console.log(jsonVal.username);
window.location.reload();
return jsonVal;
}

Expand Down
27 changes: 13 additions & 14 deletions client-base/src/main/webapp/html/javascript/user-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,25 @@ class UserAccessManager{
credentials: 'include'
}).then(async (response)=> {
const data = await response.json();
if(!data.name) return null;
const userPlan = data.plan.name.toLowerCase();
this.#current = userPlan;
this.#setGeneSearchLimit(userPlan);
const userPlan = data.plan?.name.toLowerCase()
if(userPlan.length){
this.#current = userPlan
this.#setGeneSearchLimit();
}

})
}

// Sets geneslist search limit based on current user plan.
// 20 for guest, 100 for registered and unlimited for pro users.
#setGeneSearchLimit(current)
#setGeneSearchLimit()
{
if( current === 'free' )
if( this.#current === 'free' )
{
this.#defaultGeneLimit = 100
}else if(current === 'pro'){
this.#isGeneLimitEnforced = false;
$('.genesCount').html('0/100');
}else if(this.#current === 'pro'){
this.#isGeneLimitEnforced = false;
$('.genesCount').hide();
}
}

Expand All @@ -48,10 +51,6 @@ class UserAccessManager{
}

// Gets geneslist search limit
getGenesListLimit(){
return this.#defaultGeneLimit
}

// Checks if query restriction should be added to example queries.
// Method compare user current role to the roles specified for each example queries.
requires(queryRole){
Expand Down Expand Up @@ -115,7 +114,7 @@ class UserRole {
}
}

const userAccessMgr = Object.freeze(new UserAccessManager());
const userAccessMgr = new UserAccessManager()


// Usage examples
Expand Down

0 comments on commit e13bc19

Please sign in to comment.