Skip to content

Commit dcb59cd

Browse files
committed
Merge branch 'Silic0nS0ldier-hotfix-development' into hotfix-development
2 parents 961e822 + e49a4f4 commit dcb59cd

2 files changed

Lines changed: 28 additions & 23 deletions

File tree

userfrosting/controllers/InstallController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,22 @@ public function setupMasterAccount(){
230230

231231
// Create the master user
232232
$user = new User($data);
233+
233234
$user->id = $this->_app->config('user_id_master');
234235

236+
// If using SQL Server or Azure SQL Server, store the user now.
237+
if (\Illuminate\Database\Capsule\Manager::connection()->getPdo()->getAttribute(\PDO::ATTR_DRIVER_NAME) == "sqlsrv") {
238+
// Manually insert master user to overcome session IDENTITY_INSERT restriction caused by AUTO_NUMBER specification.
239+
$tableName = $user->getTable();
240+
$values = $user->export();
241+
$values['created_at'] = \Carbon\Carbon::now();
242+
$values['updated_at'] = \Carbon\Carbon::now();
243+
\Illuminate\Database\Capsule\Manager::statement("SET IDENTITY_INSERT [$tableName] ON; INSERT INTO [$tableName] (id, user_name, display_name, email, password, flag_verified, locale, primary_group_id, title, created_at, updated_at) VALUES (:id, :user_name, :display_name, :email, :password, :flag_verified, :locale, :primary_group_id, :title, :created_at, :updated_at);", $values);
244+
245+
// Get master user back from database
246+
$user = User::where('id', $this->_app->config('user_id_master'))->first();
247+
}
248+
235249
// Add user to default groups, including default primary group
236250
$defaultGroups = Group::where('is_default', GROUP_DEFAULT)->get();
237251
$user->addGroup($primaryGroup->id);

userfrosting/models/database/Database.php

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ public static function install(){
305305
// Setup default groups
306306
Capsule::table(static::getSchemaTable('group')->name)->insert([
307307
[
308-
'id' => 1,
309308
'name' => 'User',
310309
'is_default' => GROUP_DEFAULT_PRIMARY,
311310
'can_delete' => 0,
@@ -315,7 +314,6 @@ public static function install(){
315314
'icon' => 'fa fa-user'
316315
],
317316
[
318-
'id' => 2,
319317
'name' => 'Administrator',
320318
'is_default' => GROUP_NOT_DEFAULT,
321319
'can_delete' => 0,
@@ -325,7 +323,6 @@ public static function install(){
325323
'icon' => 'fa fa-flag'
326324
],
327325
[
328-
'id' => 3,
329326
'name' => 'Zerglings',
330327
'is_default' => GROUP_NOT_DEFAULT,
331328
'can_delete' => 1,
@@ -336,60 +333,54 @@ public static function install(){
336333
]
337334
]);
338335

336+
// Get default groups id's.
337+
$user = Capsule::table(static::getSchemaTable('group')->name)->where('name', '=', 'User')->first()['id'];
338+
$admin = Capsule::table(static::getSchemaTable('group')->name)->where('name', '=', 'Administrator')->first()['id'];
339339

340340
// Setup default authorizations
341341
Capsule::table(static::getSchemaTable('authorize_group')->name)->insert([
342342
[
343-
'id' => 1,
344-
'group_id' => 1,
343+
'group_id' => $user,
345344
'hook' => 'uri_dashboard',
346345
'conditions' => 'always()'
347346
],
348347
[
349-
'id' => 2,
350-
'group_id' => 2,
348+
'group_id' => $admin,
351349
'hook' => 'uri_dashboard',
352350
'conditions' => 'always()'
353351
],
354352
[
355-
'id' => 3,
356-
'group_id' => 2,
353+
'group_id' => $admin,
357354
'hook' => 'uri_users',
358355
'conditions' => 'always()'
359356
],
360357
[
361-
'id' => 4,
362-
'group_id' => 1,
358+
'group_id' => $user,
363359
'hook' => 'uri_account_settings',
364360
'conditions' => 'always()'
365361
],
366362
[
367-
'id' => 5,
368-
'group_id' => 1,
363+
'group_id' => $user,
369364
'hook' => 'update_account_setting',
370365
'conditions' => 'equals(self.id, user.id)&&in(property,[\"email\",\"locale\",\"password\"])'
371366
],
372367
[
373-
'id' => 6,
374-
'group_id' => 2,
368+
'group_id' => $admin,
375369
'hook' => 'update_account_setting',
376-
'conditions' => '!in_group(user.id,2)&&in(property,[\"email\",\"display_name\",\"title\",\"locale\",\"flag_password_reset\",\"flag_enabled\"])'
370+
'conditions' => '!in_group(user.id,'.$admin.')&&in(property,[\"email\",\"display_name\",\"title\",\"locale\",\"flag_password_reset\",\"flag_enabled\"])'
377371
],
378372
[
379-
'id' => 7,
380-
'group_id' => 2,
373+
'group_id' => $admin,
381374
'hook' => 'view_account_setting',
382375
'conditions' => 'in(property,[\"user_name\",\"email\",\"display_name\",\"title\",\"locale\",\"flag_enabled\",\"groups\",\"primary_group_id\"])'
383376
],
384377
[
385-
'id' => 8,
386-
'group_id' => 2,
378+
'group_id' => $admin,
387379
'hook' => 'delete_account',
388-
'conditions' => '!in_group(user.id,2)'
380+
'conditions' => '!in_group(user.id,'.$admin.')'
389381
],
390382
[
391-
'id' => 9,
392-
'group_id' => 2,
383+
'group_id' => $admin,
393384
'hook' => 'create_account',
394385
'conditions' => 'always()'
395386
]

0 commit comments

Comments
 (0)