mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Started work on making the public role/user configurable
Create a new 'public' guest user and made the public role visible on role setting screens.
This commit is contained in:
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class RemoveHiddenRoles extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Remove the hidden property from roles
|
||||
Schema::table('roles', function(Blueprint $table) {
|
||||
$table->dropColumn('hidden');
|
||||
});
|
||||
|
||||
// Add column to mark system users
|
||||
Schema::table('users', function(Blueprint $table) {
|
||||
$table->string('system_name')->nullable()->index();
|
||||
});
|
||||
|
||||
// Insert our new public system user.
|
||||
$publicUserId = DB::table('users')->insertGetId([
|
||||
'email' => 'guest@example.com',
|
||||
'name' => 'Guest',
|
||||
'system_name' => 'public',
|
||||
'email_confirmed' => true,
|
||||
'created_at' => \Carbon\Carbon::now(),
|
||||
'updated_at' => \Carbon\Carbon::now(),
|
||||
]);
|
||||
|
||||
// Get the public role
|
||||
$publicRole = DB::table('roles')->where('system_name', '=', 'public')->first();
|
||||
|
||||
// Connect the new public user to the public role
|
||||
DB::table('role_user')->insert([
|
||||
'user_id' => $publicUserId,
|
||||
'role_id' => $publicRole->id
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('roles', function(Blueprint $table) {
|
||||
$table->boolean('hidden')->default(false);
|
||||
$table->index('hidden');
|
||||
});
|
||||
|
||||
DB::table('users')->where('system_name', '=', 'public')->delete();
|
||||
|
||||
Schema::table('users', function(Blueprint $table) {
|
||||
$table->dropColumn('system_name');
|
||||
});
|
||||
|
||||
DB::table('roles')->where('system_name', '=', 'public')->update(['hidden' => true]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user