예제 #1
0
def init_acl():
    _app = AppCache.get('cmdb') or App.create(name='cmdb')
    app_id = _app.id

    # 1. add resource type
    for resource_type in ResourceTypeEnum.all():
        try:
            ResourceTypeCRUD.add(app_id, resource_type, '', PermEnum.all())
        except AbortException:
            pass

    # 2. add role
    try:
        RoleCRUD.add_role(RoleEnum.CONFIG, app_id, True)
    except AbortException:
        pass
    try:
        RoleCRUD.add_role(RoleEnum.CMDB_READ_ALL, app_id, False)
    except AbortException:
        pass

    # 3. add resource and grant
    ci_types = CIType.get_by(to_dict=False)
    type_id = ResourceType.get_by(name=ResourceTypeEnum.CI,
                                  first=True,
                                  to_dict=False).id
    for ci_type in ci_types:
        try:
            ResourceCRUD.add(ci_type.name, type_id, app_id)
        except AbortException:
            pass

        ACLManager().grant_resource_to_role(ci_type.name,
                                            RoleEnum.CMDB_READ_ALL,
                                            ResourceTypeEnum.CI,
                                            [PermEnum.READ])

    relation_views = PreferenceRelationView.get_by(to_dict=False)
    type_id = ResourceType.get_by(name=ResourceTypeEnum.RELATION_VIEW,
                                  first=True,
                                  to_dict=False).id
    for view in relation_views:
        try:
            ResourceCRUD.add(view.name, type_id, app_id)
        except AbortException:
            pass

        ACLManager().grant_resource_to_role(view.name, RoleEnum.CMDB_READ_ALL,
                                            ResourceTypeEnum.RELATION_VIEW,
                                            [PermEnum.READ])
예제 #2
0
    def post(self):
        name = request.values.get('name')
        app_id = request.values.get('app_id')
        description = request.values.get('description', '')
        perms = request.values.get('perms')

        rt = ResourceTypeCRUD.add(app_id, name, description, perms)

        return self.jsonify(rt.to_dict())
예제 #3
0
    def get(self):
        page = get_page(request.values.get("page", 1))
        page_size = get_page_size(request.values.get("page_size"))
        q = request.values.get('q')
        app_id = request.values.get('app_id')

        numfound, res, id2perms = ResourceTypeCRUD.search(
            q, app_id, page, page_size)

        return self.jsonify(numfound=numfound,
                            page=page,
                            page_size=page_size,
                            groups=[i.to_dict() for i in res],
                            id2perms=id2perms)
예제 #4
0
 def get(self, type_id):
     return self.jsonify(ResourceTypeCRUD.get_perms(type_id))
예제 #5
0
    def delete(self, type_id):
        ResourceTypeCRUD.delete(type_id)

        return self.jsonify(type_id=type_id)
예제 #6
0
    def put(self, type_id):
        rt = ResourceTypeCRUD.update(type_id, **request.values)

        return self.jsonify(rt.to_dict())