Exemplo n.º 1
0
def share():
    """
    Show the list of desk to with the item can be push
    """
    item = application.getItemByUUID(request.args(0))
    if item is None:
        raise HTTP(404)

    query = (db.desk.id != session.desk_id)
    query &= auth.accessible_query('push_items', db.desk)

    posible_desk = db(query).select()

    fld_to_desk = Field('to_desk', 'integer')
    fld_to_desk.label = T("Push to organization desk")
    fld_to_desk.comment = T("Select where to push the item")
    fld_to_desk.requires = IS_EMPTY_OR(
        IS_IN_SET([(desk.id, desk.name) for desk in posible_desk]))

    fld_personal_desk = Field('to_person_desk', 'integer')
    fld_personal_desk.label = T("Push to other person desk")
    fld_personal_desk.comment = T("Select a person from the list.")
    # list of person on orgs
    persons = []
    # search up all the persons
    orgs = db(db.organization.users.contains(auth.user.id)).select()
    for org in orgs:
        x = [db.auth_user(id=y) for y in org.users if y != auth.user.id]
        persons.extend(x)
    persons = list(set(persons))
    fld_personal_desk.requires = IS_EMPTY_OR(
        IS_IN_SET([(per.id, "{} {}".format(per.first_name, per.last_name))
                   for per in persons]))

    fld_cond = Field('cond', 'boolean', default=False)
    fld_cond.label = T('To other person?')

    form = SQLFORM.factory(fld_to_desk,
                           fld_personal_desk,
                           fld_cond,
                           submit_button=T("Send"),
                           table_name='share')
    if form.process().accepted:
        src = session.desk_id
        if form.vars.cond:
            # send the item to other user
            other_user = db.auth_user(form.vars.to_person_desk)
            target = application.getUserDesk(other_user).id
        else:
            # send the item to the selected desk
            target = form.vars.to_desk

        if target:
            ct = application.getContentType(item.item_type)
            ct.shareItem(item.unique_id, src, target)
        response.js = "$('#metaModal').modal('hide');"
        response.flash = None

    return locals()
Exemplo n.º 2
0
def share():
    """
    Show the list of desk to with the item can be push
    """
    item = application.getItemByUUID(request.args(0))
    if item is None:
        raise HTTP(404)

    query = (db.desk.id != session.desk_id)
    query &= auth.accessible_query('push_items', db.desk)

    posible_desk = db(query).select()

    fld_to_desk = Field('to_desk', 'integer')
    fld_to_desk.label = T("Push to")
    fld_to_desk.comment = T("Select where to push the item")
    fld_to_desk.requires = IS_IN_SET([(desk.id, desk.name)
                                      for desk in posible_desk])
    form = SQLFORM.factory(fld_to_desk,
                           submit_button=T("Send"),
                           table_name='share')
    if form.process().accepted:
        # send the item to the selected desk
        ct = application.getContentType(item.item_type)
        ct.shareItem(item.unique_id, session.desk_id, form.vars.to_desk)
        response.js = "$('#metaModal').modal('hide');"

    return locals()
Exemplo n.º 3
0
def members():
    org = db.organization(request.args(0))

    if not request.args(1):
        fld_email = Field('email', 'string', label=T("Email"))
        fld_email.requires = IS_EMAIL()

        form = SQLFORM.factory(
            fld_email,
            formstyle='bootstrap3_inline',
            submit_button=T("Add user"),
            table_name='members')

        if form.process().accepted:
            u = db.auth_user(email=form.vars.email)
            if u is not None:
                # create new share
                if u.id in org.users:
                    form.errors.email = T(
                        "The user is already in the organization")
                else:
                    user_list = org.users
                    user_list.insert(0, u.id)
                    org.update_record(users=user_list)
                    g_id = auth.user_group(u.id)
                    auth.add_permission(g_id, 'read', db.organization, org.id)
            else:
                # no user with that email
                response.flash = ""
                form.errors.email = T("The user don't exists on this system")
    elif request.args(1) == 'delete':
        # remove the user on args(2) from the org members list
        # TODO: remove else any perms on the org desks
        user_to_remove = db.auth_user(request.args(2))
        if user_to_remove is not None:
            user_list = org.users
            user_list.remove(user_to_remove.id)
            org.update_record(users=user_list)
            # remove perms over the org
            auth.del_permission(
                auth.user_group(user_to_remove.id),
                'read',
                db.organization,
                org.id)
            # remove, also, all rights over the desks in the org.
            desk_perms = [
                'read_desk', 'update_items', 'push_items', 'update_desk']
            for desk_id in org.desks:
                for perm in desk_perms:
                    auth.del_permission(
                        auth.user_group(user_to_remove.id),
                        perm,
                        db.desk,
                        desk_id
                    )
        redirect(URL('org', 'members', args=[org.id]))

    return locals()
Exemplo n.º 4
0
def members():
    org = db.organization(request.args(0))

    if not request.args(1):
        fld_email = Field('email', 'string', label=T("Email"))
        fld_email.requires = IS_EMAIL()

        form = SQLFORM.factory(fld_email,
                               formstyle='bootstrap3_inline',
                               submit_button=T("Add user"),
                               table_name='members')

        if form.process().accepted:
            u = db.auth_user(email=form.vars.email)
            if u is not None:
                # create new share
                if u.id in org.users:
                    form.errors.email = T(
                        "The user is already in the organization")
                else:
                    user_list = org.users
                    user_list.insert(0, u.id)
                    org.update_record(users=user_list)
                    g_id = auth.user_group(u.id)
                    auth.add_permission(g_id, 'read', db.organization, org.id)
            else:
                # no user with that email
                response.flash = ""
                form.errors.email = T("The user don't exists on this system")
    elif request.args(1) == 'delete':
        # remove the user on args(2) from the org members list
        # TODO: remove else any perms on the org desks
        user_to_remove = db.auth_user(request.args(2))
        if user_to_remove is not None:
            user_list = org.users
            user_list.remove(user_to_remove.id)
            org.update_record(users=user_list)
            # remove perms over the org
            auth.del_permission(auth.user_group(user_to_remove.id), 'read',
                                db.organization, org.id)
            # remove, also, all rights over the desks in the org.
            desk_perms = [
                'read_desk', 'update_items', 'push_items', 'update_desk'
            ]
            for desk_id in org.desks:
                for perm in desk_perms:
                    auth.del_permission(auth.user_group(user_to_remove.id),
                                        perm, db.desk, desk_id)
        redirect(URL('org', 'members', args=[org.id]))

    return locals()
Exemplo n.º 5
0
def share():
    """
    Show the user's who has access to this item
    """
    item = application.getItemByUUID(request.args(0))
    if item is None:
        raise HTTP(404)

    fld_email = Field('email', 'string', default='')
    fld_perms = Field('perms', 'string', default='owner')
    fld_email.requires = IS_EMAIL()
    form = SQLFORM.factory(
        fld_email,
        fld_perms,
        formstyle='bootstrap3_inline',
        submit_button=T("Share this item"),
        table_name='share')
    if form.process().accepted:
        # search a user by his email addr
        u = db.auth_user(email=form.vars.email)
        if u is not None:
            # create new share
            ct = application.getContentType(item.item_type)
            ct.shareItem(item.unique_id, u, perms=form.vars.perms)
            # notify users
            subject = T("Share of %s", (item.headline,))
            message = response.render(
                'share_email.txt',
                dict(
                    item=item,
                    user=auth.user,
                    t_user=db.auth_user(email=form.vars.email)
                )
            )
            application.notifyCollaborators(
                item.unique_id,
                subject,
                message
            )
            # --
            # close the dialog
            response.js = "$('#metaModal').modal('hide');"
        else:
            # no user with that email
            response.flash = T("The user don't exists on this system")
            form.errors.email = T("The user don't exists on this system")

    return locals()
Exemplo n.º 6
0
def share():
    """
    Show the list of desk to with the item can be push
    """
    item = application.getItemByUUID(request.args(0))
    if item is None:
        raise HTTP(404)

    query = (db.desk.id != session.desk_id)
    query &= auth.accessible_query('push_items', db.desk)

    posible_desk = db(query).select()

    fld_to_desk = Field('to_desk', 'integer')
    fld_to_desk.label = T("Push to organization desk")
    fld_to_desk.comment = T("Select where to push the item")
    fld_to_desk.requires = IS_EMPTY_OR(IS_IN_SET(
        [(desk.id, desk.name) for desk in posible_desk]
    ))

    fld_personal_desk = Field('to_person_desk', 'integer')
    fld_personal_desk.label = T("Push to other person desk")
    fld_personal_desk.comment = T("Select a person from the list.")
    # list of person on orgs
    persons = []
    # search up all the persons
    orgs = db(db.organization.users.contains(auth.user.id)).select()
    for org in orgs:
        x = [db.auth_user(id=y) for y in org.users if y != auth.user.id]
        persons.extend(x)
    persons = list(set(persons))
    fld_personal_desk.requires = IS_EMPTY_OR(IS_IN_SET(
        [(per.id, "{} {}".format(per.first_name, per.last_name)) for per in persons]
    ))

    fld_cond = Field('cond', 'boolean', default=False)
    fld_cond.label = T('To other person?')

    form = SQLFORM.factory(
        fld_to_desk,
        fld_personal_desk,
        fld_cond,
        submit_button=T("Send"),
        table_name='share')
    if form.process().accepted:
        src = session.desk_id
        if form.vars.cond:
            # send the item to other user
            other_user = db.auth_user(form.vars.to_person_desk)
            target = application.getUserDesk(other_user).id
        else:
            # send the item to the selected desk
            target = form.vars.to_desk

        if target:
            ct = application.getContentType(item.item_type)
            ct.shareItem(item.unique_id, src, target)
        response.js = "$('#metaModal').modal('hide');"
        response.flash = None

    return locals()