-
Notifications
You must be signed in to change notification settings - Fork 16
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
User access management in the client code #768
Comments
If you're happy @marco-brandizi, let's close. |
@Arnedeklerk, @lawal-olaotan this is good, but it requires a few more changes. see the code comments. |
@lawal-olaotan pls remember to add limits for allowing pro users to search with >10 genes selected out of gene view. |
Happy! Looks good, thanks @lawal-olaotan. Closing... |
@lawal-olaotan, @Arnedeklerk sorry, I need to reopen this, cause it still contains things to be fixed: In if (isGeneListRestricted && minimumUserRole == 'pro') {
queryRestriction = `<a class='query-restriction-text' href="https://knetminer.com/pricing-plans" target="_blank" >(Upgrade)</a>`;
} As explained in the comment, the proper way to do this is
|
@marco-brandizi, here are the ways I tried to refine the code based on your last comment. In
In
In There are two roles with the same permission value because the Knetspace API returns a static string |
user-access
This works, but still isn't clean enough: think of a UserRole as an abstract entity, where the only thing that is authoritative for telling the power of a role (and compare it to another role) is Then, you would do the above check this way: // I understand this comes from sample-query.xml
var {minimumUserRole,description,index} = query
// Gets the object from the string
minimumUserRole = UserRole.get ( minimumUserRole )
...
if ( isGeneListRestricted && minimumUserRole.can ( UserRole.PRO ) ) {
...
} There are commented examples in user-access.js, which show similar cases. This might seem nuanced, however:
Moreover, for the above to work, you need to change this too: class UserRole {
...
static can ( role,queryRole ) {
...
}
}
can ( queryRole ) {
return this.compare ( queryRole ) <= 0
} This is what is proposed in the hereby ticket's description above. Actually, I've written Similarly, Also, note that the result of UsetAccessManager checks: if(this.requires('free')){
this.#defaultGeneLimit = 100;
}else if(this.requires('pro')){
this.#isGeneLimitEnforced = false;
this.#defaultKnetViewLimit = 20
} No. if/elseif works only when you scan from the most powerful role to the least one, for if your user is a pro, then first if() sets the free limits and then nothing else is touched. Furthermore, for the reasons said above, it's better to work with if ( this.#currentRole.can ( UserRole.PRO ) ) {
// pro rights and settings, apply to ADMIN, ROOT too
....
}
else if ( this.#currentRole.can ( UserRole.FREE ) // adding this, just to show a complete example
{
// FREE rights, apply to pro too
...
}
else {
// fall back to min rights (ie, guest)
// ===> set these defaults here, not elsewhere, for this is the method that deals with it
...
} Here, I'm not using your Free/registered roles:
I see. One option is to just report this in a comment in |
Writing this after having seen this code in
example-queries.js
:That's too bad, even for an interim codebase. The code is confusing the policy applied to the current user ('anonymous has 20 genes limit') with the task of establishing the kind of current user ('it's a free user, hence it has a 20 genes limit', not the opposite).
This is bad because of multiple reasons:
We need a
userAccessManager
singleton (possibly, define a class first), with the following (it's a draft, to be verified):roles representation: Se the draft below. Something simpler like integer constants is possible, but the example below is more robust, especially for extensions
userAccessManager.getRole ()
Returns the current user's role (as an instance of UserRole)
userAccessManager.getGenesSearchLimit( role = <current> )
The max no of genes the user can search. If role is omitted, use current role
userAccessManager.can( role, testedRole = <current> )
True if the testedRole has the same or higher powers (ie, level) of the role expressed by
the 'role'. This is a wrapper of the
UserRole.can()
method shown belowuserAccessManager.require ( requiredRole, testedRole, currentRole = <current> )
A boolean wrapper of:
Again, role names can be either strings or UserRole(s), currentRole can be omitted.
possibly, other methods, such as
getIsGeneListLimitEnforced ( role = <current> )
(not sure this is necessary, rather than be represented with limit = -1 or max int).This way, the sample query case above would work like:
User roles
The text was updated successfully, but these errors were encountered: