459 Commits

Author SHA1 Message Date
tjhunt
cc3d5e10ec Put back DEBUG_DEVELOPER sanity check in has_capability, that makes sure the capabiltiy you are asking about actually exists. I know it takes an extra DB query, but it is DEBUG_DEVELOPER only, and it is worth its weight in gold, because otherwise you get really subtle bugs that take forever to diagnose. I know, I have just been banging my head against the wall for an hour. 2008-01-08 15:04:00 +00:00
martinlanghoff
19f2318a44 accesslib: get_users_by_capability() now excludes doanything'ers properly
With some subselect-outer-join poison-pill magic, when the we don't
want doanything users, we remove the roles that would grant such
dubious status.

Just a flick of the SQL muscle, actually.
2008-01-06 23:26:19 +00:00
martinlanghoff
92c879cef1 accesslib: get_users_by_capability() fix subselect with ra.hidden
MDL-12452
2008-01-06 23:26:08 +00:00
martinlanghoff
635bfbad21 accesslib: Introducing sort_by_roleassignment_authority()
This will help us bridge the gap from olden-style order-by
user_teachers.id. From the phpdoc...

 Will re-sort a $users results array (from get_users_by_capability(), usually)
 based on a sorting policy. This is to support the odd practice of
 sorting teachers by 'authority', where authority was "lowest id of the role
 assignment".

 Will execute 1 database query. Only suitable for small numbers of users, as it
 uses an u.id IN() clause.

 Notes about the sorting criteria.

 As a default, we cannot rely on role.sortorder because then
 admins/coursecreators will always win. That is why the sane
 rule "is locality matters most", with sortorder as 2nd
 consideration.

 If you want role.sortorder, use the 'sortorder' policy, and
 name explicitly what roles you want to cover. It's probably
 a good idea to see what roles have the capabilities you want
 (array_diff() them against roiles that have 'can-do-anything'
 to weed out admin-ish roles. Or fetch a list of roles from
 variables like $CFG->coursemanagers .

MDL-12452
2008-01-06 23:25:37 +00:00
martinlanghoff
f17a660a05 accesslib: get_user_by_capability() - Fix pagination
Ooops! Off-by-one error

MDL-12452
2008-01-06 23:25:03 +00:00
martinlanghoff
c92bce4614 accesslib: get_user_by_capability() - Fix last_access handling
We were missing $courseid, which is actually $context->instanceid.

MDL-12452
2008-01-06 23:24:37 +00:00
martinlanghoff
6c9d86b7a6 accesslib: get_user_by_capability() - Move capcheck to has_capability_from_rarc()
This fixes the handling of default roles as "tie breakers" for lower
RAs in conflict, and simplifies the code a lot.

The main loop in get_user_by_capability() runs a simpler state machine
that just collects role assignments (roleid and depth), and handles
pagination.

The complex part of the state machine has moved to
has_capability_from_rarc() which will walk the data structures
collected by get_user_by_capability() for each user.

Having all the complex state handling of $hascap there makes things a
lot easier for pagination and general sanity of
get_user_by_capability().

MDL-12452
2008-01-06 23:24:25 +00:00
martinlanghoff
d2c5b7a9fa accesslib: get_user_by_capability() - Move hidden RA checks to subselect
we don't deal with RAs in the main SELECT -- we deal with _capabilities_
which is an entirely different matter ;-) -- so push the ra.hidden check
into the subselect.

Also, remove ra.hidden from the default list of fields. Hopefully no
callers are using ra.hidden -- if they are, they should be calling
something else, as this function deals with capabilities. So we might
need an audit of callers, to check that noone is expecting ra.hidden
to be there.

MDL-12452
2008-01-06 23:24:14 +00:00
martinlanghoff
a4436c6db8 accesslib: get_user_by_capability() - Handle the complex case
With this commit, we can handle the complex cases with

 - correct pagination, but not very efficient over large datasets

 - mostly-correct application of the override rules

The structure of the code is fairly complex in that we want to do
it without holding all the recs in memory, so we use a small state
machine. We have to handle the complex override rules over 1 or 2
permissions (when $doanything is set) so it all ends up quite complex.

There is one known issue with this code, in cases where the default
role ends up as the decider between 2 conflicting RAs, we fail to
apply it. This will need a bit of reorg of how the loop works.

MDL-12452
2008-01-06 23:23:58 +00:00
martinlanghoff
2d1669b0d5 accesslib: get_user_by_capability() - Simple cases now handle multiple RAs
The "simple" case SQL did not handle multiple enrolments for the same
user correctly -- it would generate multiple rows for those users,
incorrectly.

With this patch we move the join to RA to a subselect where DISTINCT
takes care of things.

MDL-12452
2008-01-06 23:23:46 +00:00
martinlanghoff
8b8bf40cc7 accesslib: get_user_by_capability() - Handle complex rolecap resolution
With this patch, get_user_by_capability() can handle the cases where
users have multiple role assignments to the same course, and PREVENTs
and PROHIBITs affect the rolecaps of this course.

Without stored procedures we cannot resolve this entirely on the
server side - so in the complex cases we do as much as we can on SQL,
and post-process the data on the PHP side, including SQL-style
pagination.

MDL-12452
2008-01-06 23:23:24 +00:00
martinlanghoff
26843e106b accesslib: get_user_by_capability() - First, handle simple cases
This patch reorganises the conditions and field handling so
we can spot if this is a call we can resolve in a single SQL
query that we just pass back the results.

If there are any PREVENTs or PROHIBITs, we need to delve into
more involved stuff...

MDL-12452
2008-01-06 23:22:26 +00:00
martinlanghoff
987e745442 accesslib: revert changes to get_users_by_capability() - MDL-12452 MDL-12451
The changes made by Yu and Tim are superceded by the patches that
follow -- and would not apply cleanly without this revert.
2008-01-06 23:22:08 +00:00
skodak
47af2e43f3 MDL-12720 removing confusing/not implemented CONTEXT_PERSONAL; merged from MOODLE_19_STABLE 2007-12-23 19:48:32 +00:00
mjollnir_
7bb03e8a7b merged from MOODLE_19_STABLE: fixing lying phpdoc comments in role_cap_duplicate function that I moved to accesslib yesterday 2007-12-19 23:32:53 +00:00
mjollnir_
d4564cf018 merged from MOODLE_19_STABLE: moving two functions from admin/roles/manage.php (switch_roles and role_cap_duplicate) to accesslib & added phpdoc. Fixes MDL-12621 2007-12-18 20:51:07 +00:00
skodak
d9854bee3f MDL-12602 redirect to course if require_capability() fails for module context; merged from MOODLE_19_STABLE 2007-12-16 13:53:04 +00:00
toyomoyo
6967ba2846 MDL-12544, hide hidden roles in profile when user has no capability 2007-12-12 07:13:09 +00:00
tjhunt
b04ad8649b Take out debugging output in role_assign. It only tells you that something has worked, and everywhere else we use debugging output to warn people they have called an API wrongly. Therefore, this is just confusing now that we trust this bit of roles code. 2007-12-11 10:37:53 +00:00
martinlanghoff
70dd126e0b MDL-12523 accesslib:cleanup_contexts() - Fix invalid SQL syntax and reserved keywords
cleanup_contexts() was not working on Oracle - mostly due to 2 SQL
syntax problems. So probably marginally working elsewhere.

 - We should not use AS when naming table/subselect aliases - only
   when referring to column aliases in the resultset

 - level is a reserved word - oops! - so back to contextlevel
2007-12-10 21:35:58 +00:00
toyomoyo
176058849a MDL-12451, in get_users_by_capability(), defaultroleid bit fixes 2007-12-06 03:57:05 +00:00
tjhunt
36c6f4f59e MDL-12452 - not a fix I fear, just clarifying the comments about how this method is broken. 2007-12-05 17:25:25 +00:00
toyomoyo
086df9283f MDL-12437, sorting by names adds teacher to gradebook list 2007-12-05 01:13:29 +00:00
martinlanghoff
2ff0fb1205 accesslib: build_context_path() remove $temptable for Oracle too
The removal of $temptable was incomplete - and so build_context_path()
was broken on Oracle. MDL-11347
2007-12-04 06:25:25 +00:00
toyomoyo
b1ee7d3a02 MDL-12366, removing useless print_capabilities function 2007-11-28 01:20:59 +00:00
toyomoyo
d2b8b98732 MDL-12309, gradebook can not sort by names while in group mode 2007-11-22 05:17:26 +00:00
martinlanghoff
4f957b116d accesslib: has_capability_in_accessdata() respects rdef locality a bit more
With this patch, we respect rdef locality when two roles
assignments in the same context have conflicting rdefs.
In that case, the most local rdef wins.

So RA locality still matters most. If you are a teacher
sitewide and a student in course X, student role trumps
teacher.

For a use case, see the discussion here
http://moodle.org/mod/forum/discuss.php?d=84472

Notes:

- If we wanted to have locality of RDEF trump everything
  we can. A comment in this patch shows how.

- I don't know how to reproduce this in pure SQL.

And Also:

This patch also fixes a bug where if CAP_PROHIBIT was set
_and_ another role added to it in the same context, we would
add or substract 1 to CAP_PROHIBIT, and it would lose its magic.

And while at it, tighten the code to avoid casts. All the
ints are unambiguously ints.
2007-11-20 00:18:31 +00:00
scyrma
7be3be1bf0 Fix to a bug preventing rss feeds from displaying. 2007-11-16 03:34:05 +00:00
toyomoyo
ba1393b43f MDL-12180, blocks capabilities not appearing when overriding block roles 2007-11-15 07:46:04 +00:00
martinlanghoff
8f9e1d2c4d accesslib: Move check_enrolment_plugins() to complete_user_login()
... where it belongs ;-)

load_all_capabiloties() gets called at several points where we don't
want to be re-querying the enrolment backends. It needs to  be called
before load_all_capabilities() and only by callers that are setting up
a logon session.

Those callers need to be calling complete_user_login() anyway, as they
need to set the Moodle cookie, log the logon action, etc. In fact,
those callers duplicate a lot of that code already.

The callers that don't duplicate code for the login are actually the
cases where the backend enrolment plugins should not be queried.

To be followed by callers cleanup...
2007-11-14 22:04:05 +00:00
nfreear
0dbb2191fb Fixes MDL-12125, Call to a member function FetchRow on a non-object in get_user_access_sitewide. 2007-11-12 16:53:53 +00:00
skodak
5966487712 MDL-11951 a little typo - no recursive call intended in has_any_capability() I guess 2007-10-30 20:51:37 +00:00
tjhunt
3fc3ebf26b MDL-11951 - supplemental - need capability checks in the outer if of the file too. Merged from MOODLE_19_STABLE. 2007-10-30 10:50:20 +00:00
toyomoyo
602654f358 merged fix for MDL-11532, updatesql needs to run after every 'round' otherwises nothing to pull from the context table 2007-10-26 07:58:23 +00:00
stronk7
b738808bb3 Commenting some more debug...
Merged from MOODLE_19_STABLE
2007-10-18 16:04:54 +00:00
stronk7
6100dad06e Commenting out some excess of debug info.
Merged from MOODLE_19_STABLE
2007-10-18 15:57:15 +00:00
toyomoyo
cb8cb8bf88 MDL-11241, adding logs for roles management 2007-10-18 05:53:14 +00:00
skodak
a2cf7f1b8a MDL-11658 shared rdef definition - reduced memory usage in cron 2007-10-17 09:19:39 +00:00
gustav_delius
84dfbdd2f6 Fixed error in the SQL in get_users_by_capability() that made many things not work properly on the course front page. 2007-10-16 08:42:23 +00:00
toyomoyo
13c7c8183e adding missing context 2007-10-12 07:41:30 +00:00
skodak
03cedd6283 MDL-11432 eliminated majority of RecordCount uses, added several missing rs_close() - this should help improve perf on some platforms - Eloy says ;-) 2007-10-10 12:19:27 +00:00
skodak
3f7d592598 add proper rs_close() into cleanup_contexts() - we have to close even when now records returned 2007-10-10 08:43:25 +00:00
skodak
8a4d32d8a3 MDL-11688 makes sure all course and user contexts exist during upgrade (all contexts when going from in 1.6) - this is needed for grade_letter upgrade; other minor tweaks - the USER->access is now loaded automatically, feedback parameters added 2007-10-10 08:33:06 +00:00
nicolasconnault
b7064779f5 Updated copyright notice in header 2007-10-10 05:25:14 +00:00
skodak
b51ece5b3b MDL-11660
* user_lastaccess deleted when deleting course
* rewritten deleting of contexts - does not use get_context_instance() anymore because it is much more strict now
* added deleting of grade_letters and settings when deleting course
2007-10-09 16:07:15 +00:00
skodak
128f098418 MDL-11640
* improved handling of dirty contexts in general - caching, switching in cron, marking, loading, etc.
* role_assing() and role_unassign() now marks dirty contexts because we use has_capability() in this function - we can not do it later outside to speedup bulk operations
* fixed some inline docs
* fixed notice from rs closing
* removed cached $CONTEXT from has_capability() - $context is now required parameter; this was hiding serious bugs when context did not exist or ppl passed false as parameter
* removed some ===, we can not use these on function parameters - we must support ints, strings, '', nulls, etc. - this could be a source of really dangerous bugs in future
* some other improvements and fixes - documented inline
2007-10-09 12:49:54 +00:00
skodak
5c8e6cb179 MDL-11621 removed recursion from create_contexts() 2007-10-05 20:47:08 +00:00
skodak
9a81a6060a MDL-11621 new create_contexts() function that makes sure all contexts exist, optionally initialises the paths and depths too 2007-10-05 20:16:51 +00:00
skodak
7d0c81b3ba MDL-11521 fixed problems when creating contexts and aprents does not exist yet
MDL-11527 fixed warning from $CFG->defaultuserroleid when installing and upgrading
+ removed reusing of previous contexts in has_capability() and get_context_instance()  because it was hiding critical errors when context was false, not specified, etc.
+ tweaked roles defaults - faster and defaults are applied when roles exist
+ SYSCONTEXTID may be specified in config.php to eliminate 1 db query
+ static context cache is now reset after rebuilding of context paths
+ path field in context table is now nullable - pg compatibility requirement
+ other minor fixes
2007-10-05 15:06:38 +00:00
skodak
3d811bc167 MDL-11143 fixed defaultfrongpageroleid typo and fixed notices during install and upgrade cause by undefined $CFG->defaultfrontpageroleid 2007-10-03 14:38:55 +00:00