def modify_group_post(request): check = check_request(request, need_login=True, is_post=True) if not check.ok: return http_str(check.info) post_info = {} for i, j in request.POST.items(): post_info[i] = j if 'name' not in post_info: return http_str(ErrorInfo.Group.name_needed) group_name = post_info['name'] if not database_check_user_is_boss(group_name, request.user.username): return http_str(ErrorInfo.Permission.no_permission) if 'public' in post_info: post_info['public'] = True if post_info['public'] == 'true' else False operation_result = database_modify_group(group_name, **post_info) if not operation_result.ok: return http_str(ErrorInfo.Group.group_not_exists) return http_str(SuccessInfo.success)
def kick_user_post(request): check = check_request(request, need_login=True, is_post=True) if not check.ok: return http_str(check.info) post_info = {} for i, j in request.POST.items(): post_info[i] = j if 'name' not in post_info: return http_str(ErrorInfo.Group.name_needed) group_name = post_info['name'] if 'username' not in post_info: return http_str(ErrorInfo.User.username_required) username = post_info['username'] print(group_name, username) if not database_check_user_can_manage(group_name, request.user.username): return http_str(ErrorInfo.Permission.no_permission) if is_himself(request, username): return http_str(ErrorInfo.Group.cannot_kick_yourself) if database_check_user_can_manage( group_name, username) and database_check_user_is_boss( group_name, username): return http_str(ErrorInfo.Group.cannot_kick_manager) ret = database_leave_group(group_name, username) if not ret.ok: return http_str(ErrorInfo.Group.user_is_boss) return http_str(SuccessInfo.success)
def group_info(request, group_name): info = database_get_group(group_name) members_formal = database_get_group_user(group_name, formal=True) members_applicant = database_get_group_user(group_name, formal=False) applicants = database_get_group_user(group_name, formal=False) if info is None: return render(request, 'html/404.html', {'user_status': user_status(request)}) is_applicant = False in_group = False can_manage = False is_boss = False if has_login(request): if database_check_user_is_applicant(group_name, request.user.username): is_applicant = True if database_check_user_in_group(group_name, request.user.username): in_group = True if database_check_user_can_manage(group_name, request.user.username): can_manage = True if database_check_user_is_boss(group_name, request.user.username): is_boss = True return render(request, 'html/group_info.html', { 'user_status': user_status(request), 'group_info': info, 'members_formal': members_formal, 'members_applicant': members_applicant, 'is_applicant': is_applicant, 'in_group': in_group, 'can_manage': can_manage, 'is_boss': is_boss })
def edit_group(request, group_name): if not database_check_user_is_boss(group_name, request.user.username): return render(request, 'html/404.html', {'user_status': user_status(request)}) group = database_get_group(group_name) return render(request, 'html/group/edit_group.html', { 'user_status': user_status(request), 'group_info': group })