Esempio n. 1
0
def register_new_actor(request, session, ro, new_uid):
    """Register a new user according to info in form

    Args:
        request: (Request)
        session: (DBSession)
        ro: (ResearchObject)
        new_uid: (str) id of user to add to ro auth

    Returns:
        (bool): whether ro has changed and need to be reloaded
    """
    role = Role.from_str(request.params.get("role_new", "denied"))

    actor = Actor.get(session, new_uid)
    if actor is not None:
        if new_uid in (pol.actor for pol in ro.auth):
            msg = "%s already a direct member" % actor.id
            request.session.flash(msg, 'warning')
            return False

        ro.add_policy(session, actor, role)
        request.session.flash("New actor %s added" % actor.id, 'success')
        return True

    request.session.flash("Actor %s does not exists" % new_uid, 'warning')
    return False
Esempio n. 2
0
def view(request):
    session = DBSession()
    uid = request.matchdict['uid']
    actor = Actor.get(session, uid)

    if actor is not None:
        if actor.type == "user":
            return HTTPFound(location=request.route_url('user_view_home', uid=uid))
        elif actor.type == "team":
            return HTTPFound(location=request.route_url('team_view_home', uid=uid))
        else:
            request.session.flash("Unknown actor type: %s" % actor.type, 'warning')
            raise HTTPFound(location=request.route_url('home'))

    request.session.flash("Actor %s does not exists" % uid, 'warning')
    raise HTTPFound(location=request.route_url('home'))