Esempio n. 1
0
class Usergroup(db.Model):

    __tablename__ = 'user_group'

    id = Column(db.BigInteger, primary_key=True, autoincrement=True)
    name = Column(db.String(100), unique=True)
    parent_name = Column(db.String(100), default='Basic')
    create_by = Column(db.String(32))
    create_time = Column(db.DateTime, default=date_time)
    modified_date = Column(db.DateTime, default=create_time)
    modified_by = Column(db.String(32), default=create_by)
    is_deleted = Column(db.Boolean, default=False)
    users = db.relationship('User',
                            secondary=user2group,
                            backref=db.backref('group',
                                               lazy='dynamic',
                                               cascade='all, delete'))
    roles = db.relationship('Role',
                            secondary=role2group,
                            backref=db.backref('group',
                                               lazy='dynamic',
                                               cascade='all, delete'))

    # 数据表属性 初始化
    def __init__(self, name, create_by, _id=None):
        self.id = _id
        self.name = name
        self.create_by = create_by
        # self.is_activated = is_activated  # 0-关闭 1-活动

    def __repr__(self):
        return "<UserGroup'{}'>".format('用户组名: ' + self.name + "\t创建时间:" +
                                        str(self.create_time))
Esempio n. 2
0
class Usergroup(db.Model):
    # 表的名字:
    __tablename__ = 'user_group'
    
    id = Column(db.BigInteger, primary_key=True, autoincrement=True)
    name = Column(db.String(100), nullable=False, unique=True)
    parent_name = Column(db.String(100))
    create_by = Column(db.String(32))
    create_time = Column(db.Date())
    modified_date = Column(db.Date(), default=create_time)
    modified_by = Column(db.String(32), default=create_by)
    is_deleted = Column(db.Boolean, default=False)
    users = db.relationship('User', secondary=user2group,
                            backref=db.backref('group', lazy='dynamic',
                                               cascade='all, delete'))
    roles = db.relationship('Role', secondary=role2group,
                            backref=db.backref('group', lazy='dynamic',
                                               cascade='all, delete'))
    
    # 数据表属性 初始化
    def __init__(self, name, create_time, create_by, _id=None):
        self.id = _id
        self.name = name
        self.create_time = create_time
        self.create_by = create_by
        # self.is_activated = is_activated  # 0-关闭 1-活动
    
    def __repr__(self):
        return "<UserGroup'{}'>".format('用户组名' + self.name + "\t创建时间:" +
                                        str(self.create_time))
    
    def add_user(self, user):
        self.users.append(user)
    
    def remove_user(self, user):
        self.users.remove(user)
    
    def add_users(self, users):
        for user in users:
            self.add_user(user)
    
    def get_users(self):
        for user in self.users:
            yield user
    
    def get_roles(self):
        for role in self.roles:
            yield role
Esempio n. 3
0
class Permission(db.Model):
    __tablename__ = 'permission'

    id = Column(db.BigInteger, primary_key=True, autoincrement=True)
    name = Column(db.String(100), unique=True)
    o_type = Column(db.String(10))
    create_by = Column(db.String(32))
    create_time = Column(db.DateTime, default=date_time)
    modified_date = Column(db.DateTime, default=create_time)
    modified_by = Column(db.String(32), default=create_by)
    # resource = Column(db.BigInteger, db.ForeignKey('resource.id'))
    content = Column(db.Text)
    is_deleted = Column(db.Boolean, default=False)
    roles = db.relationship('Role',
                            secondary=role2perm,
                            backref=db.backref('perms',
                                               lazy='dynamic',
                                               cascade='all, delete'))

    def __init__(self, name, o_type, create_by, content, _id=None):
        self.id = _id
        self.name = name
        self.o_type = o_type
        self.create_by = create_by
        self.content = content

    def __repr__(self):
        return "<Permission '{}'>".format('权限名称 :' + self.name + "\t类型:" +
                                          self.o_type + '\t权限内容:' +
                                          self.content + "\t创建时间:" +
                                          str(self.create_time))
        pass
Esempio n. 4
0
class Role(db.Model):
    # 表的名字:
    __tablename__ = 'role'
    
    # 表的结构:
    # primary_key等于主键
    # unique唯一
    # nullable非空
    id = Column(db.BigInteger, primary_key=True, autoincrement=True)
    name = Column(db.String(100), nullable=False, unique=True)
    role_code = Column(db.String(30))
    role_type = Column(db.String(10))
    create_by = Column(db.String(32))
    create_time = Column(db.Date())
    modified_date = Column(db.Date(), default=create_time)
    modified_by = Column(db.String(32), default=create_by)
    is_deleted = Column(db.Boolean, default=False)
    users = db.relationship('User', secondary=user2role,
                            backref=db.backref('roles', lazy='dynamic'))
    
    # 数据表属性 初始化
    def __init__(self, name, role_type, create_time, create_by, _id=None):
        self.id = _id
        self.name = name
        self.role_type = role_type  # 管理员与普通身份    readonly 1 , modify 3, owner 4
        self.create_by = create_by
        self.create_time = create_time
Esempio n. 5
0
class Resource(db.Model):
    __tablename__ = 'resource'
    
    # 表的结构:
    # primary_key等于主键
    id = Column(db.BigInteger, primary_key=True, autoincrement=True)
    name = Column(db.String(100), nullable=False, unique=True)
    res_type = Column(db.String(10))
    # owner = Column(db.Integer, db.ForeignKey('user.id'))
    create_time = Column(db.Date())
    create_by = Column(db.String(32))
    modified_date = Column(db.Date(), default=create_time)
    modified_by = Column(db.String(32), default=create_by)
    location = Column(db.String(100), nullable=True)
    content = Column(db.Text)
    is_deleted = Column(db.Boolean, default=False)
    perms = db.relationship('Permission', secondary=perm2resource,
                            backref=db.backref('resources', lazy='dynamic',
                                               cascade='all, delete'))
    
    def __init__(self, name, res_type, create_time, create_by, is_deleted,
                 _id=None):
        self.id = _id
        # self.role_group_id = role_group_id  
        self.name = name
        self.res_type = res_type  # 文件 1 , 门禁 2, 设备 3
        self.create_time = create_time
        self.create_by = create_by
        self.is_deleted = is_deleted
    
    def __repr__(self):
        return "<Role '{}'>".format(
            '资源名称' + self.name + '\t资源类型' + self.res_type + "创建时间:"
            + str(self.create_time))
Esempio n. 6
0
class AppClient(db.Model):
    __tablename__ = 'appclient'

    # 表的结构:
    client_key = db.Column(db.String(40), primary_key=True)
    client_secret = db.Column(db.String(55), index=True, unique=True)
    user = db.relationship('User')
    name = Column(db.String(100), unique=True)
    
    # public or confidential
    is_confidential = db.Column(db.Boolean)
    
    _realms = db.Column(db.Text)
    _redirect_uris = db.Column(db.Text)
    _default_scopes = db.Column(db.Text)
    
    description = Column(db.Text)
    create_time = Column(db.DateTime, default=date_time)
    modified_date = Column(db.DateTime, default=create_time)

    @property
    def client_type(self):
        if self.is_confidential:
            return 'confidential'
        return 'public'
    
    @property
    def redirect_uris(self):
        if self._redirect_uris:
            return self._redirect_uris.split()
        return []

    @property
    def default_redirect_uri(self):
        return self.redirect_uris[0]

    @property
    def default_realms(self):
        if self._realms:
            return self._realms.split()
        return []

    @property
    def default_scopes(self):
        if self._default_scopes:
            return self._default_scopes.split()
        return []