- The system knows about kinds of Roles by a list of role types.
- The system knows about kinds of org units by a list of org unit types.
- Every org unit has an org unit record, keyed by ID, and part of the org unit record is its org unit type (i.e. whether 'course offering', 'department', etc)
- Every user has a user record keyed by ID, part of that user record coming out of the act of user creation, is a "default enrollment"... the enrollment of the user in the org unit context in which they're created -- this is almost certainly going to be the "organization" or the special root org unit node that has the org unit type "organization".
- Every time a user has an enrollment in an org unit, that enrollment represents a binding between the user record, the org unit record, and a role type -- absent of enrollments in org units, users don't really have roles (except for the "special" role they get from their special enrollment-upon-creation).
- Permissions to do things are divided into sets of permissions for 'Tools' -- in the LMS' Admin UI, when you edit permissions, you can look at the entire table, or just the permissions associated with a particular 'Tool'... rarely do permissions from more than one tool bear on what a user is allowed to do, but it does happen (for example, the "User Information Privacy" permissions apply to activity where potentially private user information can be revealed, not just within some "UIP Tool").
- Permissions to do things are also divided into org unit types and role types -- that is, a particular permission applies to any user enrolled with Role X in Org Unit Type Y -- or any user that's enrolled as a "Student" in a "Course Offering" for example.
- Because the tools available on a back-end service are definable client-to-client, and the org unit types and role types are definable client-to-client, the manifestation of what a particular client's permissions sets look like get really varied and really complex, really fast.
- The data about what role types are available, what org unit types are available, and particularly what role a user enrollment binds to, are often judged to be sensitive information by clients, and the ability to see that stuff is ALSO governed by permissions -- this means that your calling user context may not have any ability to, programmatically, "know or determine" what particular things it can and cannot do, other than just to try to do things and cope with potential failure. Administer type users can often see enrollment details that show role, and so can make some judgements, but, really, all they'll know is role type and then they have to "know" what that role type can actually do. (We're only just starting to programmatically expose views on the permissions sets out through the API, and it might not yet really have all the support there you'd need for effective permission investigation and processing at run-time: <
http://docs.valence.desire2learn.com/res/permissions.html>.)
In your particular case, you probably need to know exactly what role your calling user context has in the context of the org unit you're trying to operate on. It's possible that your user context may need to be explicitly enrolled in the org unit (course), and not just enrolled via cascading enrollment. But, in any case, your user context needs to have permissions that allow the user's enrolled role to do the right stuff within org units of the appropriate type.
In nearly all cases, the permissions governing API functions and "through the web UI" equivalents are exactly the same; unfortunately, for one reason or another, in some small number of cases, they are not. Thus, while in most cases, it does hold true that "if you can do it in the Web UI, you can do it through the API if you make the API call as the same user", in a few cases, it may not, and the Grades functionality may well be one of those exceptions.
To do the kind of interactive role-permission testing outlined in the walkthrough really requires you to have direct access to a back-end LMS service, preferably a test one, so that you can use it with the org unit and role types expected by the production platform (or at least provide information that a production platform can map to), and go through the sticky parts in your client integration to find out exactly what role permissions are required of user contexts using your client application.
This is potentially quite laborious and frustrating, admittedly. However, on the whole, the general statement holds true -- types of users that can generally do things through the web UI can also do those things through the API, and designing with this principle in mind, and designing to cope gracefully with API call failure, are the right way to go.
I hope this helps. I admit that it's all fairly complex.
--
V.