From 94ee6e4bc35dea0a6edc052790cf2c5ac2a8b123 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 7 Jan 2024 17:33:30 +0000 Subject: [PATCH] [user] admins are exempt from the email requirement, fixes #996 --- ext/user/main.php | 4 +++- ext/user/test.php | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ext/user/main.php b/ext/user/main.php index e836e06a..f9a04dc8 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -462,7 +462,9 @@ class UserPage extends Extension throw new UserCreationException("Passwords don't match"); } if( - $user->can(Permissions::CREATE_OTHER_USER) || + // Users who can create other users (ie, admins) are exempt + // from the email requirement + !$user->can(Permissions::CREATE_OTHER_USER) && ($config->get_bool("user_email_required") && empty($event->email)) ) { throw new UserCreationException("Email address is required"); diff --git a/ext/user/test.php b/ext/user/test.php index 1aa90f2a..0761ecc8 100644 --- a/ext/user/test.php +++ b/ext/user/test.php @@ -53,4 +53,28 @@ class UserPageTest extends ShimmiePHPUnitTestCase $this->get_page('user_admin/classes'); $this->assert_text("admin"); } + + public function testCreateOther() + { + global $page; + + $this->assertException(UserCreationException::class, function () { + $this->log_out(); + $this->post_page('user_admin/create_other', [ + 'name' => 'testnew', + 'pass1' => 'testnew', + 'email' => '', + ]); + }); + $this->assertNull(User::by_name('testnew'), "Anon can't create others"); + + $this->log_in_as_admin(); + $this->post_page('user_admin/create_other', [ + 'name' => 'testnew', + 'pass1' => 'testnew', + 'email' => '', + ]); + $this->assertEquals(302, $page->code); + $this->assertNotNull(User::by_name('testnew'), "Admin can create others"); + } }