WeBWorK Problems

BEGIN_TEXT ... END_TEXT permission-dependent options?

BEGIN_TEXT ... END_TEXT permission-dependent options?

by Patti Lamm -
Number of replies: 8
Are there BEGIN_TEXT ... END_TEXT block options allow the region to be viewed/printed only for users at a certain permission level (e.g., 'ta' and 'professor')?

The purpose would be to have 2 levels of solutions available: In one level would be what the student would see after the due date, and the other level ) might contain teaching aids and other comments not intended for students to see. Obviously this could be handled by having two versions of every problem, but that's a lot of bookkeeping to keep up with.

Failing the above, is there a way to disable the appearance of the text in the SOLUTION area for students, even after the due date? That is, they could get the correct answer after the due date, but would not see anything written in the SOLUTION block area.

Thanks in advance...
In reply to Patti Lamm

Re: BEGIN_TEXT ... END_TEXT permission-dependent options?

by Michael Gage -
Hi Patricia, The hooks are there to accomplish this although there isn't yet a neat macro to do this cleanly. (That will await a clearer understanding of exactly what features are desirable.)
 TEXT(EV3(<<'EOF')) if permissionLevel>=10;

Insert instructor only text here

EOF

BEGIN_TEXT is syntactic sugar for TEXT(EV3(<<'END_TEXT'));

This snippet will only print for instructors (level 10 or higher). You can get fancier: This snippet is from the hint() macro defined in PGbasicmacros.pl

 

my $permissionLevel = PG_restricted_eval(q!$main::envir{permissionLevel}!); 

my $PRINT_FILE_NAMES_PERMISSION_LEVEL = (PG_restricted_eval(q!defined( $main::envir{'PRINT_FILE_NAMES_PERMISSION_LEVEL'} )!))? 

PG_restricted_eval(q!$main::envir{'PRINT_FILE_NAMES_PERMISSION_LEVEL'}!) : 10000; 

# protect against undefined values 

my $printHintForInstructor = $permissionLevel >= $PRINT_FILE_NAMES_PERMISSION_LEVEL; 

This insures that hints are always printed for anyone who has permission to see the paths to the PG files. (usually set to instructor level). There is a lot of room for imaginative improvement of this capability. -- Mike
In reply to Michael Gage

Re: BEGIN_TEXT ... END_TEXT permission-dependent options?

by Davide Cervone -
Note that
    if ($permissionLevel >= 10) {
      BEGIN_TEXT
      Instructions here
      END_TEXT
    }
also works, so you don't have to resort to the ugly TEXT with EV3 form. That would also prevent you from getting updates to how BEGIN_TEXT/END_TEXT works; for example I think it now uses EV3P rather than EV3, so over time, such problems would get out of date, and might stop working altogether.

Also, you don't need to do the PG_restricted_eval stuff when you are using this within a problem file. That was only needed in the hint() macro because PGbasicmacros.pl is preloaded into the main compartment, and it needs to look up the values from the safe compartment. Since the problem is already running in the safe compartment, you can just use

  $printHintForInstructor = $permissionLevel >= $PRINT_FILE_NAMES_PERMISSION_LEVEL;
since both $permissionLevel and $PRINT_FILE_NAMES_PERMISSION_LEVEL are already defined in the main namespace (the %envir hash is used to predefine variables in the main namespace, so anything in that hash should end up as a scalar variable as well).

Davide

In reply to Davide Cervone

Re: BEGIN_TEXT ... END_TEXT permission-dependent options?

by Patti Lamm -
Many thanks for the answers, which are working like I'd hoped.

Question to Davide: If I'm putting the permission-check in the solution area, do I still need the "ugly EV3 form"? That is, I'm using:

if ($permissionLevel >= 10) {
SOLUTION(EV3(<<'END_SOLUTION'));
stuff for instructors only goes here
END_SOLUTION

} else {

SOLUTION(EV3(<<'END_SOLUTION'));
what you want students to see goes here
END_SOLUTION

}



Am I using an EV3 which will be outdated soon?

Thanks again...
In reply to Patti Lamm

Re: BEGIN_TEXT ... END_TEXT permission-dependent options?

by Michael Gage -
You can use BEGIN_HINT/END_HINT and BEGIN_SOLUTION/END_SOLUTION in the same way that you use BEGIN_TEXT/END_TEXT

EV3 has been around for a decade now and is not going to stop working. EV3P has added a few new possibilities for writing problems, but it will still process the old problems correctly. (see http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/PGbasicmacros.pl.html#ev3p for capabilities)


In reply to Patti Lamm

Re: BEGIN_TEXT ... END_TEXT permission-dependent options?

by Davide Cervone -
You can use the same technique with BEGIN_SOLUTION/END_SOLUTION, but these are relatively new (it looks like they were added in June last summer), so they may not be in the version you are using. They do appear to be in the current rel-2-4-patches version of the pg directory, so if you have updated to that since last summer, you should have them. Otherwise, you could consider going to that version (or to the HEAD version, which has been stable for quite a while, and includes some fixes that aren't in rel-2-4-patches). You can do that without having to update all of WeBWorK, if you are at a reasonably current, but earlier, version of pg.

Davide
In reply to Davide Cervone

Re: BEGIN_TEXT ... END_TEXT permission-dependent options?

by Patti Lamm -
Thanks to all. We just started using webwork at our university in Jan 09, so it's a very new installation.

I'm getting the different solutions to display on the screen appropriately, according to permission level, but cannot seem to get a hardcopy of anything but the permission=0 level solutions. Is there a flag that tells the hardcopy what is OK or not OK to print? I would like to make a hardcopy of the permission-level 10 solutions to post in Help Room staffing area, etc.

Thanks...

In reply to Patti Lamm

Re: BEGIN_TEXT ... END_TEXT permission-dependent options?

by Davide Cervone -
The changes to the hardcopy generated needed for the permission level were made on September 12th, so you probably don't have them in the version you are running. You may want to update webwork2/lib/WeBWorK/ContentGenerator/Hardcopy.pm to the current rel-2-4-patches release. That should take care of the problem.

One thing I noticed when looking into this is that the $permissionLevel is always that of the logged-in user, so if a professor acts as a student, the $permissionLevel is still professor. This means that if a student comes into your office and you look at his or her version of the problem, it will not look like what he or she sees, but will include all the professor solutions as well. I suspect that may not be what is desired.

Mike: I suggest that we add a $effectivePermissionLevel that corresponds to the permission level of the effective user. That way you can provide content based on the effective user or the actual user. I think both are desired. For example, the professor solution that Patricia is writing should be by effective user, but another situation where I had wanted permission information was in the answerDiscussion.pl library, where I wanted to know if the professor was acting as a student (so that aditional controls were available) or if it was the actual student.

On a related note, I'm a little unhappy about comparing against the constant 10 (and I know that is why you suggested the $PRINT_FILE_NAMES_PERMISSION_LEVEL solution. It seems to me that now that $permissionLevel is available, we may want to think about giving the problem access to the %permissionLevels and %userRoles hashes, and provide some sort of hasPermission() and hasEffectivePermission() functions for checking whether the user as a particular permission like "print_path_to_problem", and hasRole() and hasEffectiveRole() for checking what type of user it is. These would be pretty straight-forward, I think, given access to the hashes.

Davide
In reply to Davide Cervone

Re: BEGIN_TEXT ... END_TEXT permission-dependent options?

by Michael Gage -

Mike: I suggest that we add an $effectivePermissionLevel that corresponds to the permission level of the effective user.

I agree and this is easy enough to do. Unless there are objections I will also change the decision which prints file path names once the permission is high enough to depend on the permission of the effectiveUser rather than the permission of the user. Raghu has asked for this features so that an instructor can print hardcopies for students without the file path names.

Providing access hasPermission(user,action) is probably the way to handle all of this in the long run, but it's a bigger project. There are already hasPermission() like routines on the webwork2 side and these, or some portion of them could be shared with the PG side of the code. It will be a mid-sized project to work out how much sharing one should allow to obtain all the functionality one wants but also to continue to minimize interdependence between the two code bases and to maintain reasonable security.

For special purposes one can continue to use the mechanism used to pass PRINT_FILE_NAMES_PERMISSION_LEVEL in which the constant is set in global.conf and can be overridden in course.conf.