Skip to content

Commit

Permalink
Merge branch 'w13_MDL-44107_m27_canview' of git://github.com/skodak/m…
Browse files Browse the repository at this point in the history
…oodle
  • Loading branch information
marinaglancy committed Mar 25, 2014
2 parents 1f777e5 + 15f009e commit daf7b64
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/classes/event/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,18 @@ public function get_description() {
}

/**
* Define whether a user can view the event or not.
* This method was originally intended for granular
* access control on the event level, unfortunately
* the proper implementation would be too expensive
* in many cases.
*
* @deprecated since 2.7
*
* @param int|\stdClass $user_or_id ID of the user.
* @return bool True if the user can view the event, false otherwise.
*/
public function can_view($user_or_id = null) {
debugging('can_view() method is deprecated, use anonymous flag instead if necessary.', DEBUG_DEVELOPER);
return is_siteadmin($user_or_id);
}

Expand Down
3 changes: 3 additions & 0 deletions mod/feedback/classes/event/course_module_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ protected function init() {
/**
* Define whether a user can view the event or not. Make sure no one except admin can see details of an anonymous response.
*
* @deprecated since 2.7
*
* @param int|\stdClass $userorid ID of the user.
* @return bool True if the user can view the event, false otherwise.
*/
public function can_view($userorid = null) {
global $USER;
debugging('can_view() method is deprecated, use anonymous flag instead if necessary.', DEBUG_DEVELOPER);

if (empty($userorid)) {
$userorid = $USER;
Expand Down
3 changes: 3 additions & 0 deletions mod/feedback/classes/event/response_deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@ protected function get_legacy_logdata() {
/**
* Define whether a user can view the event or not. Make sure no one except admin can see details of an anonymous response.
*
* @deprecated since 2.7
*
* @param int|\stdClass $userorid ID of the user.
* @return bool True if the user can view the event, false otherwise.
*/
public function can_view($userorid = null) {
global $USER;
debugging('can_view() method is deprecated, use anonymous flag instead if necessary.', DEBUG_DEVELOPER);

if (empty($userorid)) {
$userorid = $USER;
Expand Down
3 changes: 3 additions & 0 deletions mod/feedback/classes/event/response_submitted.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,14 @@ protected function get_legacy_logdata() {
/**
* Define whether a user can view the event or not. Make sure no one except admin can see details of an anonymous response.
*
* @deprecated since 2.7
*
* @param int|\stdClass $userorid ID of the user.
* @return bool True if the user can view the event, false otherwise.
*/
public function can_view($userorid = null) {
global $USER;
debugging('can_view() method is deprecated, use anonymous flag instead if necessary.', DEBUG_DEVELOPER);

if (empty($userorid)) {
$userorid = $USER;
Expand Down
8 changes: 8 additions & 0 deletions mod/feedback/tests/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ public function test_response_deleted_event() {
// Test can_view() .
$this->setUser($this->eventuser);
$this->assertFalse($event->can_view());
$this->assertDebuggingCalled();
$this->setAdminUser();
$this->assertTrue($event->can_view());
$this->assertDebuggingCalled();

// Create a response, with anonymous set to no and test can_view().
$response = new stdClass();
Expand All @@ -162,8 +164,10 @@ public function test_response_deleted_event() {
// Test can_view() .
$this->setUser($this->eventuser);
$this->assertTrue($event->can_view());
$this->assertDebuggingCalled();
$this->setAdminUser();
$this->assertTrue($event->can_view());
$this->assertDebuggingCalled();
$this->assertEventContextNotUsed($event);
}

Expand Down Expand Up @@ -228,8 +232,10 @@ public function test_response_submitted_event() {
$this->assertEquals(FEEDBACK_ANONYMOUS_YES, $event->other['anonymous']);
$this->setUser($this->eventuser);
$this->assertFalse($event->can_view());
$this->assertDebuggingCalled();
$this->setAdminUser();
$this->assertTrue($event->can_view());
$this->assertDebuggingCalled();

// Test legacy data.
$this->assertEventLegacyLogData(null, $event);
Expand Down Expand Up @@ -262,8 +268,10 @@ public function test_response_submitted_event() {

// Test can_view().
$this->assertTrue($event->can_view());
$this->assertDebuggingCalled();
$this->setAdminUser();
$this->assertTrue($event->can_view());
$this->assertDebuggingCalled();
$this->assertEventContextNotUsed($event);
}

Expand Down

0 comments on commit daf7b64

Please sign in to comment.