Beispiel #1
0
    async def change_nickname(self):
        u = self.current_user
        if not u:
            return self.finish(RETCODE.PERMISSION_DENIED)

        post = await self.post_data()
        form = NicknameForm(**post)
        if not form.validate():
            return self.finish(RETCODE.INVALID_POSTDATA, form.errors)

        if u.change_nickname_chance > 0:
            try:
                old_nickname = u.nickname
                u.nickname = form['nickname'].data
                u.change_nickname_chance -= 1
                u.is_new_user = False
                u.save()
                self.finish(
                    RETCODE.SUCCESS, {
                        'nickname': u.nickname,
                        'change_nickname_chance': u.change_nickname_chance
                    })
                # note: 虽然有点奇怪,但下面这句其实没问题 18.11.13
                ManageLog.add_by_post_changed(self, 'nickname',
                                              MOP.USER_NICKNAME_CHANGE,
                                              POST_TYPES.USER, True,
                                              {'nickname': old_nickname}, u)
                return
            except peewee.DatabaseError:
                db.rollback()

        self.finish(RETCODE.FAILED)
Beispiel #2
0
    def after_update(self, raw_post: Dict, values: SQLValuesToWrite,
                     old_records: List[DataRecord], records: List[DataRecord]):
        for old_record, record in zip(old_records, records):
            manage_try_add = lambda column, op: ManageLog.add_by_post_changed(
                self, column, op, POST_TYPES.WIKI, values, old_record, record)
            manage_try_add_with_diff = lambda column, op: ManageLog.add_by_post_changed(
                self,
                column,
                op,
                POST_TYPES.WIKI,
                values,
                old_record,
                record,
                diff_func=diff)

            title_changed = manage_try_add('title',
                                           MOP.POST_TITLE_CHANGE)  # 管理日志:标题编辑
            content_changed = manage_try_add_with_diff(
                'content', MOP.POST_CONTENT_CHANGE)  # 管理日志:正文编辑

            if title_changed or content_changed:
                post_stats_do_edit(record['id'], record['user_id'])

            manage_try_add('ref', MOP.WIKI_REF_CHANGE)  # 管理日志:链接编辑
            manage_try_add('state', MOP.POST_STATE_CHANGE)  # 管理日志:改变状态
            manage_try_add('visible', MOP.POST_VISIBLE_CHANGE)  # 管理日志:改变可见度

            if config.SEARCH_ENABLE:
                run_in_thread(esdb.es_update_wiki, record['id'])
Beispiel #3
0
 def after_update(self, raw_post: Dict, values: SQLValuesToWrite,
                  old_records: List[DataRecord], records: List[DataRecord]):
     for old_record, record in zip(old_records, records):
         # 管理日志:修改评论状态
         ManageLog.add_by_post_changed(self, 'state', MOP.POST_STATE_CHANGE,
                                       POST_TYPES.COMMENT, values,
                                       old_record, record)
Beispiel #4
0
    async def change_nickname(self):
        u: User = self.current_user
        if not u:
            return self.finish(RETCODE.PERMISSION_DENIED)

        vpost: ChangeNicknameDataModel = self._.validated_post

        if u.change_nickname_chance > 0:
            try:
                old_nickname = u.nickname
                u.nickname = vpost.nickname
                u.change_nickname_chance -= 1
                u.is_new_user = False
                u.save()
                self.finish(
                    RETCODE.SUCCESS, {
                        'nickname': u.nickname,
                        'change_nickname_chance': u.change_nickname_chance
                    })
                # note: 虽然有点奇怪,但下面这句其实没问题 18.11.13
                ManageLog.add_by_post_changed(self, 'nickname',
                                              MOP.USER_NICKNAME_CHANGE,
                                              POST_TYPES.USER, True,
                                              {'nickname': old_nickname}, u)
                return
            except peewee.DatabaseError:
                db.rollback()

        self.finish(RETCODE.FAILED)
Beispiel #5
0
    def after_update(self, raw_post: Dict, values: SQLValuesToWrite, old_records: List[DataRecord], records: List[DataRecord]):
        for old_record, record in zip(old_records, records):
            manage_try_add = lambda column, op: ManageLog.add_by_post_changed(
                self, column, op, POST_TYPES.USER, values, old_record, record
            )

            # 管理日志:重置访问令牌
            ManageLog.add_by_post_changed(self, 'key', MOP.USER_KEY_RESET, POST_TYPES.USER,
                                          values, old_record, record, value=None)

            # 管理日志:重置密码
            ManageLog.add_by_post_changed(self, 'password', MOP.USER_PASSWORD_CHANGE, POST_TYPES.USER,
                                          values, old_record, record, value=None)

            manage_try_add('state', MOP.POST_STATE_CHANGE)
            manage_try_add('visible', MOP.POST_VISIBLE_CHANGE)

            manage_try_add('group', MOP.USER_GROUP_CHANGE)
            manage_try_add('exp', MOP.USER_EXP_CHANGE)

            def manage_try_add_resource(column, op):
                if column not in values: return
                uid = self.current_user.id
                src = json.loads(raw_post['$src'])
                # TODO: 检查一下是否真的存在

                def func(info):
                    info['related_type'] = src['type']
                    info['related_id'] = to_bin(src['id'])
                    info['related_user_id'] = uid

                ManageLog.add_by_post_changed(self, column, op, POST_TYPES.USER, values, old_record, record, cb=func)

            manage_try_add_resource('credit', MOP.USER_CREDIT_CHANGE)
            manage_try_add_resource('repute', MOP.USER_REPUTE_CHANGE)
Beispiel #6
0
    def after_update(self, raw_post: Dict, values: SQLValuesToWrite, old_records: List[DataRecord], records: List[DataRecord]):
        for old_record, record in zip(old_records, records):
            manage_try_add = lambda column, op: ManageLog.add_by_post_changed(
                self, column, op, POST_TYPES.TOPIC, values, old_record, record
            )
            manage_try_add_with_diff = lambda column, op: ManageLog.add_by_post_changed(
                self, column, op, POST_TYPES.TOPIC, values, old_record, record, diff_func=diff
            )

            title_changed = manage_try_add('title', MOP.POST_TITLE_CHANGE)  # 管理日志:标题编辑
            content_changed = manage_try_add_with_diff('content', MOP.POST_CONTENT_CHANGE)  # 管理日志:正文编辑

            if title_changed or content_changed:
                post_stats_do_edit(record['id'], record['user_id'])
                Topic.update(edit_count=Topic.edit_count + 1).where(Topic.id == record['id']).execute()

            manage_try_add('state', MOP.POST_STATE_CHANGE)  # 管理日志:状态修改
            manage_try_add('visible', MOP.POST_VISIBLE_CHANGE)  # 管理日志:改变可见度
            manage_try_add('awesome', MOP.TOPIC_AWESOME_CHANGE)  # 管理日志:设置精华
            manage_try_add('sticky_weight', MOP.TOPIC_STICKY_WEIGHT_CHANGE)  # 管理日志:置顶权重
            manage_try_add('weight', MOP.TOPIC_WEIGHT_CHANGE)  # 管理日志:修改权重

            # 管理日志:移动板块
            if manage_try_add('board_id', MOP.TOPIC_BOARD_MOVE):
                post_stats_topic_move(old_record['board_id'], record['board_id'], record['id'])
Beispiel #7
0
    def after_update(self, raw_post: Dict, values: SQLValuesToWrite,
                     old_records: List[DataRecord], records: List[DataRecord]):
        for old_record, record in zip(old_records, records):
            # 管理日志:修改评论状态
            ManageLog.add_by_post_changed(self, 'state', MOP.POST_STATE_CHANGE,
                                          POST_TYPES.COMMENT, values,
                                          old_record, record)

            if config.SEARCH_ENABLE:
                run_in_thread(esdb.es_update_comment, record['id'])
Beispiel #8
0
            def manage_try_add_resource(column, op):
                if column not in values: return
                uid = self.current_user.id
                src = json.loads(raw_post['$src'])
                # TODO: 检查一下是否真的存在

                def func(info):
                    info['related_type'] = src['type']
                    info['related_id'] = to_bin(src['id'])
                    info['related_user_id'] = uid

                ManageLog.add_by_post_changed(self, column, op, POST_TYPES.USER, values, old_record, record, cb=func)