def project_index(account_id=None): from models.account import Account from models.project import Project from helpers.project import ProjectHelper title = g._t('projects') if account_id: account_id = urllib.unquote_plus(account_id) account = Account.query.filter_by(id=account_id).first() if not account: abort(404) elif not app.access('membership', account=account): abort(403) projectList = ProjectHelper.listProjectsForMember(account) else: account = g.account if app.access('project', action='administer'): projectList = ProjectHelper.listProjects() elif app.access('project', action='list'): projectList = ProjectHelper.listActiveProjects() elif app.access('membership', account=account): projectList = ProjectHelper.listProjectsForMember(account) else: abort(403) return render_template('project/index.html', title=title, projectList=projectList, account=account)
def _activityHeader(**kwargs): from models.account import Account from models.project import Project, Component, Membership, Label from helpers.account import AccountHelper from helpers.project import ProjectHelper header = {} if kwargs.has_key('start_date'): header['start_date'] = kwargs['start_date'] else: header['start_date'] = request.values.get('start_date', g._constant()['DATE']['MONTH']) #start_date = datetime.datetime.strptime(start_datestring, '%Y-%m-%d') #start_ts = start_date.strftime('%s') if kwargs.has_key('end_date'): header['end_date'] = kwargs['end_date'] else: header['end_date'] = request.values.get('end_date', g._constant()['DATE']['TODAY']) #end_date = datetime.datetime.strptime(end_datestring, '%Y-%m-%d') #end_ts = end_date.strftime('%s') header['employees'] = [] if kwargs.has_key('employees'): header['employees'] = kwargs['employees'] elif app.access('profile', action='administer'): header['employees'] = AccountHelper.listAccounts() elif app.access('profile', action='list'): header['employees'] = AccountHelper.listActiveAccounts() elif app.access('profile', action='read', account=g.account): header['employees'] = [g.account] else: header['employees'] = [] header['skip_projects'] = ProjectHelper.listVacationProjects() header['projects'] = [] if kwargs.has_key('projects'): header['projects'] = kwargs['projects'] elif app.access('project', action='administer'): header['projects'] = ProjectHelper.listAllComponents() elif app.access('project', action='list'): header['projects'] = ProjectHelper.listAllActiveComponents() elif app.access('membership', account=g.account): header['projects'] = ProjectHelper.listAllComponentsForMember(account=g.account) else: header['projects'] = [] return header
def permission_project(action=None, project=None, account=None): """Project CRUD check for signed in account. @description Check if a signed in account has a specified action for a given project. @param <str>action, valid values ["list", "administer", "create", "read", "update", "delete"] @param <Project>project (optional) @return bool @example Call as app.access('project', action='update', project=PROJECT)""" from models.project import Project from helpers.project import ProjectHelper if not action: raise Exception('Project CRUD permission: action missing') if not account or not account.id: account=g.account if not project and not action in ['list', 'administer', 'create']: raise Exception('Project CRUD permission: project required for action "'+action+'"') if action == 'list': return app.access('group', account=account, group_alias=['administrator', 'privileged_manager']) if action == 'administer': return app.access('group', account=account, group_alias=['administrator', 'privileged_manager']) elif action == 'create': return app.access('group', account=account, group_alias=['administrator', 'privileged_manager', 'manager']) elif action == 'read': if project.status & project.STATUS_DELETED: return app.access('group', account=account, group_alias=['administrator', 'privileged_manager']) elif ProjectHelper.projectHasActiveMember(project=project, account=account): return True else: return app.access('group', account=account, group_alias=['administrator', 'privileged_manager']) elif action == 'update': if project.status & project.STATUS_DELETED: return app.access('group', account=account, group_alias=['administrator', 'privileged_manager']) elif ProjectHelper.projectHasManager(project=project, account=account): return True else: return app.access('group', account=account, group_alias=['administrator', 'privileged_manager']) elif action == 'delete': return app.access('group', account=account, group_alias=['administrator', 'privileged_manager']) elif action == 'role': if project.status & project.STATUS_DELETED: return app.access('group', account=account, group_alias=['administrator', 'privileged_manager']) else: return app.access('group', account=account, group_alias=['administrator', 'privileged_manager']) else: raise Exception('Project CRUD permission: incorrect action "'+action+'", must be ["list", "administer", "create", "read", "update", "delete"]')
def application_vacation(): from helpers.project import ProjectHelper data = [] for component in ProjectHelper.listVacationComponents(): data.append((component.path, component.title)) data = dict(data) return Response(json.dumps({'status':200, 'description':'OK', 'data':data, 'errors':[]}), mimetype='application/json')
def _is_vacation(project): from helpers.project import ProjectHelper return ProjectHelper.projectIsHoliday(project) import datetime if str( timestamp ).isdigit(): return datetime.datetime.fromtimestamp( int( str( timestamp ).split('.')[0] ) ).weekday() > 4 else: return datetime.datetime.strptime( timestamp, '%Y-%m-%d' ).weekday() > 4
def permission_activity(account=None): from helpers.project import ProjectHelper """Accounts' membership check for signed in account. @description Check if a signed in account is permitted to see the given account's membership activity or totals. @param <Account>account (optional) @return bool @example Call as app.access('membership', account=ACCOUNT)""" if not account: return app.access('profile', action='list') and app.access('report', action='list')# and app.access('project', action='list') else: return ProjectHelper.profileHasSubordinate(g.account, account) or app.access('membership', account=account)
def project_members(project_id): from models.account import Account from models.project import Project, Component, Membership, Role from helpers.account import AccountHelper from helpers.project import ProjectHelper project_id = urllib.unquote_plus(project_id) project = Project.query.filter_by(id=project_id).first() if not project: abort(404) elif not app.access('project', action='update', project=project): abort(403) title = g._t('project members') breadcrumbs = ( (g._t('projects'), url_for('project_index')), (project.__str__(), url_for('project_view', project_id=urllib.quote_plus(str(project_id)))), (title, "#") ) if (request.form.get('method') == 'PUT' or request.method == 'PUT') and request.form.get('csrf_token'): submittedMembership = Membership.query.filter_by(project=project, id=request.form.get('membership_id')).first() if submittedMembership: submittedMembership.component = Component.query.filter_by(project=project, id=request.form.get('membership_component_id', None)).first() submittedMembership.account = Account.query.filter_by(id=request.form.get('membership_account_id', None)).first() submittedMembership.role = Role.query.filter_by(id=request.form.get('membership_role_id', None)).first() if not submittedMembership.validate(): submittedMembership.save() flash( g._t('membership update success')) return redirect(url_for('project_members', project_id=urllib.quote_plus(str(project_id)))) else: flash( g._t('membership not found'), 'error') elif (request.form.get('method') == 'DELETE' or request.method == 'DELETE') and request.form.get('csrf_token'): submittedMembership = Membership.query.filter_by(project=project, id=request.form.get('membership_id')).first() if submittedMembership: submittedMembership.delete() flash( g._t('membership delete success')) return redirect(url_for('project_members', project_id=urllib.quote_plus(str(project_id)))) else: flash( g._t('membership not found')) elif (request.form.get('method') == 'POST' or request.method == 'POST') and request.form.get('csrf_token'): submittedMembership = Membership() submittedMembership.project_id = project.id component = Component.query.filter_by(project=project, id=request.form.get('membership_component_id', None)).first() if component: submittedMembership.component_id = component.id account = submittedMembership.account_id = Account.query.filter_by(id=request.form.get('membership_account_id', None)).first() if account: submittedMembership.account_id = account.id role = Role.query.filter_by(id=request.form.get('membership_role_id', None)).first() if role: submittedMembership.role_id = role.id if not submittedMembership.validate(): submittedMembership.save() flash( g._t('membership create success')) return redirect(url_for('project_members', project_id=urllib.quote_plus(str(project_id)))) else: submittedMembership = Membership() if app.access('profile', action='administer'): accountList =AccountHelper.listAccounts() elif app.access('profile', action='list'): accountList = AccountHelper.listActiveAccounts() else: accountList = [g.account] if app.access('profile', action='administer'): componentList = ProjectHelper.listComponents(project=project) elif app.access('profile', action='list'): componentList = ProjectHelper.listActiveComponents(project=project) else: componentList = [ProjectHelper.getDefaultComponent(project=project)] roleList = ProjectHelper.listRoles() return render_template('project/members.html', project_id=project_id, project=project, accountList=accountList, roleList=roleList, roleDefault=ProjectHelper.getDefaultRole(), submittedMembership=submittedMembership, title=title, breadcrumbs=breadcrumbs)