mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2025-06-14 20:16:05 +00:00
Fixes issue ngoduykhanh/PowerDNS-Admin#11.
This change populates the 'role' and 'setting' tables to their initial states via the create_db.py script which removes a step from the initial setup. We now also search for roles instead of expecting them to be at certain IDs.
This commit is contained in:
@ -187,9 +187,9 @@ class User(db.Model):
|
||||
|
||||
# first register user will be in Administrator role
|
||||
if User.query.count() == 0:
|
||||
self.role_id = 1
|
||||
self.role_id = Role.query.filter_by(name='Administrator').first().id
|
||||
else:
|
||||
self.role_id = 2
|
||||
self.role_id = Role.query.filter_by(name='User').first().id
|
||||
|
||||
self.create_user()
|
||||
logging.info('Created user "%s" in the DB' % self.username)
|
||||
@ -230,9 +230,9 @@ class User(db.Model):
|
||||
try:
|
||||
# first register user will be in Administrator role
|
||||
if User.query.count() == 0:
|
||||
self.role_id = 1
|
||||
self.role_id = Role.query.filter_by(name='Administrator').first().id
|
||||
else:
|
||||
self.role_id = 2
|
||||
self.role_id = Role.query.filter_by(name='User').first().id
|
||||
|
||||
user = User(username=self.username, firstname=self.firstname, lastname=self.lastname, role_id=self.role_id, email=self.email, password=self.get_hashed_password(self.plain_text_password))
|
||||
db.session.add(user)
|
||||
@ -340,10 +340,16 @@ class Role(db.Model):
|
||||
description = db.Column(db.String(128))
|
||||
users = db.relationship('User', backref='role', lazy='dynamic')
|
||||
|
||||
def __int__(self, id=None, name=None, description=None):
|
||||
def __init__(self, id=None, name=None, description=None):
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.description = description
|
||||
|
||||
# allow database autoincrement to do its own ID assignments
|
||||
def __init__(self, name=None, description=None):
|
||||
self.id = None
|
||||
self.name = name
|
||||
self.description = description
|
||||
|
||||
def __repr__(self):
|
||||
return '<Role %r>' % (self.name)
|
||||
@ -910,6 +916,12 @@ class Setting(db.Model):
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.value = value
|
||||
|
||||
# allow database autoincrement to do its own ID assignments
|
||||
def __init__(self, name=None, value=None):
|
||||
self.id = None
|
||||
self.name = name
|
||||
self.value = value
|
||||
|
||||
def set_mainteance(self, mode):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user