Add default user to allow for default groups and IAM
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

This commit is contained in:
Garrett Mills 2021-03-15 17:45:18 -05:00
parent 0844da594e
commit 3a91417db3
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
3 changed files with 33 additions and 0 deletions

View File

@ -91,6 +91,7 @@ class AuthController extends Controller {
if ( !(await User.findOne()) ) user.promote('root') if ( !(await User.findOne()) ) user.promote('root')
await user.save() await user.save()
await user.grant_defaults()
// Log in the user automatically // Log in the user automatically
await this.auth.get_provider().session(req, user) await this.auth.get_provider().session(req, user)
@ -321,6 +322,7 @@ class AuthController extends Controller {
await user.reset_password(req.body.password, 'create') await user.reset_password(req.body.password, 'create')
await user.save() await user.save()
await user.grant_defaults()
return res.api(await user.to_api()) return res.api(await user.to_api())
} }

View File

@ -40,9 +40,24 @@ class User extends AuthUser {
notify_config: NotifyConfig, notify_config: NotifyConfig,
uid_number: Number, uid_number: Number,
login_shell: String, login_shell: String,
is_default_user_for_coreid: { type: Boolean, default: false },
}} }}
} }
async grant_defaults() {
const default_user = await this.constructor.findOne({is_default_user_for_coreid: true, active: true})
this.login_shell = default_user.login_shell
this.roles = default_user.roles
this.permissions = default_user.permissions
const groups = await default_user.groups()
for ( const group of groups ) {
group.user_ids.push(this.id)
await group.save()
}
}
async get_uid_number() { async get_uid_number() {
if ( !this.uid_number ) { if ( !this.uid_number ) {
const Setting = this.models.get('Setting') const Setting = this.models.get('Setting')

View File

@ -13,6 +13,22 @@ class SettingsUnit extends Unit {
Error.stackTraceLimit = 50 Error.stackTraceLimit = 50
app.express.set('trust proxy', true) app.express.set('trust proxy', true)
const User = this.models.get('auth:User')
const user = await User.findOne({is_default_user_for_coreid: true})
if ( !user ) {
const user = new User({
uid: '__coreid_default_user__',
provider: 'flitter',
block_login: true,
first_name: 'Default_User',
last_name: 'Default_User',
ldap_visible: false,
is_default_user_for_coreid: true,
})
await user.save()
}
const Setting = this.models.get('Setting') const Setting = this.models.get('Setting')
const default_settings = this.configs.get('setting.settings') const default_settings = this.configs.get('setting.settings')
for ( const key in default_settings ) { for ( const key in default_settings ) {