Development:Anonymous Users: Difference between revisions
m (→Objective) |
mNo edit summary |
||
(25 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
{{Moodle 2.0}} | {{Moodle 2.0}} | ||
== Objective == | |||
To allow users to switch into an anonymous mode when using certain activities eg when posting to a forum, so that the user's real identity cannot be ascertained by other non-privileged users. | |||
__TOC__ | __TOC__ | ||
== | == Possible Use Cases == | ||
# '''Activity:''' for example a forum may be switched into anonymous mode by teacher rendering all posts anonymous. | |||
# '''User:''' a user may choose to participate in an activity anonymously. In this case the teacher would switch the activity into an optional mode. For example, the forum module, when posting to a forum in an optional anonymous mode, the student could choose at the time of posting whether the post should be anonymous; | |||
# '''Role Play:''' a teacher may choose to run the whole course in an anonymous mode to allow students to role play. In this case the anonymous mode will be forced to "yes" in the course settings. | |||
== Settings == | |||
=== Global === | |||
[[Image:Anon global.png]] | |||
=== Course === | |||
[[Image:Anon course.png]] | |||
=== Activity === | |||
[[Image:Anon activity.png]] | |||
=== User Profile === | |||
[[Image:Anon profile.png]] | |||
== Code Changes == | |||
=== Status definitions === | |||
define('ANONYMITY_ON', 2); | |||
define('ANONYMITY_OPTIONAL', 1); | |||
define('ANONYMITY_INHERIT', 0); | |||
define('ANONYMITY_OFF', -1); | |||
define('ANONYMITY_DISABLED', -9999); | |||
=== Capabilities === | |||
'moodle/anonymity:viewrealname' => array( | |||
'riskbitmask' => RISK_PERSONAL, | |||
'captype' => 'read', | |||
'contextlevel' => CONTEXT_SYSTEM, | |||
'legacy' => array( | |||
'editingteacher' => CAP_ALLOW, | |||
'manager' => CAP_ALLOW | |||
) | |||
) | |||
=== DB Tables === | |||
New table: '''anonymity_context''' | |||
*Record the anonymity status in given contexts | |||
{| border="1" | |||
|- | |||
!field | |||
!type | |||
!description | |||
|- | |||
|id | |||
|int(10) unsigned | |||
|auto-increment | |||
|- | |||
|contextid | |||
|int(10) unsigned | |||
|id from the context table | |||
|- | |||
|status | |||
|int(4) signed | |||
|anonymity status | |||
|} | |||
New table: '''anonymity_user_context''' | |||
*Record user aliases for a particular context | |||
{| border="1" | |||
|- | |||
!field | |||
!type | |||
!description | |||
|- | |||
|id | |||
|int(10) unsigned | |||
|auto-increment | |||
|- | |||
|userid | |||
|int(10) unsigned | |||
|id from the user table | |||
|- | |||
|contextid | |||
|int(10) unsigned | |||
|id from the context table | |||
|- | |||
|alias | |||
|varchar(255) | |||
|the user's alias for this given context | |||
|} | |||
=== Code === | |||
The '''fullname''' function in lib/moodlelib.php will be changed to return an anonymous name if applicable. We can take advantage of the Navigation 2.0 changes which ensure each page is linked to a specific context (That is, $PAGE->context will always to set to something sensible.) | |||
As the fullname function may be called many times on a single page, it is extremely important that we keep the function as efficient as possible. It is also important that we implement these changes in a way that works in most instances without changes to the calling code. | |||
function fullname($user, $override=false, $anonymous=false) | |||
where the user object may also contain an ''alias'' property. The ''$anonymous'' parameter will only be checked if the anonymity status for the current context is set to optional. | |||
What we return depends on: | |||
* anonymity status for the current context | |||
* $anonymous parameter | |||
* existing user alias in the '''anonymity_user_context''' table | |||
* ''alias'' property in the passed ''$user'' object | |||
* ''moodle/anonymity:viewrealname'' permission for the current user | |||
* $CFG->anonymityuseraliases | |||
So what do we return? The following table shows the possibilities for various scenarios | |||
== | {| border="1" class="sortable" style="text-align:center" | ||
|- style="font-size:0.8em" valign="top" | |||
!anonymity status<br /> | |||
!$anonymous<br /> | |||
!$CFG->anonymityuseraliases<br /> | |||
!anonymity_user_alias.alias<br /> | |||
!$user->alias<br /> | |||
!moodle/anonymity:viewrealname<br /> | |||
!return example<br /> | |||
|- | |||
|off | |||
|N/A | |||
|N/A | |||
|N/A | |||
|N/A | |||
|N/A | |||
|"Real Name" | |||
|- | |||
|optional | |||
|true | |||
|false | |||
|N/A | |||
|N/A | |||
|true | |||
|get_string('anonymous').<br />"(Real Name)" | |||
|- | |||
|optional | |||
|true | |||
|false | |||
|N/A | |||
|N/A | |||
|false | |||
|get_string('anonymous') | |||
|- | |||
|optional | |||
|true | |||
|true | |||
|''(not set)'' | |||
|''(not set)'' | |||
|true | |||
|get_string('anonymous').<br />"(Real Name)" | |||
|- | |||
|optional | |||
|true | |||
|true | |||
|''(not set)'' | |||
|''(not set)'' | |||
|false | |||
|get_string('anonymous') | |||
|- | |||
|optional | |||
|true | |||
|true | |||
|''(not set)'' | |||
|"Fred Jones" | |||
|true | |||
|"Fred Jones (Real Name) | |||
|- | |||
|optional | |||
|true | |||
|true | |||
|''(not set)'' | |||
|"Fred Jones" | |||
|false | |||
|"Fred Jones" | |||
|- | |||
|optional | |||
|true | |||
|true | |||
|"Bob Smith" | |||
|''(not set)'' | |||
|false | |||
|Bob Smith | |||
|- | |||
|optional | |||
|true | |||
|true | |||
|"Bob Smith" | |||
|''(not set)'' | |||
|true | |||
|"Bob Smith (Real Name)" | |||
|- | |||
|optional | |||
|true | |||
|true | |||
|"Bob Smith" | |||
|"Fred Jones" | |||
|false | |||
|"Fred Jones" | |||
|- | |||
|optional | |||
|true | |||
|true | |||
|"Bob Smith" | |||
|"Fred Jones" | |||
|true | |||
|"Fred Jones (Real Name)" | |||
|- | |||
|optional | |||
|false | |||
|N/A | |||
|N/A | |||
|N/A | |||
|N/A | |||
|"Real Name" | |||
|- | |||
|on | |||
|N/A | |||
|false | |||
|N/A | |||
|N/A | |||
|true | |||
|get_string('anonymous').<br />"(Real Name)" | |||
|- | |||
|on | |||
|N/A | |||
|false | |||
|N/A | |||
|N/A | |||
|false | |||
|get_string('anonymous') | |||
|- | |||
|on | |||
|N/A | |||
|true | |||
|''(not set)'' | |||
|''(not set)'' | |||
|true | |||
|get_string('anonymous').<br />"(Real Name)" | |||
|- | |||
|on | |||
|N/A | |||
|true | |||
|''(not set)'' | |||
|''(not set)'' | |||
|false | |||
|get_string('anonymous') | |||
|- | |||
|on | |||
|N/A | |||
|true | |||
|''(not set)'' | |||
|"Fred Jones" | |||
|true | |||
|"Fred Jones (Real Name) | |||
|- | |||
|on | |||
|N/A | |||
|true | |||
|''(not set)'' | |||
|"Fred Jones" | |||
|false | |||
|"Fred Jones" | |||
|- | |||
|on | |||
|N/A | |||
|true | |||
|"Bob Smith" | |||
|''(not set)'' | |||
|false | |||
|Bob Smith | |||
|- | |||
|on | |||
|N/A | |||
|true | |||
|"Bob Smith" | |||
|''(not set)'' | |||
|true | |||
|"Bob Smith (Real Name)" | |||
|- | |- | ||
|on | |||
|N/A | |||
|true | |||
|"Bob Smith" | |||
|"Fred Jones" | |||
|false | |||
|"Fred Jones" | |||
|- | |- | ||
| | |on | ||
| | |N/A | ||
| | |true | ||
|"Bob Smith" | |||
|"Fred Jones" | |||
|true | |||
|"Fred Jones (Real Name)" | |||
|} | |} | ||
== | ==See also== | ||
* MDL-1071 Add a forum option to allow anonymous posting |
Latest revision as of 13:26, 2 May 2010
Note: This article is a work in progress. Please use the page comments or an appropriate moodle.org forum for any recommendations/suggestions for improvement.
Moodle 2.0
Objective
To allow users to switch into an anonymous mode when using certain activities eg when posting to a forum, so that the user's real identity cannot be ascertained by other non-privileged users.
Possible Use Cases
- Activity: for example a forum may be switched into anonymous mode by teacher rendering all posts anonymous.
- User: a user may choose to participate in an activity anonymously. In this case the teacher would switch the activity into an optional mode. For example, the forum module, when posting to a forum in an optional anonymous mode, the student could choose at the time of posting whether the post should be anonymous;
- Role Play: a teacher may choose to run the whole course in an anonymous mode to allow students to role play. In this case the anonymous mode will be forced to "yes" in the course settings.
Settings
Global
Course
Activity
User Profile
Code Changes
Status definitions
define('ANONYMITY_ON', 2); define('ANONYMITY_OPTIONAL', 1); define('ANONYMITY_INHERIT', 0); define('ANONYMITY_OFF', -1); define('ANONYMITY_DISABLED', -9999);
Capabilities
'moodle/anonymity:viewrealname' => array( 'riskbitmask' => RISK_PERSONAL, 'captype' => 'read', 'contextlevel' => CONTEXT_SYSTEM, 'legacy' => array( 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW ) )
DB Tables
New table: anonymity_context
- Record the anonymity status in given contexts
field | type | description |
---|---|---|
id | int(10) unsigned | auto-increment |
contextid | int(10) unsigned | id from the context table |
status | int(4) signed | anonymity status |
New table: anonymity_user_context
- Record user aliases for a particular context
field | type | description |
---|---|---|
id | int(10) unsigned | auto-increment |
userid | int(10) unsigned | id from the user table |
contextid | int(10) unsigned | id from the context table |
alias | varchar(255) | the user's alias for this given context |
Code
The fullname function in lib/moodlelib.php will be changed to return an anonymous name if applicable. We can take advantage of the Navigation 2.0 changes which ensure each page is linked to a specific context (That is, $PAGE->context will always to set to something sensible.)
As the fullname function may be called many times on a single page, it is extremely important that we keep the function as efficient as possible. It is also important that we implement these changes in a way that works in most instances without changes to the calling code.
function fullname($user, $override=false, $anonymous=false)
where the user object may also contain an alias property. The $anonymous parameter will only be checked if the anonymity status for the current context is set to optional.
What we return depends on:
- anonymity status for the current context
- $anonymous parameter
- existing user alias in the anonymity_user_context table
- alias property in the passed $user object
- moodle/anonymity:viewrealname permission for the current user
- $CFG->anonymityuseraliases
So what do we return? The following table shows the possibilities for various scenarios
anonymity status |
$anonymous |
$CFG->anonymityuseraliases |
anonymity_user_alias.alias |
$user->alias |
moodle/anonymity:viewrealname |
return example |
---|---|---|---|---|---|---|
off | N/A | N/A | N/A | N/A | N/A | "Real Name" |
optional | true | false | N/A | N/A | true | get_string('anonymous'). "(Real Name)" |
optional | true | false | N/A | N/A | false | get_string('anonymous') |
optional | true | true | (not set) | (not set) | true | get_string('anonymous'). "(Real Name)" |
optional | true | true | (not set) | (not set) | false | get_string('anonymous') |
optional | true | true | (not set) | "Fred Jones" | true | "Fred Jones (Real Name) |
optional | true | true | (not set) | "Fred Jones" | false | "Fred Jones" |
optional | true | true | "Bob Smith" | (not set) | false | Bob Smith |
optional | true | true | "Bob Smith" | (not set) | true | "Bob Smith (Real Name)" |
optional | true | true | "Bob Smith" | "Fred Jones" | false | "Fred Jones" |
optional | true | true | "Bob Smith" | "Fred Jones" | true | "Fred Jones (Real Name)" |
optional | false | N/A | N/A | N/A | N/A | "Real Name" |
on | N/A | false | N/A | N/A | true | get_string('anonymous'). "(Real Name)" |
on | N/A | false | N/A | N/A | false | get_string('anonymous') |
on | N/A | true | (not set) | (not set) | true | get_string('anonymous'). "(Real Name)" |
on | N/A | true | (not set) | (not set) | false | get_string('anonymous') |
on | N/A | true | (not set) | "Fred Jones" | true | "Fred Jones (Real Name) |
on | N/A | true | (not set) | "Fred Jones" | false | "Fred Jones" |
on | N/A | true | "Bob Smith" | (not set) | false | Bob Smith |
on | N/A | true | "Bob Smith" | (not set) | true | "Bob Smith (Real Name)" |
on | N/A | true | "Bob Smith" | "Fred Jones" | false | "Fred Jones" |
on | N/A | true | "Bob Smith" | "Fred Jones" | true | "Fred Jones (Real Name)" |
See also
- MDL-1071 Add a forum option to allow anonymous posting