Exemple #1
0
 def get(self):
     the_get = Get()
     group_id = the_get.get_id(self)
     if group_id:
         instance_staff = DBOHHOStaff()
         instance_group_staff_relation = OHHOPermission().group_and_staff
         staffs = instance_staff.get_query()
         staffs = instance_staff.get_valid(staffs)
         staffs = instance_staff.get_all(staffs)
         staff_list = list()
         group_staff_list = list()
         group_staffs = instance_group_staff_relation.get_by_group_id(
             group_id)
         group_staffs = instance_group_staff_relation.get_all(group_staffs)
         if staffs:
             for staff in staffs:
                 if group_staffs:
                     for group_staff in group_staffs:
                         if staff.username == group_staff.username:
                             group_staff_list.append(staff)
                 staff_list.append(staff)
         staff_list = list(set(staff_list) - set(group_staff_list))
         return self.render(
             PERMISSION_GROUP_STAFF_RELATION_HTML,
             add_url=PERMISSION_GROUP_STAFF_RELATION_ADD_URL,
             delete_url=PERMISSION_GROUP_STAFF_RELATION_DELETE_URL,
             list_url=PERMISSION_GROUP_BACKSTAGE_LIST_URL,
             group_id=group_id,
             staff_list=staff_list,
             group_staff_list=group_staff_list,
         )
     else:
         return self.redirect(PERMISSION_GROUP_BACKSTAGE_LIST_URL)
 def get(self):
     the_get = Get()
     group_id = the_get.get_id(self)
     if group_id:
         instance_user = DBOHHOUser()
         instance_group_user_relation = OHHOPermission().group_and_user
         users = instance_user.get_query()
         users = instance_user.get_valid(users)
         users = instance_user.get_all(users)
         user_list = list()
         group_user_list = list()
         group_users = instance_group_user_relation.get_by_group_id(
             group_id)
         group_users = instance_group_user_relation.get_all(group_users)
         if users:
             for user in users:
                 if group_users:
                     for group_user in group_users:
                         if user.username == group_user.username:
                             group_user_list.append(user)
                 user_list.append(user)
         user_list = list(set(user_list) - set(group_user_list))
         return self.render(
             PERMISSION_GROUP_USER_RELATION_HTML,
             add_url=PERMISSION_GROUP_USER_RELATION_ADD_URL,
             delete_url=PERMISSION_GROUP_USER_RELATION_DELETE_URL,
             list_url=PERMISSION_GROUP_BACKSTAGE_LIST_URL,
             group_id=group_id,
             user_list=user_list,
             group_user_list=group_user_list,
         )
     else:
         return self.redirect(PERMISSION_GROUP_BACKSTAGE_LIST_URL)
 def post(self):
     the_post = Post()
     OHHOLog.print_log(self.request.body)
     permission = OHHOPermission()
     submit = the_post.get_submit(self)
     group_id = int(the_post.get_group_id(self))
     page_id = int(the_post.get_page_id(self))
     insert = int(the_post.get_insert(self))
     delete = int(the_post.get_delete(self))
     update = int(the_post.get_update(self))
     select = int(the_post.get_select(self))
     if submit:
         if page_id:
             data = dict()
             data["page_id"] = page_id
             data["insert"] = insert if insert else 0
             data["delete"] = delete if delete else 0
             data["update"] = update if update else 0
             data["select"] = select if select else 0
             message = permission.add_group_and_page(data, group_id)
         else:
             message = "请选择有效页面"
     else:
         message = "未提交"
     return self.redirect(PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_ADD_URL +
                          "?id=" + str(group_id) + "&data=" + message)
    def post(self):
        the_post = Post()
        name = the_post.get_name(self)
        description = the_post.get_description(self)
        data = dict()
        instance = OHHOPermission().group

        if name:
            data["name"] = name
            if description:
                data["description"] = description
            success = instance.add(data)
            if success:
                return self.redirect(PERMISSION_GROUP_BACKSTAGE_LIST_URL)

        return self.redirect(PERMISSION_GROUP_BACKSTAGE_ADD_URL)
    def post(self):
        the_post = Post()
        OHHOLog.print_log(self.request.body)
        permission = OHHOPermission()
        submit = the_post.get_submit(self)
        group_id = the_post.get_group_id(self)
        page_name = the_post.get_page_name(self)
        page_permission_id = int(the_post.get_page_permission_id(self))
        insert = int(the_post.get_insert(self))
        delete = int(the_post.get_delete(self))
        update = int(the_post.get_update(self))
        select = int(the_post.get_select(self))
        if submit:
            if page_permission_id:
                page_permission = permission.page_permission.get_by_id(page_permission_id)
                if page_permission:
                    success = permission.page_permission.delete(page_permission)

                    if success:
                        message = "删除成功"
                    else:
                        message = "删除失败"
                else:
                    message = "暂时还没有页面权限,请添加"
            else:
                message = "页面权限ID不合法"
        else:
            message = "未提交"
        return self.redirect(
            PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_DELETE_URL
            + "?data=%s&page_name=%s&group_id=%d" % (
                message, page_name,
                int(group_id)))
Exemple #6
0
 def get(self):
     the_get = Get()
     group_id = the_get.get_id(self)
     instance = OHHOPermission()
     if group_id:
         group_obj = instance.group.get_by_id(group_id)
     return self.render(PERMISSION_GROUP_BACKSTAGE_DELETE_HTML,
                        group_obj=group_obj,
                        delete_url=PERMISSION_GROUP_BACKSTAGE_DELETE_URL,
                        list_url=PERMISSION_GROUP_BACKSTAGE_LIST_URL)
Exemple #7
0
 def get(self):
     the_get = Get()
     page_id = the_get.get_id(self)
     instance = OHHOPermission()
     if page_id:
         page_obj = instance.page.get_by_id(page_id)
     return self.render(PERMISSION_PAGE_BACKSTAGE_DELETE_HTML,
                        page_obj=page_obj,
                        detail_url=PERMISSION_PAGE_BACKSTAGE_DETAIL_URL,
                        delete_url=PERMISSION_PAGE_BACKSTAGE_DELETE_URL,
                        list_url=PERMISSION_PAGE_BACKSTAGE_LIST_URL
                        )
    def get(self):
        the_get = Get()
        instance = OHHOPermission()
        group_id = the_get.get_id(self)
        message = the_get.get_data(self)
        group_name = ""
        if group_id:
            group_id = int(group_id)
            group = instance.group.get_by_id(group_id)
            if group:
                group_name = group.name

        all_page = instance.page.get_query()
        page_ids = [p.id for p in all_page] if all_page else []

        query_group_and_page = instance.group_and_page.get_query()
        query_group_and_page = instance.group_and_page.get_by_group_id(
            query_group_and_page, group_id)
        permission_ids = [p.page_permission_id for p in query_group_and_page
                          ] if query_group_and_page else []

        query_page_permission = instance.page_permission.get_query()
        query_page_permission = instance.page_permission.get_by_page_permission_ids(
            query_page_permission, permission_ids)
        permission_page_ids = [q.page_id for q in query_page_permission
                               ] if query_page_permission else []

        the_page_ids = OHHOOperation.list_minus_list(page_ids,
                                                     permission_page_ids)
        rest_page_list = list()
        for page_id in the_page_ids:
            page = instance.page.get_by_id(page_id)
            temp = dict()
            if page:
                temp["page_id"] = page.id
                temp["page_description"] = page.description
                temp["page_name"] = page.name
            if temp:
                rest_page_list.append(temp)

        return self.render(
            PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_ADD_HTML,
            group_id=group_id,
            rest_page_list=rest_page_list,
            group_name=group_name,
            home_list_url=MANAGEMENT_PERMISSION_HOME_URL,
            list_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_LIST_URL +
            "?id=" + str(group_id),
            detail_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_DETAIL_URL,
            add_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_ADD_URL + "?id=" +
            str(group_id),
            delete_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_DELETE_URL,
            message=message)
Exemple #9
0
 def post(self):
     the_post = Post()
     group_id = the_post.get_id(self)
     group_staffs_name = self.get_body_arguments("group_user")
     staffs_name = self.get_body_arguments("name")
     data = dict()
     instance = OHHOPermission().group_and_staff
     success = ""
     if group_id:
         if staffs_name:
             for staff_name in staffs_name:
                 group_name = instance.get_by_group_id_and_username(
                     group_id, staff_name)
                 if group_name:
                     success = instance.delete(group_name)
         if group_staffs_name:
             for staff_name in group_staffs_name:
                 group_name = instance.get_by_group_id_and_username(
                     group_id, staff_name)
                 if not group_name:
                     data["group_id"] = group_id
                     data["username"] = staff_name
                     success = instance.add(data)
     else:
         pass
     if success:
         return self.redirect(PERMISSION_GROUP_BACKSTAGE_LIST_URL)
     return self.redirect(PERMISSION_GROUP_STAFF_RELATION_ADD_URL +
                          "?group_id=" + group_id)
Exemple #10
0
    def post(self):
        the_post = Post()
        page_id = the_post.get_id(self)
        instance = OHHOPermission()
        page_obj = instance.page.get_by_id(page_id)
        delete_or_restore = the_post.get_delete_or_restore(self)
        success = False
        if delete_or_restore:
            success = instance.page.delete(page_obj)

        if success:
            return self.redirect(PERMISSION_PAGE_BACKSTAGE_LIST_URL)
        return self.redirect(PERMISSION_PAGE_BACKSTAGE_DETAIL_URL + "?id=" + str(page_id))
Exemple #11
0
    def post(self):
        the_post = Post()

        group_id = the_post.get_id(self)
        instance = OHHOPermission()
        group_obj = instance.group.get_by_id(group_id)
        delete_or_restore = the_post.get_delete_or_restore(self)
        success = False
        if delete_or_restore:
            success = instance.group.delete(group_obj)
        if success:
            return self.redirect(PERMISSION_GROUP_BACKSTAGE_LIST_URL)
        return self.redirect(PERMISSION_GROUP_BACKSTAGE_DELETE_URL + "?id=" +
                             str(group_id))
Exemple #12
0
    def post(self):
        the_post = Post()
        name = the_post.get_name(self)
        description = the_post.get_description(self)
        group_id = the_post.get_id(self)
        instance = OHHOPermission()
        group_obj = instance.group.get_by_id(group_id)
        submit = the_post.get_submit(self)
        success = False
        if submit:
            data = dict()
            data["name"] = name
            data["description"] = description
            success = instance.group.update(group_obj, data)

        if success:
            return self.redirect(PERMISSION_GROUP_BACKSTAGE_LIST_URL)
        return self.redirect(PERMISSION_GROUP_BACKSTAGE_DETAIL_URL + "?id=" +
                             str(group_id))
Exemple #13
0
    def get(self):
        the_get = Get()
        instance = OHHOPermission()
        name = the_get.get_name(self)
        if name is None:
            name = ""
        page = the_get.get_page(self)
        data_count_per_page = the_get.get_data_count_per_page(self)
        page_count_per_page = the_get.get_page_count_per_page(self)
        offset = (page - 1) * data_count_per_page
        limit = data_count_per_page

        query = instance.group.get_all()

        if name:
            query = instance.group.get_by_name(query, name)

        query, count = instance.group.get_some(query, offset, limit)
        total_page = int(ceil(count / data_count_per_page))
        pagination = Pagination(total_page, page, data_count_per_page,
                                page_count_per_page)
        page_list, previous, next = pagination.get_page_list_of_this_page()

        return self.render(
            PERMISSION_GROUP_BACKSTAGE_LIST_HTML,
            groups=query,
            pages=page_list,
            previous=previous,
            next=next,
            page=page,
            home_list_url=MANAGEMENT_PERMISSION_HOME_URL,
            list_url=PERMISSION_GROUP_BACKSTAGE_LIST_URL,
            detail_url=PERMISSION_GROUP_BACKSTAGE_DETAIL_URL,
            add_url=PERMISSION_GROUP_BACKSTAGE_ADD_URL,
            delete_url=PERMISSION_GROUP_BACKSTAGE_DELETE_URL,
            add_group_staff_relation_url=
            PERMISSION_GROUP_STAFF_RELATION_ADD_URL,
            group_page_relation_list_url=
            PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_LIST_URL,
            name=name,
        )
    def get(self):
        the_get = Get()
        permission = OHHOPermission()
        group_id = the_get.get_group_id(self)
        group = permission.group.get_by_id(group_id)
        group_name = group.name if group else ""
        page_name = the_get.get_page_name(self)
        page_permission_id = int(the_get.get_page_permission_id(self))
        insert = the_get.get_insert(self)
        insert = int(insert) if insert else 0
        delete = the_get.get_delete(self)
        delete = int(delete) if delete else 0
        update = the_get.get_update(self)
        update = int(update) if update else 0
        select = the_get.get_select(self)
        select = int(select) if select else 0
        message = the_get.get_data(self)

        return self.render(PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_DELETE_HTML,
                           page_name=page_name,
                           page_permission_id=page_permission_id,
                           insert=insert,
                           delete=delete,
                           update=update,
                           select=select,
                           group_id=group_id,
                           group_name=group_name,
                           home_list_url=MANAGEMENT_PERMISSION_HOME_URL,
                           list_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_LIST_URL + "?id=" + str(group_id),
                           detail_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_DETAIL_URL + "?page_permission_id=%d&data=%s&page_name=%s&insert=%d&delete=%d&update=%d&select=%d&group_id=%d" % (
                               int(page_permission_id), message, page_name, int(insert), int(delete), int(update),
                               int(select),
                               int(group_id)),
                           add_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_ADD_URL + "?group_id=" + str(group_id),
                           delete_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_DELETE_URL + "?page_permission_id=%d&data=%s&page_name=%s&insert=%d&delete=%d&update=%d&select=%d&group_id=%d" % (
                               int(page_permission_id), message, page_name, int(insert), int(delete), int(update),
                               int(select),
                               int(group_id)),
                           message=message
                           )
 def post(self):
     the_post = Post()
     OHHOLog.print_log(self.request.body)
     permission = OHHOPermission()
     submit = the_post.get_submit(self)
     group_id = the_post.get_group_id(self)
     page_name = the_post.get_page_name(self)
     page_permission_id = int(the_post.get_page_permission_id(self))
     insert = int(the_post.get_insert(self))
     delete = int(the_post.get_delete(self))
     update = int(the_post.get_update(self))
     select = int(the_post.get_select(self))
     if submit:
         if page_permission_id:
             page_permission = permission.page_permission.get_by_id(page_permission_id)
             if page_permission:
                 data = dict()
                 data["insert"] = insert if insert else 0
                 data["delete"] = delete if delete else 0
                 data["update"] = update if update else 0
                 data["select"] = select if select else 0
                 success = permission.page_permission.update(page_permission, data)
                 if success:
                     message = "更新成功"
                 else:
                     message = "更新失败"
             else:
                 message = "暂时还没有页面权限,请添加"
         else:
             message = "页面权限ID不合法"
     else:
         message = "未提交"
     return self.redirect(
         PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_DETAIL_URL
         + "?page_permission_id=%d&data=%s&page_name=%s&insert=%d&delete=%d&update=%d&select=%d&group_id=%d" % (
             int(page_permission_id), message, page_name, int(insert), int(delete), int(update), int(select),
             int(group_id)))
    def get(self):
        the_get = Get()
        instance = OHHOPermission()
        group_id = the_get.get_id(self)
        page = the_get.get_page(self)
        data_count_per_page = the_get.get_data_count_per_page(self)
        page_count_per_page = the_get.get_page_count_per_page(self)
        offset = (page - 1) * data_count_per_page
        limit = data_count_per_page

        query = instance.group_and_page.get_query()
        group_name = ""

        if group_id:
            query = instance.group_and_page.get_by_group_id(query, group_id)
            group = instance.group.get_by_id(group_id)
            if group:
                group_name = group.name

        query, count = instance.group_and_page.get_some(query, offset, limit)
        # query = query
        # count = instance.page_permission.get_count(query)
        total_page = int(ceil(count / data_count_per_page))
        pagination = Pagination(total_page, page, data_count_per_page,
                                page_count_per_page)
        page_list, previous, next = pagination.get_page_list_of_this_page()

        group_permissions = list()
        if query:
            for q in query:
                temp = dict()
                page_permission = instance.page_permission.get_by_id(
                    q.page_permission_id)
                if page_permission:
                    temp["group_id"] = group_id
                    temp["page_permission_id"] = q.page_permission_id
                    page = instance.page.get_by_id(page_permission.page_id)
                    if page:
                        temp["page_description"] = page.description
                        temp["page_name"] = page.name
                    temp["insert"] = page_permission.insert
                    temp["update"] = page_permission.update
                    temp["select"] = page_permission.select
                    temp["delete"] = page_permission.delete
                if temp:
                    group_permissions.append(temp)

        return self.render(
            PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_LIST_HTML,
            group_name=group_name,
            group_permissions=group_permissions,
            pages=page_list,
            previous=previous,
            next=next,
            page=page,
            home_list_url=MANAGEMENT_PERMISSION_HOME_URL,
            list_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_LIST_URL,
            detail_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_DETAIL_URL,
            add_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_ADD_URL + "?id=" +
            str(group_id),
            delete_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_DELETE_URL,
        )
Exemple #17
0
    def _permission(self):
        username = self.current_user
        if not username:
            return self.write(
                OHHOOperation.dict2json(Result.result_not_login()))
        else:
            class_name = self.__class__.__name__
            if class_name.endswith("AddHandler"):
                the_type = "AddHandler"
            elif class_name.endswith("ListHandler"):
                the_type = "ListHandler"
            elif class_name.endswith("DetailHandler"):
                the_type = "DetailHandler"
            elif class_name.endswith("DeleteHandler"):
                the_type = "DeleteHandler"
            else:
                the_type = ""

            if the_type:
                the_type_length = len(the_type)
                name = class_name[:-the_type_length]
                permission_instance = OHHOPermission()
                page = permission_instance.get_or_create_page_from_permission(
                    name)

                flag = True
                permission = permission_instance.get_the_page_permission_from_permission(
                    username, page)
                OHHOLog.print_log(username)
                OHHOLog.print_log(page.id)
                OHHOLog.print_log(permission)
                print(permission)
                if the_type == "AddHandler":
                    if permission["insert"]:
                        pass
                    else:
                        flag = False
                elif the_type == "ListHandler":
                    if permission["select"]:
                        pass
                    else:
                        flag = False
                elif the_type == "DetailHandler":
                    if permission["update"]:
                        pass
                    else:
                        flag = False
                elif the_type == "DeleteHandler":
                    if permission["delete"]:
                        pass
                    else:
                        flag = False
                else:
                    flag = False
                if not flag:
                    result = Result.result_no_permission()
                    return self.redirect("/backstage/no/permission/?code=" +
                                         str(result.get("code", 0)) +
                                         "&data=" +
                                         str(result.get("detail", "")))
                result = func(self)
                return result