logged in: what role am I?

logged in: what role am I?

by tony chesney -
Number of replies: 12

Once I have logged in, does Moodle allow me to know what role I am (or does this depend on what role I have!?). 

If I click on my name in "You are logged on as [myname]" it doesn't seem to tell me, although there is a tab allowing me to Assign roles:  is that a clue?

Average of ratings: -
In reply to tony chesney

Re: logged in: what role am I?

by John Isner -
In reply to John Isner

Re: logged in: what role am I?

by tony chesney -
Having read through this thread, and tried Tim's print_object($USER); at various points, I have a slightly better understanding; nonetheless as I use moodle at any given point I am in a particular context, and, at least as I understand it, have a Role. Otherwise what do "Switch role to..." and "Return to my normal role" mean?

What I'm trying to find out is can I find out what Role I have at a given point? I note that the $USER object doesn't contain this information, at least not directly.


In reply to tony chesney

Re: logged in: what role am I?

by John Isner -
Hi Dave,
The question is not "What Role do I have at a given point"" but "What are my permissions at a given point?"

If you know your current context (which isn't always obvious) , you can use the information in $USER->access to look "up" through the context stack (all the way back to System) and see the roles that have been assigned to you at each level, as well as the overrides, if any. The permissions from all of these (i.e., the individual capability values) are combined to yield the permissions you have in your current context. This is not a "role" per se, but just the result of combining multiple roles and overrides. When capabilities don't conflict, they just add up in a commonsense way. When they conflict, they are resolved by an algorithm described in the developer documentation. Frankly, I don't understand what the algorithm does in certain pathological cases, which is what led to the discussion that I pointed you to. As a result of that discussion and others, I hope that we will soon have a nice interface that makes roles more transparent (vote for MDL-13228).
In reply to John Isner

Re: logged in: what role am I?

by tony chesney -
Hi
It's all helpful, but I'm still not sure.
In a given context at a given point or "state" or "level", do I have one, and only one, role? Or is it more like a super-role made up of aggregating permissions that I got from having roles at lower contexts?

Do you have a single role when you first log in, and you're at the most basic context (the homepage I suppose)?

We're using moodle 1.8, and $USER->access doesn't seem to return anything.
In reply to tony chesney

Re: logged in: what role am I?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The point (state or level) is what we call the context. It is where you currently are in the site - where the web page you are currently looking at is. The way to think of this is like a file path. If you are thinking about a word document on your hard disc, it might be in folder "VLE docs", but that is acutally
C:\Documents and Settings\timhunt\My Documents\VLE docs\spec.doc 
Similarly, this forum is Forum: Roles and Capabilities, but actually, that is

Site: moodle.org/Category: Community Discussion (in English)/Course: Using Moodle/Forum: Roles and Capabilities


You don't just have a single role. The most normal situation is that you have two. At the moment (assuming you are logged in) you are assigned the role "Logged in user" in context Site: moodle.org. Since this forum is inside the site, that role applies here. Second, you have been assigned the role "Moodler" in context Course: Using Moodle (this happened when you first came here, were asked if wanted to enrol, and clicked yet). Since this forum is inside that course, that role applies here too. So (as I said was normal) in this forum you have two roles. If, however, you go and look at the list of courses in category Community Discussion (in English), then you will only have one role (Logged in user) there, because that category is outside the course. If you were not logged in when looking at this forum (or anywhere else), you would just have one role "Guest", assigned in context Site: moodle.org, and so applying here too.


What a role actually gives you is a defined permission for each capability. A capability is a specific thing that you might, or might not, be allowed to do. For example mod/forum:viewdiscussion, or mod/forum:replypost. A permission on that capability is basically either Allow or Prevent (I am simplifying slightly here).


What actually determines whether you can do a particular thing in a particular context is the computed permission you have for that capability. This is a combination of the permissions you have from each role that applies in this context. The precise rules here are complicated but roughly it is "Count +1 foreach allow, -1 for each prevent. If the total is > 0, the computed permission is allow; if the
total is < 0, it is prevent; in the case of a tie, apply some tie-breaking rules."


There is one more concept to understand, and that is overrides. Above I talked about the defined permissions for a role. Normally, roles are just defined in the site context (for example saying that Moodlers are allowed to
mod/forum:replypost), and that definition applies everywhere. But suppose in one particular forum (e.g. the news forum) you want to change the definition, so Moodlers can't reply there. Well, you can do that by overriding the Moodler role in the context of that forum to change the permission.

Overrides just make the "complicated rules for working out the computed permission" more complicated. Fortunately, you don't really need to understand these rules. They normally do what you expect (and the reason they are very hard to write down precisely is that human common sense is very hard to describe and explain to a computer).


P.S. the terms I have put into bold are a combination of existing ones (context, role, assign, permission, capability, override) that are currently used in the code and user interface and explained on MoodleDocs; and some I made up just now because I thought they made this explanation clearer (applies, defined/computed permission).
Average of ratings: Useful (7)
In reply to Tim Hunt

Re: logged in: what role am I?

by John Isner -
Tim,
You say (apropos of how the conflict resolution rules are affected by overrides) "you don't really need to understand these rules."

But there are people (like me) whose job is to explain roles to other people. Unless I understand something, I cannot tell them "you don't really need to understand this." It would be intellectually dishonest to do so. So I really do need to understand these rules.

So here is how I have been explaining it. I'm not sure if the explanation is correct, and if not, I would dearly appreciate your help with it.

Suppose you assign role R in context C1. Then you override R in a lower context C2, setting permissions for X, Y, and Z. This is equivalent to assigning role R' in C2 with X, Y, and Z having the values from the override and all other permissions Not set.

This lets us use the original rule, substituting synthetic roles (like R') for overrides. We don't need a more complicated rule.

But is it correct?

In reply to John Isner

Re: logged in: what role am I?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
No, I know enough to say that you are incorrect.


The only complete and correct description of all the rules is in accesslib.php, in particular in the function has_capability_in_accessdata. I accept that that is not at all readable.


I think that something even more useful than a textual description of the algorithm would be a set of worked examples the demonstrate first some normally situations, and then most of the interesting edge cases. That would probably take about 20 examples. Compiling the examples would be a great way of learning the algorithm.


But I am not going to bother, because although I could not explain the general algorithm to someone else, I do know enough to set up courses and activities in real situations, and to explain to people how to solve particular roles configuration problems.


So instead of trying to describe the general rules, and alternative approach is write a document that says "If you only do these few things, then it will work like this" and have it that the subset described is enough to do 99.99% of what teachers want.


In reply to Tim Hunt

Re: logged in: what role am I?

by John Isner -
Thanks for your reply Tim!

I agree that it would be difficult to describe the rules in text, and I agree that users should not have to read code.

I also agree that a good collection of examples (normal and edge cases) would help. For admins and teachers who are fiddling with roles without knowing what they're doing, the edge cases are especially important smile

Here's another possibility: A developer who understands the code writes a stripped-to-its-bare-essence pseudocode version of the algorithm and puts in in moodle docs. If the algorithm is coded as a recursive function, it will be really short and easy for anyone with a programming background to understand. Those people can use it as the basis for their own textual descriptions and examples.
In reply to John Isner

Re: logged in: what role am I?

by John Isner -
Entered MDLSITE-355 "has_capability_in_accessdata must be documented"
In reply to John Isner

Re: logged in: what role am I?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The person you need to do this is Martin Langhoff. He rewrote the whole of accesslib for Moodle 1.9 massively improve performance. As a result, he is probably the person who understands roles best.
In reply to Tim Hunt

Re: logged in: what role am I?

by tony chesney -
thanks that's very useful.
re the bit about overrides: I can see how to override at Course context using the Administration block, but I can't see how to override for a particular instance of an Activity, eg a particular forum, because there is no Administration available at individual Activity context. Maybe in your example Tim the best override available would be ALL forums in that course?
In reply to tony chesney

Re: logged in: what role am I?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
If you want an override of, say mod/forum:reply in every forum in a course, then do the override at course level.

To assign or override roles in a forum (or other activity), click on the edit icon for the forum, then switch to the roles tab.