1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- from account.decorators import login_required
- from .models import Group
- from account.models import User, get_user
- from utils.debug import debug_view
- from utils.http import make_json_response
- from utils.crypto import secure_transport
- # Create your views here.
- @secure_transport
- # @debug_view('group_id')
- @login_required
- def get_group_root_folder(request):
- user = get_user(request)
- data = request.POST
- group_id = data.get('group_id')
- try:
- group = user.joined_groups.get(group_id=group_id)
- except:
- return make_json_response(code=403, error='群不存在')
- root_folder = group.get_root_folder()
- return make_json_response(root_folder_id=root_folder.folder_id)
- @secure_transport
- # @debug_view('group_id')
- @login_required
- def join_group(request):
- user = get_user(request)
- data = request.POST
- group_id = data.get('group_id')
- if user.joined_groups.filter(group_id=group_id).exists():
- return make_json_response(code=402, error='已在群内')
- try:
- group = Group.objects.get(group_id=group_id)
- except:
- return make_json_response(code=403, error='群不存在')
- group.members.add(user)
- group.save()
- return make_json_response()
- @secure_transport
- # @debug_view('group_name')
- @login_required
- def create_group(request):
- user = get_user(request)
- data = request.POST
- group_name = data.get('group_name')
- try:
- Group.objects.create(group_name=group_name, creator=user)
- except:
- return make_json_response(code=500, error='新建群失败')
- return make_json_response()
- @secure_transport
- # @debug_view('group_id')
- @login_required
- def quit_group(request):
- user = get_user(request)
- data = request.POST
- group_id = data.get('group_id')
- try:
- group = user.joined_groups.get(group_id=group_id)
- except:
- return make_json_response(code=403, error='群不存在')
- if group.creator == user:
- return make_json_response(code=421, error='群主不可退群')
- group.members.remove(user)
- group.save()
- return make_json_response()
- # 获取你所在的所有群组
- @secure_transport
- # @debug_view()
- @login_required
- def group_list(request):
- user = get_user(request)
- _list = list(map(lambda g: g.to_json(), user.joined_groups.all()))
- return make_json_response(group_list=_list)
- # 删除群组
|