Skip to content

Issue #55: [UPD] make userkey respect suspended status of users#87

Open
IJOL wants to merge 3 commits intocatalyst:MOODLE_33PLUSfrom
anodino-dev:trivax
Open

Issue #55: [UPD] make userkey respect suspended status of users#87
IJOL wants to merge 3 commits intocatalyst:MOODLE_33PLUSfrom
anodino-dev:trivax

Conversation

@IJOL
Copy link

@IJOL IJOL commented Nov 14, 2022

No description provided.

@dmitriim
Copy link
Member

Hi @IJOL !

Thanks for your patch. It mostly looks ok. Just a couple of things to fix before we can land it,

  1. Can you please create an issue describing the problem you are trying to solve. This is for others who may be struggling to know that it has been fixed.
  2. Can you please add automatic tests to cover a new logic?

@dmitriim
Copy link
Member

dmitriim commented Mar 30, 2023

Hi @IJOL any chance you can fix issues before we can merge the code in?

@dmitriim dmitriim changed the title [UPD] make userkey respect suspended status of users Issue #55: [UPD] make userkey respect suspended status of users May 17, 2023
…ing event will add a log record to an application log."
@IJOL
Copy link
Author

IJOL commented Aug 2, 2023

Hmm, is starting to be self evident that i need some help to pass the tests, is my first test case for php ever, and I'm little confused.. any help will be great..


$user = $this->getDataGenerator()->create_user();
$user->suspended = 1;
$this->setUser($user);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you trying to test here? I don't think you need set a user here and then try to login again, but using a key.

public function test_throwing_exception_if_user_is_suspended() {
global $USER, $SESSION;

$user = $this->getDataGenerator()->create_user();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is already created user for the test. You can use $this->user.

global $USER, $SESSION;

$user = $this->getDataGenerator()->create_user();
$user->suspended = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to save this state to DB.

$this->create_user_private_key();
$_POST['key'] = 'TestKey';

$this->expectException(invalid_parameter_exception::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before checking this, can you please check that login failed event has been triggered?


$user = get_complete_user_data('id', $key->userid);
if (!empty($user->suspended)) {
$failurereason = AUTH_LOGIN_SUSPENDED;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you really need this variable? Could be passed as is to the code below.

$event = \core\event\user_login_failed::create(array('userid' => $user->id,
'other' => array('username' => $user->username, 'reason' => $failurereason)));
$event->trigger();
throw new invalid_parameter_exception('User suspended');
Copy link
Member

@dmitriim dmitriim Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this error will be displayed to a user, can we please replace this with moodle_exception + add a lang string so it could be localised.

@dmitriim
Copy link
Member

dmitriim commented Aug 2, 2023

Thanks @IJOL
The patch looks almost ready. Few things to polish it up and we can merge. Great job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants