Block context - is it Moodle being dumb or me?

Block context - is it Moodle being dumb or me?

by Charlie Owen -
Number of replies: 6
Hey all,

We've just upgraded to 1.7.1+ from 1.6.1+. It's been a painful experience and we're actively considering rolling back to 1.6.1. angry

In the meantime, before we take that drastic step, I can't seem to get block context permissions working. I've created a new role (called student assistant) and given them the capabilities of a legacy teacher. I've then clicked the roles icon on a HTML block and assigned a user that role in that context. However... when I log in with the user given the role, nothing has changed. No editing icon appears.

Am I doing something blatently wrong or is this just another reason to roll back?
Average of ratings: -
In reply to Charlie Owen

Re: Block context - is it Moodle being dumb or me?

by Yu Zhang -
Hi,

To get this to work you need to have the student assistant to have moodle/course:manageactivities assigned to him at the course level (like a normal teacher), this is so that he will get the "turn editting on" button. If you want him to have access to all the blocks in this course you can assign moodle/site:manageblocks at the course level as well. However if you just want him to be able to manage one particular html block, you need to assign a role with
moodle/site:manageblocks at that block context. The legacy teacher capability is not really a capability and will not do anything in this situation.

Thanks for pointing this out, I have made one related changes to this so you would need to update and use the latest 1.7 code.

Yu
Average of ratings: Useful (1)
In reply to Yu Zhang

Re: Block context - is it Moodle being dumb or me?

by Charlie Owen -
Hey,

Thanks for that solution. It worked just as I expected it to - the only pre-existing block that user can edit is the one I've assigned them to.

However, there's a big drawback - because moodle/course:manageactivities has been assigned to them in the course context that user can now add activities and resources to the center column of the course, as well as adding new blocks! They can't however edit a section summary (permission denied) nor edit any block they've added.

I'm using the latest 1.7.1+ code (downloaded only an hour ago).

I've reported this as MDL-8543. smile

(Edited by Martin Dougiamas - original submission Friday, 16 February 2007, 08:43 PM)

In reply to Charlie Owen

Re: Block context - is it Moodle being dumb or me?

by Yu Zhang -
Hi Charlotte,

agree, in fact we already checked in a patch in 1.9. With this patch, if you have an editting capability assigned in a module or a block under a course, you will get the "turn editting on" button without needing to have moodle/course:manageactivities assigned at course context. But because there are quite a lot of change, we are still looking at the possiblity of back porting them to 1.8.

Thanks,

Yu
In reply to Yu Zhang

How to prevent editing-teachers from adding activities or blocks?

by J. Chan -

Hi Yu Zhang,

I wonder if we could let our editing teacher to do the following in Moodle 1.7.

  1. allow them to see the "edit this page" button
  2. allow them to manage exisiting activities ONLY
  3. allow them to move, show or hide existing blocks ONLY
  4. not allow them to add activities (= not seeing the pull-down menu to add activities)
  5. not allow them to add blocks (= not seeing the pull-down menu to add blocks).

Can I do the above restrictions by changing codes in the lib/pagelib.php file?

I read your post regarding "moodle/site:manageblocks at the course level", and "moodle/site:manageblocks at that block context" . I can't find the setting for the above two. But I can find the permission settings for "moodle/course:manageactivities at the course level". Can you give me some hints?

Cheers

James

In reply to J. Chan

Re: How to prevent editing-teachers from adding activities or blocks?

by Yu Zhang -
Hi James,

I don't think it is possible to do this in 1.7.

With the exception of 3), Everything else is possible in 1.9, see this discussion. It's somewhat troublesome as you need to go into each activity and blocks, and assign the teacher's role to the teachers with "editting capability only" in those contexts, but as you can see from the screenshot this teacher can manage limited blocks and activities, and not able to add new activities or blocks. 3) might not possible as you will need a course wide capability (it might be, but I need to run some test to confirm this)

Also, you don't need to explicitly set permissions (though you can) for moodle/site:manageblocks at block level. All you have to do is assigning a user role with that capability, say "teacher" role in that block, and he will have the capability to manage that block. But again, this only fully works in 1.9.

Cheers,

Yu
In reply to Yu Zhang

Re: How to prevent editing-teachers from adding activities or blocks?

by J. Chan -

Hi Yu Zhang

Thanks for your reply. I've tried some changes in some of my files. Now some of the problem I have below are solved:

  1. allow them to see the "edit this page" button
  2. allow them to manage exisiting activities ONLY
  3. allow them to move, show or hide existing blocks ONLY
  4. not allow them to add activities (= not seeing the pull-down menu to add activities)
  5. not allow them to add blocks (= not seeing the pull-down menu to add blocks).

but, some other strange problems occur today. Perhaps see if my "changes" of the files are OK.

For #2 and #4, I don't want them to see the pull-down of new activities and the "delete" button, so I did some changes in the course/lib.php file: I added the bolded lines to the following script:

    if (course_allowed_module($course,'label') && empty($resourceallowed)) {
        $modnames['label'] = get_string('modulename', 'label');
    }
    $output .= ' ';
     if (isadmin() or iscreator()) {                                   
    $output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&sesskey=$USER->sesskey&add=",
                $modnames, "section$section", "", $straddactivity, 'mods', $straddactivity, true);
}
    if ($vertical) {
        $output .= '</div>';
    }

and I added some lines :

 if (isadmin() or iscreator()) {                                   
    return '<span class="commands">'."\n".$leftright.$move.
           '<a class="editing_update" title="'.$str->update.'" href="'.$path.'/mod.php?update='.$mod->id.
           '&amp;sesskey='.$sesskey.$section.'"><img'.
           ' src="'.$CFG->pixpath.'/t/edit.gif" hspace="2" height="11" width="11" border="0" '.
           ' alt="'.$str->update.'" /></a>'."\n".
             '<a title="'.$str->lock.'" href="'.$path.'/lock.php?id='.$mod->id.
     '&amp;sesskey='.$sesskey.$section.'"><img'.
           ' src="'.$CFG->pixpath.'/t/lock.gif" hspace="2" height="11" width="11" border="0" '.
           ' alt="'.$str->lock.'" /></a>'.$unlock.

           '<a class="editing_delete" title="'.$str->delete.'" href="'.$path.'/mod.php?delete='.$mod->id.
           '&amp;sesskey='.$sesskey.$section.'"><img'.
           ' src="'.$CFG->pixpath.'/t/delete.gif" hspace="2" height="11" width="11" border="0" '.
           ' alt="'.$str->delete.'" /></a>'.
           "\n".$hideshow.$groupmode."\n".'</span>';
}else{

before:

    return '<span class="commands">'."\n".$leftright.$move.
           '<a class="editing_update" title="'.$str->update.'" href="'.$path.'/mod.php?update='.$mod->id.
           '&amp;sesskey='.$sesskey.$section.'"><img'.
           ' src="'.$CFG->pixpath.'/t/edit.gif" hspace="2" height="11" width="11" border="0" '.
           ' alt="'.$str->update.'" /></a>'."\n".
             '<a title="'.$str->lock.'" href="'.$path.'/lock.php?id='.$mod->id.
     '&amp;sesskey='.$sesskey.$section.'"><img'.
           ' src="'.$CFG->pixpath.'/t/lock.gif" hspace="2" height="11" width="11" border="0" '.
           ' alt="'.$str->lock.'" /></a>'.$unlock.

Also, I commented out the following lines (i.e. the underlined lines):

/*'<a class="editing_delete" title="'.$str->delete.'" href="'.$path.'/mod.php?delete='.$mod->id.
           '&amp;sesskey='.$sesskey.$section.'"><img'.
           ' src="'.$CFG->pixpath.'/t/delete.gif" hspace="2" height="11" width="11" border="0" '.
           ' alt="'.$str->delete.'" /></a>'.
*/
           "\n".$hideshow.$groupmode."\n".'</span>';
}

For #5 (not allow them to add blocks), I worked on the lib/blocklib.php: I added the bolded line to:

    if ($page->blocks_default_position() == $position && $page->user_is_editing()) {
     if (isadmin() or iscreator()) {                                   
        blocks_print_adminblock($page, $pageblocks);
    }
}
}

// This iterates over an array of blocks and calculates the preferred width
// Parameter passed by reference for speed; it's not modified.

Now, the editing-teacher can edit the pages but cannot add or delete an activity, also cannot add block. He can still (#3 be allowed them to move, show or hide existing blocks ONLY ).

Some other problems occur that is related to my resource page. I'm not sure of they are related. See here.

Cheers

James