Issue Details (XML | Word | Printable)

Key: MDL-13240
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Petr Skoda
Reporter: Sam Marshall
Votes: 1
Watchers: 5
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

Add timestart/timeend support back to permissions code

Created: 30/Jan/08 03:30 AM   Updated: 25/Mar/09 01:46 PM
Return to search
Component/s: Roles
Affects Version/s: 1.9
Fix Version/s: 2.0

File Attachments: 1. Text File roletimes.patch (4 kB)
2. Text File timestart.revised.patch (11 kB)
3. Text File timestart1.9.3+.patch.txt (11 kB)
4. Text File timestartHEAD.patch.txt (11 kB)
5. Text File timestartHEADcomplete.patch.txt (40 kB)

Issue Links:
Dependency
 
Relates
 

Participants: Martin Dougiamas, Petr Skoda, Sam Marshall and Tim Hunt
Security Level: None
Affected Branches: MOODLE_19_STABLE
Fixed Branches: MOODLE_20_STABLE


 Description  « Hide
Support for timestart in the capabilities code was removed by MDL-8785 mostly for performance reasons, although there was also a complicated justification of the decision.

IMO this behaviour is bad - it's very confusing. You set a user's enrolment to the future but they are allowed to access the site now? why? (Removing on cron is ok for the end date...) Adding and removing things in enrolment plugins may be technically possible but could be pretty difficult.

In my opinion, if timestart is not implemented properly then it should be removed from the database.

However, with the new queries it should probably not be a performance issue as far as I can see (they don't look that scary). I have done a patch (against 1.9 actually though probably a suitable change for that) which adds this feature back, attached. The patch applies only to functions which are normally used to check permissions, not to all the 'informational' ones (so e.g. if you get a list of the students on a course, it will still include those who 'haven't started yet', etc - they just won't be able to get in yet).

I have not yet tested performance. Would it be worth doing so?

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Sam Marshall added a comment - 30/Jan/08 03:32 AM
'Probably not a suitable change for 1.9', that was supposed to say. Although I note that interface supporting timestart has been added, so it's a bit embarrassing that it doesn't work. (Could be resolved by removing the UI again...)

Martin Dougiamas added a comment - 30/Jan/08 04:18 PM - edited
The main problem was performance of the inequalities on some really heavy-used JOIN queries (forum cron, for example). I don't think these should be brought back.

The suggestion in MDL-8785 to augment it with a boolean flag still sounds good to me (see MDL-8789 ). A cron job could quickly update the flag on a regular basis:

UPDATE role_assignments SET current = (timestart < $now AND (timeend >= $now OR timeend=0 ) )

Would have to be 2.0 though, as it would mean a new field.

Where is the interface to support timestart that you refer to?


Sam Marshall added a comment - 30/Jan/08 07:27 PM
UI is in admin/roles/assign.php, the 'Starting from' dropdown affects timestart; sets either now, or course start date. IMO this option should probably be hidden for 1.9 release since it isn't going to be implemented.

(There is also a dropdown 'Enrolment duration' which uses timeend so presumably works.)

If there are performance problems with inequalities in general in some databases (rather than just when they're part of very complex queries which is what I had assumed) then I agree that your solution to update on cron is better.

There are also a few other issues in this area to do with how this is displayed. For example it might be nice if users who are 'not current' were shown greyed-out in the interface, etc. So maybe it is a bigger task...

[I guess we can live without timestart working as long as we're careful not to set the 'visible to students' flag on courses until they go live, so I think we'll do that locally for now.]


Sam Marshall added a comment - 30/Jan/08 07:39 PM
Gah, update - apparently that's not an acceptable solution for us, we need this to work.

I will do a patch shortly for 2.0 to add the database field 'current' , the cron query to check timestart and update current, and the check of 'current' in the same queries that were affected in my original patch.


Tim Hunt added a comment - 29/Oct/08 10:05 AM
Sam, did you ever make that patch?

Sam Marshall added a comment - 29/Oct/08 07:58 PM
Don't think so, sorry! However here is the latest patch for 1.9 (I think - I also have an 'OU update' one, but I think that is based on this as the times are very similar.

Martin Dougiamas added a comment - 31/Oct/08 11:26 AM
Looks good! Bouncing to Tim!

(Don't forget to remove the timestart/timeend rounding code mentioned in MDL-8785)


Tim Hunt added a comment - 05/Nov/08 07:42 PM
This patch applies cleanly to the tip of the 1.9 stable branch.

Now (tomorrow) to merge to HEAD.


Tim Hunt added a comment - 05/Nov/08 08:15 PM
So much for tomorrow.

This patch applies to HEAD. Now I just need to review it and check it in.


Petr Skoda added a comment - 05/Nov/08 11:01 PM - edited
hmm, I agree that time limited role assignments are good in some specific cases, but I do not agree these should be used to limit course enrolments - this seems like just another hack to work around problems caused by course:view, legacy guest capability, etc. Major problem is that if you do not have any role with course:view in course you are unenrolled from course and some of your data is lost!

I suppose people want to limit access to course depending on some dates/conditions, but they want to see them in gradebook at ALL times (if you remove role==unenrol users/grades disappear!, subscriptions are lost, group membership is gone). This is not about removing roles, this is about restricting of access to course imo.

The time bases roles could be used for example to specify a date range when students may add glossary entries, you would crate a separate role without course:view assigned at module level only. If this gets implemented with current role based enrolments I would vote loudly to allow timestart/end only for roles without the course:view capability enabled (those can not be used for enrolment).

What I really want is the separation of course enrolment from role assignments, multiple enrolment plugins of the same type in one course, elimination of the negative legacy guest capability (if you get it somehow, there is no way to get rid of it), global group enrolment, etc. Improved performance would be just a nice by product.

Please could we redesign the enrollment framework first, I am sure several current long standing problems would disappear.


Tim Hunt added a comment - 06/Nov/08 12:52 PM
I agree that enrolment needs to be rethought.

However, that is not a good reason for ignoring this bug. We have current UI for setting up timed enrolments, and we have all this data in the databse, and then accesslib just ignores it. That is a bug. Bugs should be fixed, and all the hard work on this is nearly finished.

When you come to rethink enrolments, then surely it is easier to start from a place with fewer bugs, rather than starting from a baseline where things work inconsistently.


Tim Hunt added a comment - 06/Nov/08 12:55 PM
Oh, and it would be really great if you could summarise your thoughts about enrolments on Moodle docs. Then allow several weeks for discussions in general developer, roles and capabilities, and enrolment forums before you want to start writing code.

Whenever I do manage to get a good discussion going about something I am working on, I am always surprised at how many good ideas I get, even when I already think I know all the answers.


Tim Hunt added a comment - 06/Nov/08 02:15 PM
Further refined patch:

1. Confirming we don't need any code in backup/restore, because restore uses the role_assign function, which initialises the active field properly.

2. admin/generator.php was touching the role_assignments table directly, rather than using role_assign(). Fixed in a separate commit.

3. There are some refererences to the role_assignments table outside accesslib.php, which sam missed. I'm fixing those queries that need it. Wow! there were a lot.

4. upgrade.php code redone to use 2.0 XMLDB functions.

5. We are not creating an index on the role_assignements.active field. That seems OK to me.


Tim Hunt added a comment - 25/Mar/09 01:46 PM
Petr is taking over responsibility for these things.