Esempio n. 1
0
    def process(self):
        user_body = self.parameters.get('body')
        user_id = self.parameters.get('user_id')
        current_userdata = UserService.get_user(user_id)
        if current_userdata:
            if user_body.get('id'):
                return {
                           "code": 4012,
                           "message": returncode['4012']
                       }, 400
            logging.info("ModifyUserViewByID. UserService.modify_user_by_id:{}{}".format(user_id, user_body))
            if user_body.get('usergroup_id'):
                if current_userdata.usergroup_id != user_body.get('usergroup_id'):
                    old_usergroup_id = current_userdata.usergroup_id
                    new_usergroup_id = user_body.get('usergroup_id')
                    logging.info("UserID:{},need change usergroup_id from {} to {}".format(user_id, old_usergroup_id,
                                                                                           new_usergroup_id))
                    UserService.delete_assigned_pwd(user_id)
                    UserGroupService.decrease(old_usergroup_id)
                    UserService.assign_new_pwd(user_id, new_usergroup_id)
                    UserGroupService.increase(new_usergroup_id)

            UserService.modify_user_by_id(user_id, user_body)
            db.session.commit()
            return {
                "code": 200,
                "message": "modify user success"
            }

        else:
            return {
                       "code": 4011,
                       "message": returncode['4011']
                   }, 400
Esempio n. 2
0
    def process(self):
        user_body = self.parameters.get('body')
        user_id = user_body.get('user_id')
        thunderservice_id = user_body.get('thunderservice_id')
        service_start_date = user_body.get('service_start_date')
        service_end_date = user_body.get('service_end_date')
        update_data = {
            "membership": thunderservice_id,
            "membership_starttime": service_start_date,
            "membership_endtime": service_end_date
        }
        user_data = UserService.get_user(user_id)

        # same membership level, update period only
        if user_data.get('membership') == thunderservice_id:
            UserService.modify_user_by_id(user_id, update_data)
            db.session.commit()
            return {
                'result':
                "User already have same service, modify date only. success"
            }

        # change membership level, delete old pwd and assign a new one
        new_usergroup_id = self.choose_best_usergroup(thunderservice_id)
        print("new_usergroup_id:", new_usergroup_id)

        UserService.delete_assigned_pwd(user_id)
        UserGroupService.decrease(user_data.get('usergroup'))
        update_data = {
            "usergroup": new_usergroup_id,
            "membership": thunderservice_id,
            "membership_starttime": service_start_date,
            "membership_endtime": service_end_date
        }
        UserService.modify_user_by_id(user_id, update_data)

        UserService.assign_new_pwd(user_id, new_usergroup_id)
        UserGroupService.increase(new_usergroup_id)

        db.session.commit()
        return {'result': "Active thunderservice success"}