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()
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()
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()
def users(): desk = db.desk(request.args(0)) session.desk_id = desk.id org = db.organization(session.org_id) if request.args(1): my_user = db.auth_user(request.args(1)) fld_read_desk = Field('read_desk', 'boolean') fld_read_desk.label = T("Read '%s' content", (desk.name, )) fld_read_desk.comment = T( "Allow the user read only access to the desk item list.") fld_read_desk.default = auth.has_permission('read', db.desk, desk.id, my_user.id) fld_update_items = Field('update_items', 'boolean') fld_update_items.label = T("Read/Update items in '%s'", (desk.name, )) fld_update_items.comment = T( "Allow the user make modifications to the items in the desk.") fld_update_items.default = auth.has_permission('update_items', db.desk, desk.id, my_user.id) fld_push_items = Field('push_items', 'boolean') fld_push_items.label = T("Push items into '%s'", (desk.name, )) fld_push_items.comment = T( """Allow the user move items into the desk.""") fld_push_items.default = auth.has_permission('push_items', db.desk, desk.id, my_user.id) fld_update_desk = Field('update_desk', 'boolean') fld_update_desk.label = T("Update/Manage '%s'", (desk.name, )) fld_update_desk.comment = T(""" Allow the user to manage/administrate this desk. Use with caution. """) fld_update_desk.default = auth.has_permission('update', db.desk, desk.id, my_user.id) form = SQLFORM.factory(fld_read_desk, fld_update_items, fld_push_items, fld_update_desk, table_name='desk_perms') if form.process().accepted: if form.vars.read_desk: # give perm auth.add_permission(auth.user_group(my_user.id), 'read', db.desk, desk.id) else: auth.del_permission(auth.user_group(my_user.id), 'read', db.desk, desk.id) if form.vars.update_items: # give perm auth.add_permission(auth.user_group(my_user.id), 'update_items', db.desk, desk.id) else: auth.del_permission(auth.user_group(my_user.id), 'update_items', db.desk, desk.id) if form.vars.push_items: # give perm auth.add_permission(auth.user_group(my_user.id), 'push_items', db.desk, desk.id) else: auth.del_permission(auth.user_group(my_user.id), 'push_items', db.desk, desk.id) if form.vars.update_desk: # give perm auth.add_permission(auth.user_group(my_user.id), 'update_desk', db.desk, desk.id) else: auth.del_permission(auth.user_group(my_user.id), 'update_desk', db.desk, desk.id) redirect(URL('desk', 'users', args=[desk.id])) response.view = "desk/user_perms.html" else: # select user view query = (db.auth_user.id > 0) query &= (db.auth_user.id.belongs(org.users)) my_users = db(query).select() return locals()
def users(): desk = db.desk(request.args(0)) session.desk_id = desk.id org = db.organization(session.org_id) if request.args(1): my_user = db.auth_user(request.args(1)) fld_read_desk = Field('read_desk', 'boolean') fld_read_desk.label = T("Read '%s' content", (desk.name,)) fld_read_desk.comment = T( "Allow the user read only access to the desk item list.") fld_read_desk.default = auth.has_permission( 'read', db.desk, desk.id, my_user.id) fld_update_items = Field('update_items', 'boolean') fld_update_items.label = T("Read/Update items in '%s'", (desk.name,)) fld_update_items.comment = T( "Allow the user make modifications to the items in the desk.") fld_update_items.default = auth.has_permission( 'update_items', db.desk, desk.id, my_user.id) fld_push_items = Field('push_items', 'boolean') fld_push_items.label = T("Push items into '%s'", (desk.name,)) fld_push_items.comment = T( """Allow the user move items into the desk.""" ) fld_push_items.default = auth.has_permission( 'push_items', db.desk, desk.id, my_user.id) fld_update_desk = Field('update_desk', 'boolean') fld_update_desk.label = T("Update/Manage '%s'", (desk.name,)) fld_update_desk.comment = T( """ Allow the user to manage/administrate this desk. Use with caution. """ ) fld_update_desk.default = auth.has_permission( 'update', db.desk, desk.id, my_user.id) form = SQLFORM.factory( fld_read_desk, fld_update_items, fld_push_items, fld_update_desk, table_name='desk_perms' ) if form.process().accepted: if form.vars.read_desk: # give perm auth.add_permission( auth.user_group(my_user.id), 'read', db.desk, desk.id) else: auth.del_permission( auth.user_group(my_user.id), 'read', db.desk, desk.id) if form.vars.update_items: # give perm auth.add_permission( auth.user_group(my_user.id), 'update_items', db.desk, desk.id) else: auth.del_permission( auth.user_group(my_user.id), 'update_items', db.desk, desk.id) if form.vars.push_items: # give perm auth.add_permission( auth.user_group(my_user.id), 'push_items', db.desk, desk.id) else: auth.del_permission( auth.user_group(my_user.id), 'push_items', db.desk, desk.id) if form.vars.update_desk: # give perm auth.add_permission( auth.user_group(my_user.id), 'update_desk', db.desk, desk.id) else: auth.del_permission( auth.user_group(my_user.id), 'update_desk', db.desk, desk.id) redirect(URL('desk', 'users', args=[desk.id])) response.view = "desk/user_perms.html" else: # select user view query = (db.auth_user.id > 0) query &= (db.auth_user.id.belongs(org.users)) my_users = db(query).select() return locals()