Esempio n. 1
0
def new_time_wp(db, cl, nodeid, new_values):
    if 'is_public' not in new_values:
        new_values['is_public'] = False
    common.require_attributes \
        ( _
        , cl
        , nodeid
        , new_values
        , 'name'
        , 'responsible'
        , 'project'
        , 'is_public'
        )
    prid = new_values['project']
    uid = db.getuid()
    prj = db.time_project.getnode(prid)
    if (uid != prj.responsible and uid != prj.deputy
            and not common.user_has_role(db, uid, 'Project') and uid != '1'):
        raise Reject, ("You may only create WPs for your own projects")
    act = db.time_project_status.get(prj.status, 'active')
    if not act and uid != '1':
        raise Reject, ("You may only create WPs for active projects")
    if 'durations_allowed' not in new_values:
        new_values['durations_allowed'] = False
    common.check_prop_len(_, new_values['name'])
    project = new_values['project']
    if 'wp_no' in new_values and not new_values['wp_no']:
        del new_values['wp_no']
    for i in 'name', 'wp_no':
        if i in new_values:
            check_duplicate_field_value(cl, project, i, new_values[i])
    status = db.time_project.get(project, 'status')
    new_values['cost_center'] = prj.cost_center
Esempio n. 2
0
def check_time_project(db, cl, nodeid, new_values):
    for i in 'wp_no', 'project':
        if i in new_values and cl.get(nodeid, i):
            raise Reject, "%(attr)s may not be changed" % {'attr': _(i)}
    common.check_prop_len(_, new_values.get('name', cl.get(nodeid, 'name')))
    if 'work_location' in cl.properties:
        wl = new_values.get('work_location', cl.get(nodeid, 'work_location'))
        if not wl:
            common.require_attributes \
                (_, cl, nodeid, new_values, 'organisation')
    common.require_attributes \
        ( _, cl, nodeid, new_values
        , 'cost_center', 'approval_hr', 'approval_required'
        )
Esempio n. 3
0
def new_time_wp (db, cl, nodeid, new_values) :
    if 'is_public' not in new_values :
        new_values ['is_public'] = False
    common.require_attributes \
        ( _
        , cl
        , nodeid
        , new_values
        , 'name'
        , 'responsible'
        , 'project'
        , 'is_public'
        )
    if 'is_extern' in cl.properties and 'is_extern' not in new_values :
        new_values ['is_extern'] = False
    prid = new_values ['project']
    uid  = db.getuid ()
    prj  = db.time_project.getnode (prid)
    is_auto_wp = False
    if 'auto_wp' in new_values :
        ap = db.auto_wp.getnode (new_values ['auto_wp'])
        if ap.time_project != new_values ['project'] :
            raise Reject (_ ("Auto-WP %s doesn't match") % _ ('time_project'))
        # If user may edit dyn. user we allow auto creation of wp
        if db.security.hasPermission ('Edit', db.getuid (), 'user_dynamic') :
            is_auto_wp = True
    if  (  uid != prj.responsible
        and uid != prj.deputy
        and not common.user_has_role (db, uid, 'Project')
        and uid != '1'
        and not is_auto_wp
        ) :
        raise Reject, ("You may only create WPs for your own projects")
    act  = db.time_project_status.get (prj.status, 'active')
    if not act and uid != '1' :
        raise Reject, ("You may only create WPs for active projects")
    if 'durations_allowed' not in new_values :
        new_values ['durations_allowed'] = False
    common.check_prop_len (_, new_values ['name'])
    project = new_values  ['project']
    if 'wp_no' in new_values and not new_values ['wp_no'] :
        del new_values ['wp_no']
    for i in 'name', 'wp_no' :
        if i in new_values :
            check_duplicate_field_value (cl, project, i, new_values [i])
    status = db.time_project.get (project, 'status')
    new_values ['cost_center'] = prj.cost_center
Esempio n. 4
0
def new_time_project(db, cl, nodeid, new_values):
    defaults = \
        ( ('approval_required', False)
        , ('approval_hr',       False)
        , ('op_project',        True)
        )
    common.require_attributes(_, cl, nodeid, new_values, 'name', 'responsible')
    if 'work_location' in cl.properties and 'work_location' not in new_values:
        common.require_attributes(_, cl, nodeid, new_values, 'organisation')
    for k, v in defaults:
        if k in cl.properties and k not in new_values:
            new_values[k] = v
    common.check_prop_len(_, new_values['name'])
    if 'status' not in new_values:
        try:
            new_values['status'] = db.time_project_status.lookup('New')
        except KeyError:
            new_values['status'] = '1'
    common.require_attributes(_, cl, nodeid, new_values, 'cost_center')
Esempio n. 5
0
def check_time_wp (db, cl, nodeid, new_values) :
    common.require_attributes \
        ( _
        , cl
        , nodeid
        , new_values
        , 'name'
        , 'project'
        , 'is_public'
        )
    common.check_prop_len (_, new_values.get ('name', cl.get (nodeid, 'name')))
    opr  = cl.get (nodeid, 'project')
    oprj = db.time_project.getnode (opr)
    prid = new_values.get ('project', opr)
    prj  = db.time_project.getnode (prid)
    act  = db.time_project_status.get (prj.status,  'active')
    acto = db.time_project_status.get (oprj.status, 'active')
    if (not act or not acto) and opr != prid :
        raise Reject \
            (_ ("No change of %(tp)s from/to closed %(tp)s")
            % dict (tp = _ ('time_project'))
            )
    if not act and 'time_end' in new_values :
        end = new_values ['time_end']
        now = Date ('.')
        od  = cl.get (nodeid, 'time_end')
        if (od and od < now) or end > now :
            raise Reject \
                (_ ("No change of %(te)s for %(wp)s of inactive %(tp)s")
                % dict ( te = _ ('time_end')
                       , wp = _ ('time_wp')
                       , tp = _ ('time_project')
                       )
                )
    for i in 'name', 'wp_no' :
        if i in new_values and new_values [i] is not None :
            check_duplicate_field_value (cl, prid, i, new_values [i])
    if 'project' in new_values :
        new_values ['cost_center'] = prj.cost_center
Esempio n. 6
0
def check_proplen(db, cl, nodeid, new_values, limit=64):
    pname = cl.getkey()
    if pname in new_values:
        common.check_prop_len(_, new_values[pname], pname, limit=64)