Esempio n. 1
0
def execute(pagename, request):
    request.content_type = "application/json"

    if request.environ['REQUEST_METHOD'] == "GET":
        groups = {}
        for group in request.groups:
            if request.user.may.read(group):
                members = request.groups[group].members
                grps = request.groups[group].member_groups
                groups[group] = dict(members=members, groups=grps)

        json.dump(groups, request, cls=SetEncoder)
        return

    elif request.environ['REQUEST_METHOD'] == 'POST':
        try:
            indata = request.read()
            if not indata:
                raise ValueError("No data")

            indata = json.loads(indata)

            for row in indata:
                op = row.get('op', None)
                group = row.get('group', None)
                name = row.get('name', None)

                if op == "rename":
                    group_rename(request, group, [name, row.get('to')])
                elif op == "del":
                    group_del(request, group, [name])
                elif op == "add":
                    if isGroupPage(name, request.cfg):
                        group_add(request, group, [name], row.get('create', False), False)
                    else:
                        group_add(request, group, [name], row.get('create', False))
                elif op == "invite":
                    invite_user_to_wiki(request, group, name)
                else:
                    raise ValueError("Bad operation")

        except (GroupException, ValueError) as e:
            request.status_code = 400
            request.write(e.message)

        except NotImplementedError as e:
            request.status_code = 501
            request.write(e.message)

        except Exception as e:
            request.status_code = 500
            request.write(e.message)


    else:
        #405 Method Not Allowed
        request.status_code = 405

    return
Esempio n. 2
0
def add_user_to_group(request, userobj, group, comment=""):
    success, msg = group_add(request, group, [userobj.name], create=True)

    logging.info(
        "%s added to group %s in wiki %s (invited by %s)"
        % (userobj.name, group, request.cfg.interwikiname, request.user.name)
    )
Esempio n. 3
0
def add_user_to_group(request, userobj, group, comment=""):
    success, msg = group_add(request, group, [userobj.name], create=True)

    logging.info(
        "%s added to group %s in wiki %s (invited by %s)" %
        (userobj.name, group, request.cfg.interwikiname, request.user.name))