def nosy_for_approval (db, app, add = False) : nosy = {} if app.user : for k in common.approval_by (db, app.user) : nosy [k] = 1 # Don't add deputy to nosy unless deputy_gets_mail is set if app.deputy and app.deputy_gets_mail : for k in common.approval_by (db, app.deputy) : nosy [k] = 1 nosy_dd = {} if app.role_id : ao = db.pr_approval_order.getnode (app.role_id) subst = [] for u in ao.users : # Do not include user replaced by clearance_by (delegation) # in the mailing list. subst.extend (common.approval_by (db, u)) nosy_dd = subst elif app.role : nosy_dd = common.get_uids_with_role (db, app.role) # If we're adding users, filter by unwanted messages if add and nosy_dd : nosy_dd = dict.fromkeys \ (u for u in nosy_dd if not db.user.get (u, 'want_no_messages')) nosy.update (dict.fromkeys (nosy_dd)) return nosy
def approval_undecided (db, userid, itemid) : """ User is allowed to change status of undecided approval if they are the owner/deputy or have appropriate role. In addition this is allowed if they have a delegated approval or are an active substitute. We also allow pr.status to be 'rejected': This cannot change the outcome (once approved or rejected the pr.status cannot change) but allows for race condition when someone has several approvals in a single mask and one of that approvals changed the PR to rejected before the others were processed. """ if not itemid or itemid < 1 : return False ap = db.pr_approval.getnode (itemid) pr = db.purchase_request.getnode (ap.purchase_request) und = db.pr_approval_status.lookup ('undecided') st_open = db.pr_status.lookup ('open') st_approving = db.pr_status.lookup ('approving') st_reject = db.pr_status.lookup ('rejected') if ( ap.status == und and ( userid in common.approval_by (db, ap.user) or userid in common.approval_by (db, ap.deputy) or (ap.role_id and prlib.has_pr_role (db, userid, ap.role_id)) ) and pr.status in (st_open, st_approving, st_reject) ) : return True return False
def linked_pr (db, userid, itemid) : """ Users are allowed if an approval from them is linked to the PR. """ if not itemid or itemid < 1 : return False pr = db.purchase_request.getnode (itemid) ap = db.pr_approval.filter (None, dict (purchase_request = itemid)) for id in ap : a = db.pr_approval.getnode (id) # User or deputy or delegated? if userid in common.approval_by (db, a.user) : return True if userid in common.approval_by (db, a.deputy) : return True if a.role_id and prlib.has_pr_role (db, userid, a.role_id) : return True return False
def has_pr_role(db, uid, roleid): r = db.pr_approval_order.getnode(roleid) # For speed reasons check direct user if uid in r.users: return True # Check including delegated and substituted approvals for u in r.users: if uid in common.approval_by(db, u): return True return False
def approval_undecided (db, userid, itemid) : """ User is allowed to change status of undecided approval if they are the owner/deputy or have appropriate role. In addition this is allowed if they have a delegated approval or are an active substitute. """ if not itemid or itemid < 1 : return False ap = db.pr_approval.getnode (itemid) pr = db.purchase_request.getnode (ap.purchase_request) und = db.pr_approval_status.lookup ('undecided') st_open = db.pr_status.lookup ('open') st_approving = db.pr_status.lookup ('approving') if ( ap.status == und and ( userid in common.approval_by (db, ap.user) or userid in common.approval_by (db, ap.deputy) or (ap.role_id and prlib.has_pr_role (db, userid, ap.role_id)) ) and pr.status in (st_open, st_approving) ) : return True return False