Exemple #1
0
def view(request):
    session = DBSession()
    user, view_params = edit_init(request, session, 'home')

    if 'update' in request.params:
        if 'description' in request.params:
            user.store_description(request.params['description'])
    elif 'submit_avatar' in request.params:
        field_storage = request.params['avatar']
        if field_storage == "":
            request.session.flash("Select an image first", 'warning')
        else:
            try:
                img = load_image(field_storage)
                upload_user_avatar(img, user)
                request.session.flash("Avatar submitted", 'success')
                loc = request.route_url('user_view_home', uid=user.id)
                return HTTPFound(location=loc)
            except IOError:
                request.session.flash("Unable to read image", 'warning')
    else:
        pass

    return view_params
def main(session, user, container):
    """Create ROs to test auth policies.

    Args:
        session (DBSession):
        user (User): default user
        container (ROContainer): top level container

    Returns:
        None
    """
    # create another user
    other = User.create(session,
                        uid='other',
                        name="Other User",
                        email="*****@*****.**")

    img = Image.open("seeweb/scripts/avatar/sartzet.png")
    upload_user_avatar(img, other)

    # user can view RO in container owner by other
    roa = ROArticle()
    roa.init(session, dict(owner=other.id, name="other article"))
    roa.store_description("Title\n=====\n\nLorem Ipsum\nlorem ipsum")
    roa.add_policy(session, user, Role.view)

    road = ROArticle()
    road.init(session, dict(owner=other.id, name="other editable article"))
    road.store_description("Title\n=====\n\nLorem Ipsum\nlorem ipsum")
    road.add_policy(session, user, Role.edit)

    roc = ROContainer()
    roc.init(session, dict(owner=other.id,
                           name="other project",
                           contents=[roa, road]))
    ROLink.connect(session, container.id, roc.id, 'contains')

    # access granted to ROs through their container policy
    roa = ROArticle()
    roa.init(session, dict(owner=other.id, name="other 'private' article"))
    roa.store_description("Title\n=====\n\nLorem Ipsum\nlorem ipsum")

    roc = ROContainer()
    roc.init(session, dict(owner=other.id,
                           name="other 'denied' project",
                           contents=[roa]))
    roc.add_policy(session, user, Role.denied)
    ROLink.connect(session, container.id, roc.id, 'contains')

    roc = ROContainer()
    roc.init(session, dict(owner=other.id,
                           name="other project",
                           contents=[roa]))
    roc.add_policy(session, user, Role.edit)
    ROLink.connect(session, container.id, roc.id, 'contains')

    # public container
    roa = ROArticle()
    roa.init(session, dict(owner=other.id, name="other article"))
    roa.store_description("Title\n=====\n\nLorem Ipsum\nlorem ipsum")

    road = ROArticle()
    road.init(session, dict(owner=other.id, name="other denied article"))
    road.store_description("Title\n=====\n\nLorem Ipsum\nlorem ipsum")
    road.add_policy(session, user, Role.denied)

    roc = ROContainer()
    roc.init(session, dict(owner=other.id,
                           name="other 'public' project",
                           contents=[roa, road]))
    roc.public = True
    ROLink.connect(session, container.id, roc.id, 'contains')
Exemple #3
0
def main(session):
    # users
    revesansparole = User.create(session,
                                 uid='revesansparole',
                                 name="Jerome Chopard",
                                 email="*****@*****.**")

    img = Image.open("seeweb/scripts/avatar/revesansparole.png")
    upload_user_avatar(img, revesansparole)
    users.append(revesansparole)

    doofus0 = User.create(session,
                          uid='doofus%d' % 0,
                          name="Dummy Doofus",
                          email="*****@*****.**")
    users.append(doofus0)

    doofus1 = User.create(session,
                          uid='doofus%d' % 1,
                          name="Dummy Doofus",
                          email="*****@*****.**")
    users.append(doofus1)

    pradal = User.create(session,
                         uid='pradal',
                         name="Christophe Pradal",
                         email="*****@*****.**")
    img = Image.open("seeweb/scripts/avatar/pradal.png")
    upload_user_avatar(img, pradal)
    users.append(pradal)

    sartzet = User.create(session,
                          uid='sartzet',
                          name="Simon Artzet",
                          email="*****@*****.**")
    img = Image.open("seeweb/scripts/avatar/sartzet.png")
    upload_user_avatar(img, sartzet)
    users.append(sartzet)

    fboudon = User.create(session,
                          uid='fboudon',
                          name="Fred Boudon",
                          email="*****@*****.**")
    img = Image.open("seeweb/scripts/avatar/fboudon.png")
    upload_user_avatar(img, fboudon)
    users.append(fboudon)

    # teams
    subsub_team = Team.create(session, uid="subsubteam")
    subsub_team.description = """Test team only"""
    subsub_team.add_policy(session, doofus0, Role.edit)
    teams.append(subsub_team)

    sub_team = Team.create(session, uid="subteam")
    sub_team.description = """Test team only"""
    sub_team.add_policy(session, doofus1, Role.edit)
    sub_team.add_policy(session, subsub_team, Role.edit)
    teams.append(sub_team)

    vplants = Team.create(session, uid="vplants")
    img = Image.open("seeweb/scripts/avatar/vplants.png")
    upload_team_avatar(img, vplants)
    descr = dedent("""
            Team
            ----
            INRIA team based in Montpellier

            """)
    vplants.store_description(descr)
    vplants.add_policy(session, pradal, Role.edit)
    vplants.add_policy(session, fboudon, Role.view)
    teams.append(vplants)

    oa = Team.create(session, uid="openalea")
    img = Image.open("seeweb/scripts/avatar/openalea.png")
    upload_team_avatar(img, oa)
    descr = dedent("""
            Community
            ---------

            OpenAlea is an open source project primarily aimed at the plant research community.
            It is a distributed collaborative effort to develop Python libraries and tools that address the needs of
            current and future works in Plant Architecture modeling.
            OpenAlea includes modules to analyse, visualize and model the functioning and growth of plant architecture.

            """)
    oa.store_description(descr)
    oa.add_policy(session, revesansparole, Role.edit)
    oa.add_policy(session, pradal, Role.view)
    oa.add_policy(session, sartzet, Role.view)
    oa.add_policy(session, vplants, Role.edit)
    oa.add_policy(session, sub_team, Role.edit)
    teams.append(oa)