<commit_before>from req import ApiRequestHandler
from req import Service
import tornado
from map import *

class ApiGroupHandler(ApiRequestHandler):
    def check_edit(self, meta={}):
        if meta['id'] == 0 and map_power['group_manage'] in self.account['power']:
            return True
        if map_group_power['group_manage'] not in self.current_group_power:
            self.render(403, 'Permission Denied')
            return False
        return True

    @tornado.gen.coroutine
    def get(self):
        meta = {}
        meta['id'] = self.current_group
        err, data = yield from Service.Group.get_group(meta)
        if err: self.render(500, err)
        else: self.render(200, data)

    @tornado.gen.coroutine
    def post(self):
        args = ['name', 'description']
        meta = self.get_args(args)
        meta['id'] = self.current_group
        if not self.check_edit(meta):
            self.render(403)
            return
        err, data = yield from Service.Group.post_group(meta)
        if err: self.render(500, err)
        else:
            meta = {}
            meta['group_id'] = data
            meta['user_id'] = self.account['id']
            print(meta)
            self.render(200, {"id": data})
            err, res = yield from Service.Group.post_group_user(meta)
            for i in range(1, 6):
                try: yield from Service.User.post_user_group_power(self.account['id'], data, i)
                except: pass

    @tornado.gen.coroutine
    def delete(self):
        meta = {}
        meta['id'] = self.current_group
        print('META', meta)
        if not self.check_edit(meta):
            print('ERROR')
            return
        err, res = yield from Service.Group.delete_group(meta)
        print('err', err, res)
        if err: self.render(500, err)
        else: self.render(200, res)

class ApiGroupUserHandler(ApiRequestHandler):
    def check_edit(self, meta={}):
        if map_group_power['group_manage'] not in self.current_group_power:
            self.render(403, 'Permission Denied')
            return False
        return True
    @tornado.gen.coroutine
    def get(self, user_id):
        meta = {}
        meta['group_id'] = self.current_group
        meta['user_id'] = user_id
        err, data = yield from Service.User.get_user_group_power_info(self.current_group, user_id)
        if err: self.render(500, err)
        else: self.render(200, data)

    @tornado.gen.coroutine
    def post(self, user_id):
        args = ['power']
        meta = self.get_args(args)
        meta['user_id'] = user_id
        meta['group_id'] = self.current_group
        if not self.check_edit():
            self.render(403)
            return
        if meta['power'] is None:
            err, res = yield from Service.Group.post_group_user(meta)
            if err: self.render(500, err)
            else: self.render(200, res)
        else:
            err, res = yield from Service.User.post_user_group_power(meta)
            if err: self.render(500, err)
            else: self.render(200, res)
    @tornado.gen.coroutine
    def delete(self, user_id):
        meta = {}
        meta['group_id'] = self.current_group
        meta['user_id'] = user_id
        err, res = yield from Service.Group.delete_group_user(meta)
        if err: self.render(500, err)
        else: self.render(200, res)
<commit_msg>fixed post_group bug<commit_after>from req import ApiRequestHandler
from req import Service
import tornado
from map import *

class ApiGroupHandler(ApiRequestHandler):
    def check_edit(self, meta={}):
        if meta['id'] == 0 and map_power['group_manage'] in self.account['power']:
            return True
        print(self.current_group_power)
        if map_group_power['group_manage'] not in self.current_group_power:
            self.render(403, 'Permission Denied')
            return False
        return True

    @tornado.gen.coroutine
    def get(self):
        meta = {}
        meta['id'] = self.current_group
        err, data = yield from Service.Group.get_group(meta)
        if err: self.render(500, err)
        else: self.render(200, data)

    @tornado.gen.coroutine
    def post(self):
        args = ['name', 'description']
        meta = self.get_args(args)
        meta['id'] = self.current_group
        if not self.check_edit(meta):
            self.render(403)
            return
        err, data = yield from Service.Group.post_group(meta)
        if err: self.render(500, err)
        else:
            meta = {}
            meta['group_id'] = data
            meta['user_id'] = self.account['id']
            print(meta)
            self.render(200, {"id": data})
            err, res = yield from Service.Group.post_group_user(meta)
            for i in range(1, 6):
                meta['power'] = i
                try: yield from Service.User.post_user_group_power(meta)
                except Exception as e: print(e)

    @tornado.gen.coroutine
    def delete(self):
        meta = {}
        meta['id'] = self.current_group
        print('META', meta)
        if not self.check_edit(meta):
            print('ERROR')
            return
        err, res = yield from Service.Group.delete_group(meta)
        print('err', err, res)
        if err: self.render(500, err)
        else: self.render(200, res)

class ApiGroupUserHandler(ApiRequestHandler):
    def check_edit(self, meta={}):
        if map_group_power['group_manage'] not in self.current_group_power:
            self.render(403, 'Permission Denied')
            return False
        return True
    @tornado.gen.coroutine
    def get(self, user_id):
        meta = {}
        meta['group_id'] = self.current_group
        meta['user_id'] = user_id
        err, data = yield from Service.User.get_user_group_power_info(self.current_group, user_id)
        if err: self.render(500, err)
        else: self.render(200, data)

    @tornado.gen.coroutine
    def post(self, user_id):
        args = ['power']
        meta = self.get_args(args)
        meta['user_id'] = user_id
        meta['group_id'] = self.current_group
        if not self.check_edit():
            self.render(403)
            return
        if meta['power'] is None:
            err, res = yield from Service.Group.post_group_user(meta)
            if err: self.render(500, err)
            else: self.render(200, res)
        else:
            err, res = yield from Service.User.post_user_group_power(meta)
            if err: self.render(500, err)
            else: self.render(200, res)
    @tornado.gen.coroutine
    def delete(self, user_id):
        meta = {}
        meta['group_id'] = self.current_group
        meta['user_id'] = user_id
        err, res = yield from Service.Group.delete_group_user(meta)
        if err: self.render(500, err)
        else: self.render(200, res)

{'fraction_non_alphanumeric': 0.11387224090045316, 'fraction_numerical': 0.016664230375676072, 'mean_word_length': 2.129917657822507, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5731552', 'n_tokens_mistral': 2152, 'n_tokens_neox': 2072, 'n_words': 492}