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)
def install_common_members(): """Define all the required members for the corresponding projects""" from models.account import Account from models.project import Project, Component, Membership, Label, Role newMembers = { 'ALTI': { 'alexey.paschenko': Role.ROLE_DEFAULT, 'michael.kotlyar': Role.ROLE_DEFAULT, 'sergey.bykov': Role.ROLE_DEFAULT, 'valentina.davidenko': Role.ROLE_DEFAULT, 'vladislav.nemirovskiy': Role.ROLE_DEFAULT }, 'ARK/HA': { 'ivan.kupriyan': Role.ROLE_MANAGER, 'hariton.batkov': Role.ROLE_DEFAULT, 'andrey.dmitrenko': Role.ROLE_DEFAULT }, 'BD': { 'alexey.golosenko': Role.ROLE_DEFAULT, 'rostislav.chernenko': Role.ROLE_DEFAULT }, 'DARIO': { 'mike.petruk': Role.ROLE_MANAGER, 'timur.glushan': Role.ROLE_DEFAULT, 'dmitry.mizuch': Role.ROLE_DEFAULT, 'igor.grankov': Role.ROLE_DEFAULT, 'vitaliy.shevchenko': Role.ROLE_DEFAULT, 'andrey.dmitrenko': Role.ROLE_DEFAULT }, 'DARIO:IOS': { 'anatolii.shevchenko': Role.ROLE_DEFAULT }, 'DARIO:3/IOS': { 'anatolii.shevchenko': Role.ROLE_DEFAULT }, 'DARIO:A': { 'danylo.vus': Role.ROLE_DEFAULT, 'denys.kravchenko': Role.ROLE_DEFAULT, 'oleksii.miroshnychenko': Role.ROLE_DEFAULT }, 'DARIO:3/A': { 'danylo.vus': Role.ROLE_DEFAULT, 'denys.kravchenko': Role.ROLE_DEFAULT, 'oleksii.miroshnychenko': Role.ROLE_DEFAULT }, 'DARIO:B': { 'yury.mirgorodsky': Role.ROLE_DEFAULT, 'anna.zanizdra': Role.ROLE_DEFAULT }, 'DARIO:3/B': { 'yury.mirgorodsky': Role.ROLE_DEFAULT, 'anna.zanizdra': Role.ROLE_DEFAULT }, 'DARIO:WEB': { 'yury.mirgorodsky': Role.ROLE_DEFAULT, 'anna.zanizdra': Role.ROLE_DEFAULT, 'oleg.voitenko': Role.ROLE_DEFAULT }, 'DARIO:3/WEB': { 'yury.mirgorodsky': Role.ROLE_DEFAULT, 'anna.zanizdra': Role.ROLE_DEFAULT, 'oleg.voitenko': Role.ROLE_DEFAULT }, 'KIBOSH': { 'ivan.kupriyan': Role.ROLE_MANAGER, 'denys.kravchenko': Role.ROLE_DEFAULT, 'ivan.guy': Role.ROLE_DEFAULT, 'oleksii.miroshnychenko': Role.ROLE_DEFAULT, 'danylo.vus': Role.ROLE_DEFAULT, 'andrey.dmitrenko': Role.ROLE_DEFAULT, 'vitaliy.shevchenko': Role.ROLE_DEFAULT }, 'KIKO/TT': { 'ivan.kupriyan': Role.ROLE_MANAGER, 'hariton.batkov': Role.ROLE_DEFAULT }, 'LYCOS/MSGR': { 'ivan.kupriyan': Role.ROLE_MANAGER, 'hariton.batkov': Role.ROLE_DEFAULT, 'anton.trubianov': Role.ROLE_DEFAULT, 'konstantin.shulika': Role.ROLE_DEFAULT }, 'MYH': { 'ivan.kupriyan': Role.ROLE_MANAGER }, 'MYH/MVP': { 'ivan.kupriyan': Role.ROLE_MANAGER, 'konstantin.shulika': Role.ROLE_DEFAULT, 'hariton.batkov': Role.ROLE_DEFAULT, 'anton.trubianov': Role.ROLE_DEFAULT, 'dmitry.bondarenko': Role.ROLE_DEFAULT, 'slava.miakishev': Role.ROLE_DEFAULT, 'alexey.krivosheev': Role.ROLE_DEFAULT, 'ludmila.sadovenko': Role.ROLE_DEFAULT, 'igor.grankov': Role.ROLE_DEFAULT, 'vitaliy.shevchenko': Role.ROLE_DEFAULT }, 'NOKIA': { 'timur.glushan': Role.ROLE_DEFAULT }, 'NOKIA/OFFICIAL': { 'timur.glushan': Role.ROLE_DEFAULT }, 'PHOTO': { 'alexandr.karlin': Role.ROLE_DEFAULT, 'dmitry.dunaevsky': Role.ROLE_DEFAULT }, 'QUART': { 'ivan.kupriyan': Role.ROLE_MANAGER, 'alexander.rykanov': Role.ROLE_DEFAULT, 'tymur.baksheyev': Role.ROLE_DEFAULT }, 'TINYTAP/A': { 'ivan.kupriyan': Role.ROLE_MANAGER, 'hariton.batkov': Role.ROLE_DEFAULT }, 'USTORE': { 'ivan.kupriyan': Role.ROLE_MANAGER, 'alexander.rykanov': Role.ROLE_DEFAULT, 'vadym.pastushenko': Role.ROLE_DEFAULT, 'andrew.ashmarin': Role.ROLE_DEFAULT }, 'UVIDEO': { 'ivan.kupriyan': Role.ROLE_MANAGER, 'alexander.rykanov': Role.ROLE_DEFAULT, 'vadym.pastushenko': Role.ROLE_DEFAULT, 'andrew.ashmarin': Role.ROLE_DEFAULT }, 'VIS': { 'ivan.kupriyan': Role.ROLE_MANAGER, 'andrew.ashmarin': Role.ROLE_DEFAULT }, 'IVIEW': { 'lana.ieremieva': Role.ROLE_DEFAULT, 'nadyam': Role.ROLE_DEFAULT }, 'MBOT': { 'gleb.dzyuba': Role.ROLE_DEFAULT, 'timur.glushan': Role.ROLE_DEFAULT }, 'OFFICE': { 'lana.ieremieva': Role.ROLE_DEFAULT, 'marina.usmanova': Role.ROLE_DEFAULT, 'nadyam': Role.ROLE_DEFAULT, 'veronica.belous': Role.ROLE_DEFAULT } } for project_alias, memberList in newMembers.items(): if project_alias.find(':') > 0: project_alias, component_alias = project_alias.split(':', 1) project = Project.query.filter_by(alias=project_alias).first() component = Component.query.filter_by(project=project, alias=component_alias).first() else: project = Project.query.filter_by(alias=project_alias).first() component = Component.query.filter_by(project=project, alias=Component.COMPONENT_DEFAULT).first() if project: for account_alias, role_alias in memberList.items(): account = Account.query.filter_by(alias=account_alias).first() if account: role = Role.query.filter_by(alias=role_alias).first() or Role.query.filter_by(alias=Role.ROLE_DEFAULT).first() membership = Membership.query.filter_by(project_id=project.id, component_id=component.id, account_id=account.id).first() if not membership: membership = Membership() membership.project_id = project.id membership.component_id = component.id membership.account_id = account.id membership.role_id = role.id membership.save()