예제 #1
0
    def handler(self):
        session_mark = False

        try:
            self.session_auth = DB_SESSION_AUTH

            if self.verify():
                self.obj_strategy.strategyType = self.para["strategyType"]
                self.obj_strategy.strategyName = self.para["strategyName"]
                self.obj_strategy.strategyRemark = self.para["strategyRemark"]
                self.obj_strategy.strategyRule = json.dumps(
                    self.para["strategyRule"]).encode("utf-8")

                self.res["data"]["strategyDetail"] = self.obj_strategy.to_json(
                )

            self.session_auth.commit()

        except Exception, e:
            if session_mark is True:
                self.session_auth.rollback()

            traceback_str = traceback.format_exc()
            fill_error_code(self.res, "sql_error", traceback_str)

            if self.logger:
                self.logger.error(traceback_str)
예제 #2
0
    def verify(self):
        if "ownerUin" not in self.para:
            fill_error_code(self.res, "para_miss", "miss parameter(ownerUin)")
            return False
        else:
            self.para["ownerUin"] = int(self.para["ownerUin"])

        return True
예제 #3
0
def valid_strategy_info(para, res, logger):
    for k in [
            "strategyType", "strategyName", "strategyRemark", "strategyRule"
    ]:
        if k not in para:
            fill_error_code(res, "para_miss", "miss parameter(%s)" % (k))
            return False

    para["strategyType"] = int(para["strategyType"])
    para["strategyName"] = deal_post_str(para["strategyName"])
    para["strategyRemark"] = deal_post_str(para["strategyRemark"])

    if para["strategyType"] != MODE_STRATEGY_TYPE_COMMON and para[
            "strategyType"] != MODE_STRATEGY_TYPE_OWNER and para[
                "strategyType"] != MODE_STRATEGY_TYPE_SUB:
        fill_error_code(res, "mode_strategy_type")
        return False

    if len(para["strategyName"]) == 0:
        fill_error_code(res, "empty_strategy_name")
        return False

    if not valid_strategy_rule(para["strategyRule"], logger):
        fill_error_code(res, "invalid_strategy_rule")
        return False

    return True
예제 #4
0
    def verify(self):
        if "ownerUin" not in self.para:
            fill_error_code(self.res, "para_miss", "miss parameter(ownerUin)")
            return False

        if "strategyId" not in self.para:
            fill_error_code(self.res, "para_miss",
                            "miss parameter(strategyId)")
            return False

        ownerUin = int(self.para["ownerUin"])
        strategyId = int(self.para["strategyId"])

        self.obj_strategy = self.session_auth.query(
            TableGrantStrategyInfo).filter(
                TableGrantStrategyInfo.strategyId == strategyId).first()

        if self.obj_strategy is None:
            fill_error_code(self.res, "invalid_strategy_id")
            return False

        if self.obj_strategy.ownerUin != ownerUin:
            fill_error_code(self.res, "permission_strategy")
            return False

        return True
예제 #5
0
    def handler(self):
        session_mark = False

        try:
            self.session_auth = DB_SESSION_AUTH

            if self.verify():
                self.query_strategy()

            self.session_auth.commit()

        except Exception, e:
            if session_mark is True:
                self.session_auth.rollback()

            traceback_str = traceback.format_exc()
            fill_error_code(self.res, "sql_error", traceback_str)

            if self.logger:
                self.logger.error(traceback_str)
예제 #6
0
    def verify(self):
        if "ownerUin" not in self.para:
            fill_error_code(self.res, "para_miss", "miss parameter(ownerUin)")
            return False

        self.para["ownerUin"] = int(self.para["ownerUin"])

        if self.session_auth.query(TableGrantUser).filter(
                TableGrantUser.userUin ==
                self.para["ownerUin"]).first() is None:
            fill_error_code(self.res, "invalid_owner_uin")
            return False

        self.para["strategyIdList"] = list(self.para["strategyIdList"])

        n = len(self.para["strategyIdList"])
        i = 0
        while i < n:
            self.para["strategyIdList"][i] = int(
                self.para["strategyIdList"][i])
            i += 1

        return True
예제 #7
0
    def handler(self):
        session_mark = False

        try:
            self.session_auth = DB_SESSION_AUTH

            if self.verify():
                self.res["data"]["batchRes"] = []

                for strategyId in self.para["strategyIdList"]:
                    self.res["data"]["batchRes"].append(
                        self.deleteStrategy(strategyId))

            self.session_auth.commit()

        except Exception, e:
            if session_mark is True:
                self.session_auth.rollback()

            traceback_str = traceback.format_exc()
            fill_error_code(self.res, "sql_error", traceback_str)

            if self.logger:
                self.logger.error(traceback_str)
예제 #8
0
    def verify(self):
        # check ownerUin
        if "ownerUin" not in self.para:
            fill_error_code(self.res, "para_miss", "miss parameter(ownerUin)")
            return False

        self.para["ownerUin"] = int(self.para["ownerUin"])

        if self.session_auth.query(TableGrantUser).filter(
                TableGrantUser.userUin ==
                self.para["ownerUin"]).first() is None:
            fill_error_code(self.res, "invalid_owner_uin")
            return False

        # check strategyId
        if "strategyId" not in self.para:
            fill_error_code(self.res, "para_miss",
                            "miss parameter(strategyId)")
            return False

        self.para["strategyId"] = int(self.para["strategyId"])

        self.obj_strategy = self.session_auth.query(
            TableGrantStrategyInfo).filter(TableGrantStrategyInfo.strategyId ==
                                           self.para["strategyId"]).first()

        if self.obj_strategy is None:
            fill_error_code(self.res, "invalid_strategy_id")
            return False

        if self.obj_strategy.ownerUin != self.para["ownerUin"]:
            fill_error_code(self.res, "permission_strategy")
            return False

        # check strategy info
        return valid_strategy_info(self.para, self.res, self.logger)
예제 #9
0
    def verify(self):
        if "ownerUin" not in self.para:
            fill_error_code(self.res, "para_miss", "miss parameter(ownerUin)")
            return False

        self.para["ownerUin"] = int(self.para["ownerUin"])

        if self.session_auth.query(TableGrantUser).filter(
                TableGrantUser.userUin ==
                self.para["ownerUin"]).first() is None:
            fill_error_code(self.res, "invalid_owner_uin")
            return False

        if "bindMode" not in self.para:
            fill_error_code(self.res, "para_miss", "miss parameter(bindMode)")
            return False

        self.para["bindMode"] = int(self.para["bindMode"])

        if self.para["bindMode"] != MODE_STRATEGY_BIND and self.para[
                "bindMode"] != MODE_STRATEGY_UNBIND:
            fill_error_code(self.res, "mode_related_bind")
            return False

        self.para["bindList"] = list(self.para["bindList"])

        n = len(self.para["bindList"])
        i = 0
        while i < n:
            self.para["bindList"][i]["strategyId"] = int(
                self.para["bindList"][i]["strategyId"])
            self.para["bindList"][i]["userUin"] = int(
                self.para["bindList"][i]["userUin"])
            i += 1

        f = lambda x, y: x if y in x else x + [y]
        self.para["bindList"] = reduce(f, [
            [],
        ] + self.para["bindList"])

        return True
예제 #10
0
    def handler(self):
        # 1. if miss uin
        if "ownerUin" not in self.para:
            fill_error_code(self.res, "para_miss", "miss parameter(ownerUin)")
            return

        self.para["ownerUin"] = int(self.para["ownerUin"])

        # 2. if invalid strategy info
        if not valid_strategy_info(self.para, self.res, self.logger):
            return

        # 3. logic work
        session_mark = False

        try:
            session_auth = DB_SESSION_AUTH

            if session_auth.query(TableGrantUser).filter(
                    TableGrantUser.userUin ==
                    self.para["ownerUin"]).first() is None:
                fill_error_code(self.res, "invalid_owner_uin")

            else:
                obj_strategy = TableGrantStrategyInfo(
                    self.para["ownerUin"], self.para["strategyType"],
                    self.para["strategyName"], self.para["strategyRemark"],
                    json.dumps(self.para["strategyRule"]).encode("utf-8"))
                session_auth.add(obj_strategy)
                session_auth.flush()
                self.res["data"]["strategyDetail"] = obj_strategy.to_json()

            session_auth.commit()

        except Exception, e:
            if session_mark is True:
                session_auth.rollback()

            traceback_str = traceback.format_exc()
            fill_error_code(self.res, "sql_error", traceback_str)

            if self.logger:
                self.logger.error(traceback_str)
예제 #11
0
 def handler(self):
     fill_error_code(self.res, "invalid_method")