NOTICE: Roles now in HEAD

NOTICE: Roles now in HEAD

by Martin Dougiamas -
Number of replies: 22
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I've just checked the preliminary version of the Roles implementation into HEAD so that we can work on it faster (our branch MOODLE_17_ROLES was diverging too much from HEAD).

It's not finished yet, and there's a lot of known bugs and rough edges at this stage, so as a result the dev version ( = HEAD) can be considered very unstable.

So be warned! big grin

It should be improving rapidly from now on, though. Over the next few weeks we'll be looking for a lot of testing, bug reports and collaboration with module maintainers to push out Roles support to all parts of Moodle.
Average of ratings: -
In reply to Martin Dougiamas

Re: NOTICE: Roles now in HEAD

by W Page -

Nice to hear about it Martin!!

WP1

Attachment happy_about_roles.gif
In reply to W Page

Re: NOTICE: Roles now in HEAD

by Julian Ridden -
Gee i hope thats a leg there  blush

/me appologises in advance for a comment that is sure to have offended someone tongueout
In reply to Martin Dougiamas

Re: NOTICE: Roles now in HEAD

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
This is great news! Did I hear drum roles? Probably not, that may have just been the sound of all those eyes rolling. 
In reply to Anthony Borrow

Re: NOTICE: Roles now in HEAD

by Don Hinkelman -
Picture of Particularly helpful Moodlers Picture of Plugin developers
> Did I hear drum roles?

Yes, you did.  This is so revolutionary, it deserves to be called Moodle 2.0.  Talk about designable, configurable, student-centred education!  And deconstruction of all our preconceived notions of teacher/student patterns of interaction and responsibility.  My mind is ablaze.

Now on to bug-testing.  Sorry to say, I already have three.
  1. role sequencing:  breakfast roles should come *before* dinner roles
  2. heavy bandwidth:  could you use less oil and sugar in the recipe?
  3. differentiation of roles:  how do I distinguish between loaves, roles and general pastries?
[the last point may be critical for patent litigation] wink
In reply to Don Hinkelman

Re: NOTICE: Roles now in HEAD

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Don, I would hate to see what happens when you get on a role. Although, I think my students would say that I have been pun pwnd! 
In reply to Anthony Borrow

Re: NOTICE: Roles now in HEAD

by Greg Lyon -
uh...ROFL?  (roleing on the floor laughing?)

or

Role Role Role your code
Gently to the HEAD
Moodle-ey moodle-ey moodle-ey moodle-ey
Soon the bugs are dead

ouch.  can't believe I'm about to post this...
In reply to Greg Lyon

Re: NOTICE: Roles now in HEAD

by Julian Ridden -
Greg..i think you REALLy need a break fro moodle for a while wink
In reply to Julian Ridden

Re: NOTICE: Roles now in HEAD

by Greg Lyon -
No kidding Julian! I probably should have mentioned that I posted during a bout of insomnia last night sleepy (I also reinstalled 1.7 and chased some bugs too...)
In reply to Martin Dougiamas

Re: NOTICE: Roles now in HEAD

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Very cool.

Unless you happen to be a Postgres user angry

Do you want me to commit fixes to lib/db/postgres.php?
In reply to Tim Hunt

Re: NOTICE: Roles now in HEAD

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I think the necessary patch is below.


After this, the upgrade works for me on Postgres, except that there is a bug in table_column under postgres. The bit where it tries to do
execute_sql('ALTER TABLE '. $CFG->prefix . $table .' RENAME COLUMN '. $field .' TO '. $realfield);
Claims that $realfield already exists, even though the previous line of code should have dropped that column. Hoever, the drop statement was not even being attempted. Unfortunately, Petr's update logging code seems to have a bug, and it stopped recording after the first error, so I don't have a record of exactly what happened.


P.S. Moodle coding guidelines specify spaces, not tabs, for indents, but this new code is full of tabs.

Index: mod/forum/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/forum/lib.php,v
retrieving revision 1.447
diff -u -r1.447 lib.php
--- mod/forum/lib.php	9 Aug 2006 09:18:31 -0000	1.447
+++ mod/forum/lib.php	9 Aug 2006 10:09:15 -0000
@@ -1712,7 +1712,7 @@
     }
     $output .= '<div class="subject">'.format_string($post->subject).'</div>';

-    $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $modcontext->id););
+    $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $modcontext->id));
     $by->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id.'">'.$fullname.'</a>';
     $by->date = userdate($post->modified, '', $touser->timezone);
     $output .= '<div class="author">'.get_string('bynameondate', 'forum', $by).'</div>';
Index: lib/db/postgres7.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/db/postgres7.php,v
retrieving revision 1.195
diff -u -r1.195 postgres7.php
--- lib/db/postgres7.php	8 Aug 2006 05:13:12 -0000	1.195
+++ lib/db/postgres7.php	9 Aug 2006 10:09:14 -0000
@@ -1635,26 +1635,26 @@

          modify_database('', "CREATE TABLE prefix_role_assignments (
                                   id SERIAL PRIMARY KEY,
-                                  roleid interger NOT NULL default 0,
-                                  contextid interger NOT NULL default 0,
-                                  userid interger NOT NULL default 0,
-                                  hidden interger NOT NULL default 0,
-                                  timestart interger NOT NULL default 0,
-                                  timeend interger NOT NULL default 0,
-                                  timemodified interger NOT NULL default 0,
-                                  modifierid interger NOT NULL default 0,
+                                  roleid integer NOT NULL default 0,
+                                  contextid integer NOT NULL default 0,
+                                  userid integer NOT NULL default 0,
+                                  hidden integer NOT NULL default 0,
+                                  timestart integer NOT NULL default 0,
+                                  timeend integer NOT NULL default 0,
+                                  timemodified integer NOT NULL default 0,
+                                  modifierid integer NOT NULL default 0,
                                   enrol varchar(20) NOT NULL default '',
   								  sortorder integer NOT NULL default '0'
                                 );");

         modify_database('', "CREATE TABLE prefix_role_capabilities (
                                   id SERIAL PRIMARY KEY,
-                                  contextid interger NOT NULL default 0,
-                                  roleid interger NOT NULL default 0,
+                                  contextid integer NOT NULL default 0,
+                                  roleid integer NOT NULL default 0,
                                   capability varchar(255) NOT NULL default '',
                                   permission integer NOT NULL default 0,
-                                  timemodified interger NOT NULL default 0,
-                                  modifierid interger NOT NULL default 0
+                                  timemodified integer NOT NULL default 0,
+                                  modifierid integer NOT NULL default 0
                                 );");

         modify_database('', "CREATE TABLE prefix_role_deny_grant (

In reply to Tim Hunt

Re: NOTICE: Roles now in HEAD

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
And some more Postgres problems. Logging in does not work until you apply the patch below to lib/accesslib.php. There is some problems with the SQL.

Postres can't cope with using the computed column 'sum' in the HAVING clause, so you need to spell it out again. (Is it a good idea to use a SQL reserved word like 'sum' as a column name?)

And it thinks calling the computed level 'level' is ambiguous, which it is becuase two of the tables being joined have columns called level.

Oh, and I was getting undefined variable warnings, hence the addition of the !empty(...) bits to some if statements.

After this, the quiz module (and creating a course and adding a quiz to it) seems to work for me on Postgres.

Index: accesslib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/accesslib.php,v
retrieving revision 1.4
diff -u -r1.4 accesslib.php
--- accesslib.php	9 Aug 2006 05:37:31 -0000	1.4
+++ accesslib.php	9 Aug 2006 11:06:07 -0000
@@ -354,7 +354,7 @@

 	$siteinstance = get_context_instance(CONTEXT_SYSTEM, SITEID);

-    $SQL = " SELECT  rc.capability, c1.id, (c1.level * 100) AS level,
+    $SQL = " SELECT  rc.capability, c1.id, (c1.level * 100) AS aggregatelevel,
                      SUM(rc.permission) AS sum
                      FROM
                      {$CFG->prefix}role_assignments AS ra
@@ -366,12 +366,12 @@
                      rc.contextid=$siteinstance->id
 					 $capsearch
               GROUP BY
-                     rc.capability,level,c1.id
+                     rc.capability,aggregatelevel,c1.id
                      HAVING
-                     sum != 0
+                     SUM(rc.permission) != 0
               UNION

-              SELECT rc.capability, c1.id, (c1.level * 100 + c2.level) AS level,
+              SELECT rc.capability, c1.id, (c1.level * 100 + c2.level) AS aggregatelevel,
                      SUM(rc.permission) AS sum
                      FROM
                      {$CFG->prefix}role_assignments AS ra
@@ -385,11 +385,11 @@
                      $capsearch

               GROUP BY
-                     rc.capability, level, c1.id
+                     rc.capability, aggregatelevel, c1.id
                      HAVING
-                     sum != 0
+                     SUM(rc.permission) != 0
               ORDER BY
-                     level ASC
+                     aggregatelevel ASC
             ";

 //	echo "$SQL"; // debug
@@ -411,31 +411,31 @@
     }

     /* so up to this point we should have somethign like this
-     * $capabilities[1]    ->level = 1000
+     * $capabilities[1]    ->aggregatelevel = 1000
                            ->module = SITEID
                            ->capability = do_anything
                            ->id = 1 (id is the context id)
                            ->sum = 0

-     * $capabilities[2]     ->level = 1000
+     * $capabilities[2]     ->aggregatelevel = 1000
                             ->module = SITEID
                             ->capability = post_messages
                             ->id = 1
                             ->sum = -9000

-     * $capabilittes[3]     ->level = 3000
+     * $capabilittes[3]     ->aggregatelevel = 3000
                             ->module = course
                             ->capability = view_course_activities
                             ->id = 25
                             ->sum = 1

-     * $capabilittes[4]     ->level = 3000
+     * $capabilittes[4]     ->aggregatelevel = 3000
                             ->module = course
                             ->capability = view_course_activities
                             ->id = 26
                             ->sum = 0 (this is another course)

-     * $capabilities[5]     ->level = 3050
+     * $capabilities[5]     ->aggregatelevel = 3050
                             ->module = course
                             ->capability = view_course_activities
                             ->id = 25 (override in course 25)
@@ -459,7 +459,7 @@
 	$usercap = array(); // for other user's capabilities
     foreach ($capabilities as $capability) {

-		if ($otheruserid) { // we are pulling out other user's capabilities, do not write to session
+		if (!empty($otheruserid)) { // we are pulling out other user's capabilities, do not write to session
 		
 			if (capability_prohibits($capability->capability, $capability->id, $capability->sum, $usercap)) {
 	            $usercap[$capability->id][$capability->capability] = -9000;
@@ -489,7 +489,7 @@
     // now we don't care about the huge array anymore, we can dispose it.
     unset($capabilities);

-    if ($otheruseid) {
+    if (!empty($otheruseid)) {
     	return $usercap; // return the array
     }
     // see array in session to see what it looks like
@@ -550,7 +550,7 @@
         case CONTEXT_COURSECAT:
             // Coursecat -> coursecat or site.
             $coursecat = get_record('course_categories','id',$context->instanceid);
-            if ($coursecat->parent) {
+            if (!empty($coursecat->parent)) {
                 // return parent value if exist.
                 $parent = get_context_instance(CONTEXT_COURSECAT, $coursecat->parent);
             } else {


In reply to Tim Hunt

Re: NOTICE: Roles now in HEAD

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
Did I hear "bug in upgrade logging code"? I am going to work on that more after the 1.6.2 release wink
In reply to Petr Skoda

Re: NOTICE: Roles now in HEAD

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Yes, so this morning I was going the upgrade, and in /moodledata/upgradelogs/ I have upg_20060809-1055.html and upg_20060809-1105.html.

The 1105 one ends when the upgrade crashed at a syntax error in the forum module upgrade.

So I fixed that, and resumed the upgrade at about 11:15, and nothing else was logged.
In reply to Tim Hunt

Re: NOTICE: Roles now in HEAD

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Thanks Tim! I knew parts were rough but not that rough! blush

Tabs fixed and your patches checked in (please feel free to check such things straight in if you're in the area anyway!)
In reply to Tim Hunt

Re: NOTICE: Roles now in HEAD

by Vy-Shane Sin Fat -
The tabs would probably be my fault. I installed Eclipse to help me track down some missing brackets and I forgot to change the IDE editing settings from spaces to tabs. Apologies blush
In reply to Vy-Shane Sin Fat

Re: NOTICE: Roles now in HEAD

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
That's OK, but you might like to change the configuration now. I notice you checked in some more tabs last night.

It is hard to find the right settings in Eclipse, I know from experience that there are some configuration options that appear to do this, but don't actually work in the PHP editor.

In the Window -> Preferences ... dialogue, select PHPeclipse Web Development -> PHP from the tree.

On that page, switch to the 'Typing' tab, and turn on the 'Insert spaces for tab' option there. (You probably also want to check that the 'Remove trailing whitespace on editor save' Option.)

I am pretty sure that is the key setting.

I keep meaning to make a page on Moodledocs, describing the recommeneded Eclipse setup for Moodle development.
In reply to Tim Hunt

Re: NOTICE: Roles now in HEAD

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 bit about the remaining upgrade error. This it the fault of the workshop module dp/postgres.php file.

The errors came from this block of upgrade code:

if ($oldversion < 2005041201) { // Mass cleanup of bad upgrade scripts
// Some of those steps might fail, it is normal.
In reply to Martin Dougiamas

Re: NOTICE: Roles now in HEAD

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I've started a discussion in the testing forum about Roles, so please direct further feedback about this topic there.
In reply to Martin Dougiamas

Re: NOTICE: Roles now in HEAD

by Chardelle Busch -
Picture of Core developers
Thanks for the laughs Don and Julian.

(I think the little(?) guy is really happy about the new roles.)