def group_toggle_modules(request, group): """Enable or disable modules. """ if request.method != "POST": raise Http404 referer = request.META.get("HTTP_REFERER", None) next = SITE_ROOT if referer is None else referer username = request.user.username group_wiki = request.POST.get("group_wiki", "off") if group_wiki == "on": enable_mod_for_group(group.id, MOD_GROUP_WIKI) messages.success(request, _('Successfully enable "Wiki".')) else: disable_mod_for_group(group.id, MOD_GROUP_WIKI) if referer.find("wiki") > 0: next = reverse("group_info", args=[group.id]) messages.success(request, _('Successfully disable "Wiki".')) return HttpResponseRedirect(next)
def group_toggle_modules(request, group): """Enable or disable modules. """ if request.method != 'POST': raise Http404 referer = request.META.get('HTTP_REFERER', None) next = SITE_ROOT if referer is None else referer username = request.user.username group_wiki = request.POST.get('group_wiki', 'off') if group_wiki == 'on': enable_mod_for_group(group.id, MOD_GROUP_WIKI) messages.success(request, _('Successfully enable "Wiki".')) else: disable_mod_for_group(group.id, MOD_GROUP_WIKI) if referer.find('wiki') > 0: next = reverse('group_info', args=[group.id]) messages.success(request, _('Successfully disable "Wiki".')) return HttpResponseRedirect(next)
def put(self, request, group_id): """ Rename, transfer a specific group """ username = request.user.username new_group_name = request.data.get('name', None) # rename a group if new_group_name: try: # only group owner/admin can rename a group if not is_group_admin_or_owner(group_id, username): error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) # Check whether group name is validate. if not validate_group_name(new_group_name): error_msg = _(u'Group name can only contain letters, numbers, blank, hyphen or underscore') return api_error(status.HTTP_400_BAD_REQUEST, error_msg) # Check whether group name is duplicated. if check_group_name_conflict(request, new_group_name): error_msg = _(u'There is already a group with that name.') return api_error(status.HTTP_400_BAD_REQUEST, error_msg) seaserv.ccnet_threaded_rpc.set_group_name(group_id, new_group_name) except SearpcError as e: logger.error(e) error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) new_owner = request.data.get('owner', None) # transfer a group if new_owner: try: # only group owner can transfer a group if not is_group_owner(group_id, username): error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) # augument check if not is_valid_username(new_owner): error_msg = 'Email %s invalid.' % new_owner return api_error(status.HTTP_400_BAD_REQUEST, error_msg) if is_group_owner(group_id, new_owner): error_msg = _(u'User %s is already group owner.') % new_owner return api_error(status.HTTP_400_BAD_REQUEST, error_msg) # transfer a group if not is_group_member(group_id, new_owner): ccnet_api.group_add_member(group_id, username, new_owner) if not is_group_admin(group_id, new_owner): ccnet_api.group_set_admin(group_id, new_owner) ccnet_api.set_group_creator(group_id, new_owner) ccnet_api.group_unset_admin(group_id, username) except SearpcError as e: logger.error(e) error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) wiki_enabled = request.data.get('wiki_enabled', None) # turn on/off group wiki if wiki_enabled: try: # only group owner/admin can turn on a group wiki if not is_group_admin_or_owner(group_id, username): error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) # augument check if wiki_enabled != 'true' and wiki_enabled != 'false': error_msg = 'wiki_enabled invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) # turn on/off group wiki if wiki_enabled == 'true': enable_mod_for_group(group_id, MOD_GROUP_WIKI) else: disable_mod_for_group(group_id, MOD_GROUP_WIKI) except SearpcError as e: logger.error(e) error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) group_info = get_group_info(request, group_id) return Response(group_info)