Commit graph

28474 commits

Author SHA1 Message Date
martinlanghoff
6cc59cb21b accesslib: add support for multi-enrolments
I had dropped support for multi-enrolments on the same context.

 Oops!

This patch reinstates it, changing the semantics of the 'ra'
array leaves from an int to an array of ints.

So no instead of

   $USER->access['ra']['/1/12/543'] = 5

we have

   $USER->access['ra']['/1/12/543'] = array(5)

the functions that build the array, and the array walkers have
been updated. This touches...

  Writing RAs
    load_all_capabilities()
    get_user_access_sitewide()
    get_user_access_bycontext()

  Reading RAs
    has_cap_fromsess()
    aggr_roles_fromsess()

Thanks to Matt Clarkson for mentioning multi-enrolments!
2007-09-19 07:06:30 +00:00
martinlanghoff
b1178725a8 weblib: switchroles_form() user_login_string() handle the new switchroles
The switched role data bits have moved to a
different place in the session. Trivial to fix here.
2007-09-19 07:06:17 +00:00
martinlanghoff
1c886b238d accesslib: role_switch() supports unswitching by passing $roleid=0
It is a good idea, silly of me to remove it...
2007-09-19 07:06:03 +00:00
martinlanghoff
6a8d9a387d accesslib: has_cap_from_sess() now supports role switching
With this commit we now have very fast support for
roleswitching, based on $sess[rsw] entries.

And a bit of phpdoc. This is function, and the
datastructure it walks, is the heart of of it.
2007-09-19 07:05:48 +00:00
martinlanghoff
6f1bce30b1 accesslib - role_switch() revamp, introduce get_role_access_bycontext()
First stage of role_switch() rewrite - role_switch() sets up
a rsw entry in $USER->access, and makes sure we have the
appropriate role definitions in rdef.

That is where get_role_access_bycontext() comes into play -
gets all the rdef entries in one cheap sql query.

... though there may be many of them...

TODO:

 - fix callers of role_switch()
 - teach has_cap_fromsess() to read the rsw entries
2007-09-19 07:05:32 +00:00
martinlanghoff
b5a645b4eb accesslib: Draft get_context_users_byrole()
Draft - use for the course participants list page

 Uses 1 DB query (cheap too - 2~7ms).

 TODO:
 - implement additional where clauses
 - sorting
 - get course participants list to use it!

 returns a users array, both sorted _and_ keyed
 on id (as get_my_courses() does)

 as a bonus, every user record comes with its own
 personal context, as our callers need it straight away
 {save 1 dbquery per user! yay!}
2007-09-19 07:05:21 +00:00
martinlanghoff
352f6f74fc get_my_courses() and get_user_courses_bycap() field handling and caching
- Field handling moves back to get_my_courses() and now we have
  almost all the fields that the old get_my_courses() did
  (except for summary, which is *huge*) so get_my_courses() asks
  for a lot of fields, but the get_user_courses_bycap() defaults
  are _much_ leaner now.

  I think this makes sense ;-)

- get_my_courses() now caches the course ids for the currently logged in
  user in $USER->mycourses -- as a _string_. This is magnitudes more efficient
  than having it as an array.

The cache makes a difference, but it's not very visible on
normal pageloads (with my courses block, for example).

However, over 100 iterations, for a user with 50 enrolments in a site
with 6K courses, we go from 4.3s to 0.6s. And the DB queries are *cheap*.

            $tt = microtime(true);
            for($n=0;$n<100;$n++) {
                get_my_courses($USER->id, 'sortorder ASC');
            }
            error_log("took " .  (microtime(true) - $tt));
2007-09-19 07:04:59 +00:00
martinlanghoff
2e059c7709 accesslib: get_user_courses_bycap() - make $doanything work in the optimised path
OMG! Bugfix!
2007-09-19 07:04:37 +00:00
martinlanghoff
573674bf47 accesslib: get_user_courses_bycap() is less of a piggy now...
get_user_courses_bycap() replaces get_courses_bycap_fromsess().

Using a combination of in-DB enrolments and in-session capability
checks, we narrow down the courses we fetch from the DB for checking.

This patch adds a small DB query, and has has a moderate impact on
the timings observable on my laptop (~300ms?), but reduces
*significantly* the bandwidth used, which in cluster environments
with frontends separate from backends has a serious impact.
2007-09-19 07:04:23 +00:00
martinlanghoff
aeb3916b7a datalib: get_my_courses() - some fixes to the data we return
strangely, get_my_courses() is expected to return the
array keyed on id, which messes up the sorting

So let's do it ;-)
2007-09-19 07:04:10 +00:00
martinlanghoff
e1d5e5c181 accesslib: get_my_courses() rework, new get_courses_bycap_fromsess()
get_my_courses() goes from a bazillion queries (500 in some sample
cases) to 1 for the logged-in user, and 4 for a non-logged-in user.

One of those queries brings a *lot* of data across (all rows from
mdl_course) so there is room for serious optimisation.

  However, this clocks at ~300 ms on my laptop, costly, but not
  the end of the world. If your PHP-DB link has bandwidth probs
  it might be a problem.

A few important changes to get_my_courses()

 - (Compat ALERT!) the default fields are less than before --
   (will be followed by patches that fix the callers!) our defaults
   had grown to quite a bit because of the crazy caching scheme it had

 - the $fields parameter is to name _additional_ fields you need, and
   ideally wants them passed as an array. Will cope with old-style
   strings too.

 - the returned courses have an extra property "context" that is
   a fully valid context object, so if the caller needs to perform
   further accesslib checks, we save a query per course down the road

The work is done in the newfangled get_courses_bycap_fromsess()
which is brute-force but fast. I'm sure we can optimise the common
cases a lot in it if we try. It'd be worthwhile to

  - reduce the rows we grab - that's really boneheaded

  - if we copy and tweak the logic of has_cap_fromsess() in it
    it can be made even faster
2007-09-19 07:03:49 +00:00
martinlanghoff
13a794757e accesslib: has_capability() - useful debugging bit... 2007-09-19 07:03:34 +00:00
martinlanghoff
018d4b52b7 accesslib: get_user_access_bycontext() fetches overrides in subcontexts, intro aggr_roles_fromsess()
The main thing here is that overrides in subcontexts are
now read correctly (and still cheaply) into the access array.

Also

 - introducing aggr_roles_fromsess() with gives you a list of
   the relevant roles that affect the user in this context

 - we clear out $USER->access on login/logout

 - get_user_access_bycontext() gets a few optimisations too...
2007-09-19 07:03:19 +00:00
martinlanghoff
e0376a6241 accesslib: default, guest and notloggedin roles work properly now
Changes around load_user_capability() and has_capability() to make
the default role fallbacks and guest/nonloggedin roles work.

This commit also introduces the concept of having a magic
context next to the root context in $USER->access[ra], as

 $USER->access[ra][/1] = 1 (admin roleid)
 $USER->access[ra][/1:def] = 7 (loggedinuser roleid)

and has_cap_fromsess() now checks for that magic context
as well.
2007-09-19 07:02:57 +00:00
martinlanghoff
74ac5b66cb accesslib: has_capability() now works for the logged in user
With this commit, the new has_capability works for the logged
in user correctly.

 - load_all_capabilities() no longer calls load_user_capability()!
   6K dbqueries less on login... ;-)

 - When delving into a context we haven't loaded yet, we call
   get_user_access_bycontext()

 - Introduce: get_user_access_bycontext()

 - Several fixes in get_user_access_sitewide()
   (renamed from get_user_sitewide_access())

 - Fixes in has_cap_fromsess()

 - Introduce access_insess() to check if we have to call
   get_user_access_bycontext() for the context
2007-09-19 07:02:44 +00:00
martinlanghoff
7f97ea29bf accesslib: initial has_capability() rewrite
- has_capability() renamed has_capability_old() and we fallback
   when we cannot answer the question

 - has_capability() works great for the course-and-above contexts
   for the logged in user - does not touch the DB

 - works based on $USER->access which has a pretty compact view
   of the user's access rights...

TODO:

 - deal with contexts below the course - here we need to
   trigger the role-assignment and role-defs load when needed

 - deal with "other" contexts that hang from the system context

 - deal with global roleswitch, local roleswitch
2007-09-19 07:02:31 +00:00
martinlanghoff
6dd34e935d lib/setup: declare SYSCONTEXTID to have the system context handy 2007-09-19 07:02:18 +00:00
martinlanghoff
a9bee37ea1 accesslib: Introducing get_user_sitewide_access($userid)
This function carefully fetches all the data needed to
handle site/category/course access for a given user
as cheaply as possible.

It currently takes 3 db queries.
2007-09-19 07:02:04 +00:00
martinlanghoff
41883f79ca datalib: Introducing sql_intarray_to_in()
Trivial function to turn an array of ints into a string
usable in an IN sql clause.
2007-09-19 07:01:53 +00:00
martinlanghoff
a1244706be user_set_preference(): minor optimisation
Don't update if the values already match...
2007-09-19 07:01:41 +00:00
martinlanghoff
1f3c9d097f accesslib: Introducing build_context_path()
which populates the context.path and context.depth fields
2007-09-19 07:01:27 +00:00
martinlanghoff
a9fcd13a77 datalib:add_to_log() - avoid schema lookups, pace updates to user and user_lastaccess
* All updates to user.lastaccess and user_lastaccess.timeaccess are paced to
60s of the last update on the same record -- this should reduce the heat
on those tables.

* Updates/inserts to user_lastaccess are down with raw SQL to avoid costly
schema lookups on every request.
2007-09-19 07:01:04 +00:00
martinlanghoff
e1e1f49820 pagelib: Course page - preload child contexts and smarter user_allowed_editing()
With this patch we preload the child contexts for the course
and hold on to them. This means that in one DB query we have all the contexts
we are going to need.

The checks for user_allowed_editing() move from weblib:update_icon() to
user_allowed_editing(), where we cache the result, and in the process save
50% of the cap checks by testing separately blocks from modules (doh!).

Still, the cap checks here are very inefficient...

With the last 3 patches, a course page with default blocks and 9 modinstances
goes from 157 to 86 db queries when logged in as a non-editing user (guest,
student). As admin it drops from 88 to 81.

Conflicts:

	lib/pagelib.php
2007-09-19 06:53:09 +00:00
martinlanghoff
0532aec946 weblib:update_course_icon() - remove access control from here
Access control for the course icon display should happen
at the page level, as we'll need to ask "can edit?" quite
a few times in the page.

The fact that this is weblib should be a good hint that
functions that print html should not be doing access control...
2007-09-19 06:52:52 +00:00
martinlanghoff
19bb8a0517 accesslib:get_child_contexts() reworked to use context.path
Using context.path, now get_child_contexts...

 - always takes 1 query
 - populated the context_cache
 - returns full records
 - when called with an category, it won't
   recurse into the children of courses

Also

 - All callers in accesslib changed to the new
   calling convention

A normal course page with a std blocks and a few
activities sees around 100 queries less with this patch.

Note: this commit is slightly different on HEAD/19 and on
MOODLE_18_STABLE, as groups-related tables have changed.
2007-09-19 06:52:34 +00:00
martinlanghoff
17b0efae11 accesslib: Introducing cleanup_contexts() and use it in cron
The newly minted cleanup_contexts() walks the context table
matching contexts with the tables they are referencing and
clearing any leftover contexts.
2007-09-19 06:50:53 +00:00
toyomoyo
40e0bea5cc minor fix for count of users 2007-09-19 03:48:44 +00:00
toyomoyo
60410add64 MDL-11324, only display users with moodle:course/view capability when assinging in module context or lower 2007-09-19 03:31:22 +00:00
stronk7
cb4bfe06b1 Now assignment_submissions->data1 & data2 are nullable. MDL-11268 2007-09-18 22:20:13 +00:00
stronk7
51ac73da3e Minor improvements to messages window for wood. 2007-09-18 18:57:59 +00:00
skodak
06ea7db0c3 MDL-1883 info for 3rd party developers in DEBUG_DEVELOPER mode 2007-09-18 18:50:14 +00:00
skodak
85c9ebb926 MDL-1883 improved perf when editing scales - new function xxx_scale_used_anywhere() 2007-09-18 18:37:58 +00:00
stronk7
423c029090 Fix some HTML in messages (wrong <a> and roundcorners support) 2007-09-18 18:24:52 +00:00
urs_hunkler
5228aa27cc enhancements for messages: remove header and footer with CSS. increase user top frame height via JavaScript to view the whole user image. 2007-09-18 17:10:32 +00:00
nicolasconnault
e480c18cf1 MDL-11312 Added new grade_letters table, and new grade_items.display field. 2007-09-18 14:26:15 +00:00
thepurpleblob
ad2cd664d7 Typo!
Merged from STABLE_18
2007-09-18 12:30:19 +00:00
tjhunt
c767d3b7d3 MDL-11317 - Slashes displayed in incorrect responses for short answer questions. Fix by adding stripslashes in the appropriate place. Merged from MOODLE_18_STABLE. 2007-09-18 12:15:22 +00:00
jamiesensei
8f0f605ddf moved question_make_default_categories function to questionlib.php since it is needed by other modules outside the question bank editing interface. 2007-09-18 11:23:29 +00:00
jamiesensei
41b6d0011c MDL-11318 formslib now respects a template for an element if it is set. But since formslib uses the templates to insert help buttons for setAdvanced functionality etc. if you use templates you will lose this functionality. 2007-09-18 09:35:44 +00:00
moodler
d13d30ef78 The "alias" role names were not being used in the role assign screens. Now they are. MDL-11323 2007-09-18 08:35:12 +00:00
toyomoyo
79c2d039d5 added a string for backup/restore 2007-09-18 07:14:37 +00:00
toyomoyo
461af59ac1 MDL-11234, if role definitions matches, restore role mapping should be allowed with or without role assign capabilities 2007-09-18 07:00:57 +00:00
moodler
9a9be7cbaf Automatic installer.php lang files by installer_builder (20070918) 2007-09-18 04:21:57 +00:00
toyomoyo
e5d30fdcc9 added needsupdate flag into backup/restore, added a new switch for restore on/off for grade histories, fixed some NULL related warnings 2007-09-18 04:03:02 +00:00
moodler
ae0441ac75 iAdded a string for preview rows in exports 2007-09-18 03:38:33 +00:00
moodler
567883c836 Cleaned up the display of the export pages 2007-09-18 03:36:47 +00:00
moodler
8a34e1d7ca Some layout for the grades export download link / buttons 2007-09-18 03:24:28 +00:00
stronk7
bc2019dd79 Adding Id to file 2007-09-17 22:10:22 +00:00
stronk7
e3f042fbd6 Added data_decode_content_links_caller() and data_decode_content_links()
to provide interlinking capabilities to restore. MDL-9576
2007-09-17 21:58:55 +00:00
iarenaza
bb4e530b93 MDL-11299 - Make objectClass string comparison case insensitive.
LDAP serves accept attribute names in a case insensitive way, so don't
force the users to use any particular spelling.
2007-09-17 21:30:20 +00:00