mirror of
				https://github.com/BookStackApp/BookStack.git
				synced 2025-11-03 02:13:16 +03:00 
			
		
		
		
	Fixed default registration role display options
- This also allows an admin to choose not to have a default role. - Also applied latest styleCI fixes. For #3220
This commit is contained in:
		@@ -146,7 +146,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function attachDefaultRole(): void
 | 
					    public function attachDefaultRole(): void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $roleId = setting('registration-role');
 | 
					        $roleId = intval(setting('registration-role'));
 | 
				
			||||||
        if ($roleId && $this->roles()->where('id', '=', $roleId)->count() === 0) {
 | 
					        if ($roleId && $this->roles()->where('id', '=', $roleId)->count() === 0) {
 | 
				
			||||||
            $this->roles()->attach($roleId);
 | 
					            $this->roles()->attach($roleId);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,7 +7,6 @@
 | 
				
			|||||||
 * Configuration should be altered via the `.env` file or environment variables.
 | 
					 * Configuration should be altered via the `.env` file or environment variables.
 | 
				
			||||||
 * Do not edit this file unless you're happy to maintain any changes yourself.
 | 
					 * Do not edit this file unless you're happy to maintain any changes yourself.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					 | 
				
			||||||
$dompdfPaperSizeMap = [
 | 
					$dompdfPaperSizeMap = [
 | 
				
			||||||
    'a4'     => 'a4',
 | 
					    'a4'     => 'a4',
 | 
				
			||||||
    'letter' => 'letter',
 | 
					    'letter' => 'letter',
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,7 +7,6 @@
 | 
				
			|||||||
 * Configuration should be altered via the `.env` file or environment variables.
 | 
					 * Configuration should be altered via the `.env` file or environment variables.
 | 
				
			||||||
 * Do not edit this file unless you're happy to maintain any changes yourself.
 | 
					 * Do not edit this file unless you're happy to maintain any changes yourself.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					 | 
				
			||||||
$snappyPaperSizeMap = [
 | 
					$snappyPaperSizeMap = [
 | 
				
			||||||
    'a4'     => 'A4',
 | 
					    'a4'     => 'A4',
 | 
				
			||||||
    'letter' => 'Letter',
 | 
					    'letter' => 'Letter',
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -75,6 +75,7 @@ return [
 | 
				
			|||||||
    'status_active' => 'Active',
 | 
					    'status_active' => 'Active',
 | 
				
			||||||
    'status_inactive' => 'Inactive',
 | 
					    'status_inactive' => 'Inactive',
 | 
				
			||||||
    'never' => 'Never',
 | 
					    'never' => 'Never',
 | 
				
			||||||
 | 
					    'none' => 'None',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Header
 | 
					    // Header
 | 
				
			||||||
    'header_menu_expand' => 'Expand Header Menu',
 | 
					    'header_menu_expand' => 'Expand Header Menu',
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -227,10 +227,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                            <label for="setting-registration-role">{{ trans('settings.reg_default_role') }}</label>
 | 
					                            <label for="setting-registration-role">{{ trans('settings.reg_default_role') }}</label>
 | 
				
			||||||
                            <select id="setting-registration-role" name="setting-registration-role" @if($errors->has('setting-registration-role')) class="neg" @endif>
 | 
					                            <select id="setting-registration-role" name="setting-registration-role" @if($errors->has('setting-registration-role')) class="neg" @endif>
 | 
				
			||||||
 | 
					                                <option value="0" @if(intval(setting('registration-role', '0')) === 0) selected @endif>-- {{ trans('common.none') }} --</option>
 | 
				
			||||||
                                @foreach(\BookStack\Auth\Role::all() as $role)
 | 
					                                @foreach(\BookStack\Auth\Role::all() as $role)
 | 
				
			||||||
                                    <option value="{{$role->id}}"
 | 
					                                    <option value="{{$role->id}}"
 | 
				
			||||||
                                            data-system-role-name="{{ $role->system_name ?? '' }}"
 | 
					                                            data-system-role-name="{{ $role->system_name ?? '' }}"
 | 
				
			||||||
                                            @if(setting('registration-role', \BookStack\Auth\Role::first()->id) == $role->id) selected @endif
 | 
					                                            @if(intval(setting('registration-role', '0')) === $role->id) selected @endif
 | 
				
			||||||
                                    >
 | 
					                                    >
 | 
				
			||||||
                                        {{ $role->display_name }}
 | 
					                                        {{ $role->display_name }}
 | 
				
			||||||
                                    </option>
 | 
					                                    </option>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@
 | 
				
			|||||||
namespace Tests\Auth;
 | 
					namespace Tests\Auth;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use BookStack\Auth\Access\Mfa\MfaSession;
 | 
					use BookStack\Auth\Access\Mfa\MfaSession;
 | 
				
			||||||
 | 
					use BookStack\Auth\Role;
 | 
				
			||||||
use BookStack\Auth\User;
 | 
					use BookStack\Auth\User;
 | 
				
			||||||
use BookStack\Entities\Models\Page;
 | 
					use BookStack\Entities\Models\Page;
 | 
				
			||||||
use BookStack\Notifications\ConfirmEmail;
 | 
					use BookStack\Notifications\ConfirmEmail;
 | 
				
			||||||
@@ -43,7 +44,10 @@ class AuthTest extends TestCase
 | 
				
			|||||||
    public function test_normal_registration()
 | 
					    public function test_normal_registration()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // Set settings and get user instance
 | 
					        // Set settings and get user instance
 | 
				
			||||||
        $this->setSettings(['registration-enabled' => 'true']);
 | 
					        /** @var Role $registrationRole */
 | 
				
			||||||
 | 
					        $registrationRole = Role::query()->first();
 | 
				
			||||||
 | 
					        $this->setSettings(['registration-enabled' => 'true', 'registration-role' => $registrationRole->id]);
 | 
				
			||||||
 | 
					        /** @var User $user */
 | 
				
			||||||
        $user = User::factory()->make();
 | 
					        $user = User::factory()->make();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Test form and ensure user is created
 | 
					        // Test form and ensure user is created
 | 
				
			||||||
@@ -57,7 +61,12 @@ class AuthTest extends TestCase
 | 
				
			|||||||
        $resp = $this->get('/');
 | 
					        $resp = $this->get('/');
 | 
				
			||||||
        $resp->assertOk();
 | 
					        $resp->assertOk();
 | 
				
			||||||
        $resp->assertSee($user->name);
 | 
					        $resp->assertSee($user->name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->assertDatabaseHas('users', ['name' => $user->name, 'email' => $user->email]);
 | 
					        $this->assertDatabaseHas('users', ['name' => $user->name, 'email' => $user->email]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $user = User::query()->where('email', '=', $user->email)->first();
 | 
				
			||||||
 | 
					        $this->assertEquals(1, $user->roles()->count());
 | 
				
			||||||
 | 
					        $this->assertEquals($registrationRole->id, $user->roles()->first()->id);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function test_empty_registration_redirects_back_with_errors()
 | 
					    public function test_empty_registration_redirects_back_with_errors()
 | 
				
			||||||
@@ -189,6 +198,14 @@ class AuthTest extends TestCase
 | 
				
			|||||||
        $this->assertNull(auth()->user());
 | 
					        $this->assertNull(auth()->user());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function test_registration_role_unset_by_default()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $this->assertFalse(setting('registration-role'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $resp = $this->asAdmin()->get('/settings');
 | 
				
			||||||
 | 
					        $resp->assertElementContains('select[name="setting-registration-role"] option[value="0"][selected]', '-- None --');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function test_logout()
 | 
					    public function test_logout()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->asAdmin()->get('/')->assertOk();
 | 
					        $this->asAdmin()->get('/')->assertOk();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user