def delete_freelancer_note(session, admin_id, note_id):
    note = session.query(FreelancerNoteModel).filter_by(id=note_id).scalar()
    if not note:
        raise InvalidRequest("note id does not exist")
    if not note.admin_id:
        note.admin_id = admin_id
    elif note.admin_id != admin_id:
        raise InvalidRequest("You don't have permissions to edit this note")
    session.query(FreelancerNoteModel).filter_by(id=note_id).delete()
    session.commit()
def edit_project_note(session, admin_id, note_id, note):
    note_obj = session.query(ProjectNoteModel).filter_by(id=note_id).scalar()
    if not note_obj:
        raise InvalidRequest("note id does not exist")
    if not note_obj.admin_id:
        note_obj.admin_id = admin_id
    elif note_obj.admin_id != admin_id:
        raise InvalidRequest("You don't have permissions to edit this note")
    note_obj.note = note
    note_obj.created_at = datetime.dateime.utcnow()
    session.commit()
def add_project_note(session, admin_id, note, project_id):
    if not session.query(MasterProjectModel).filter_by(id=project_id).scalar():
        raise InvalidRequest("project id does not exist")
    fnote = ProjectNoteModel(project_id=project_id,
                             admin_id=admin_id,
                             note=note)
    session.add(fnote)
    session.commit()
Exemple #4
0
 def mutate(self, info, token, project_id, stage):
     allowed_stage_values = [
         "Market Scan", "Selection", "Matching", "Contracting", "Won",
         "Lost"
     ]
     verify_admin(token)
     if stage not in allowed_stage_values:
         raise InvalidRequest("Invalid stage value, allowed values are - " +
                              str(allowed_stage_values))
     session = get_session()
     project = get_project_by_id(session, project_id)
     if not project:
         raise InvalidRequest("Project not found")
     project.project_status = stage
     session.commit()
     session.close()
     return EditMasterProjectSettings(
         master_project=MasterProject.detail(token=token, id=project_id))
 def detail(*args, **kwargs):
     verify_admin(kwargs['token'])
     project_id = kwargs['id']
     session = get_session()
     project = get_project_by_id(session, project_id)
     session.close()
     if not project:
         raise InvalidRequest("Project with id not found")
     return MasterProject(project, kwargs)
def update_candidate_quote(session, project_id, freelancer_id, rate_unit,
                           rate_amount, rate_currency):
    cmap = session.query(ProjectCandidateMapModel).filter_by(
        project_id=project_id, freelancer_id=freelancer_id).scalar()
    if not cmap:
        raise InvalidRequest("Candidate does not exit")
    cmap.rate_unit = rate_unit
    cmap.rate_amount = rate_amount
    cmap.rate_currency = rate_currency
    session.commit()
Exemple #7
0
 def mutate(self, info, token, project_id, hiring_stage_id):
     verify_admin(token)
     session = get_session()
     project = get_project_by_id(session, project_id)
     if not project:
         raise InvalidRequest("Project not found")
     update_project_settings(session, project_id, hiring_stage_id)
     session.commit()
     session.refresh(project)
     session.close()
     return EditMasterProjectSettings(master_project=MasterProject(project))
Exemple #8
0
 def mutate(self, info, token, project_id, client_id, stakeholder_id):
     verify_admin(token)
     session = get_session()
     project = get_project_by_id(session, project_id)
     if not project:
         raise InvalidRequest("Project not found")
     map_project_client(session, project_id, client_id, stakeholder_id)
     session.commit()
     session.refresh(project)
     session.close()
     return AddMasterProjectClient(master_project=MasterProject(project))
Exemple #9
0
 def mutate(self, info, *args, **kwargs):
     verify_admin(kwargs['token'])
     session = get_session()
     project = get_project_by_id(session, kwargs['project_id'])
     if not project:
         raise InvalidRequest("Project not found")
     add_project_resourcing(session, **kwargs)
     session.commit()
     session.refresh(project)
     session.close()
     return AddMasterProjectLocation(master_project=MasterProject(project))
Exemple #10
0
 def mutate(self, info, token, project_id, scale_ids, criteria_ids):
     verify_admin(token)
     session = get_session()
     project = get_project_by_id(session, project_id)
     if not project:
         raise InvalidRequest("Project not found")
     set_project_criterias(session, project_id, criteria_ids)
     set_project_scales(session, project_id, scale_ids)
     session.commit()
     session.close()
     return EditMasterProjectFeedback(
         feedback_form=ProjectFeedback(project_id=project_id, token=token))
Exemple #11
0
    def get_attributes(self, session, map_name):
        if map_name not in MasterProjectAttributeMap.MAP:
            raise InvalidRequest(
                "attribute type {} not supported".format(map_name))
        table = MasterProjectAttributeMap.MAP[map_name]

        map_ids = [
            m.map_id
            for m in session.query(MasterProjectAttributeMap).filter_by(
                map_name=map_name, project_id=self.id).all()
        ]
        return session.query(table).filter(table.id.in_(map_ids)).all()
Exemple #12
0
 def mutate(self, info, token, project_id, links):
     verify_admin(token)
     session = get_session()
     project = get_project_by_id(session, project_id)
     if not project:
         raise InvalidRequest("Project not found")
     clear_project_scope_files(session, project_id)
     for link in links:
         add_project_scope_file(session, project_id, link)
     session.commit()
     session.refresh(project)
     session.close()
     return AddMasterProjectLocation(
         master_project=MasterProject.detail(token=token, id=project_id))
def add_freelancer_note(session,
                        freelancer_id,
                        admin_id,
                        note,
                        project_id=None):
    if not session.query(FreelancerModel).filter_by(id=freelancer_id).scalar():
        raise InvalidRequest("Freelancer id does not exist")
    fnote = FreelancerNoteModel(freelancer_id=freelancer_id,
                                admin_id=admin_id,
                                note=note)
    if project_id:
        fnote.project_id = project_id
    session.add(fnote)
    session.commit()
Exemple #14
0
 def mutate(self, info, token, project_id, docs):
     verify_admin(token)
     session = get_session()
     project = get_project_by_id(session, project_id)
     if not project:
         raise InvalidRequest("Project not found")
     clear_project_scope_links(session, project_id)
     for doc in docs:
         add_project_scope_link(session, project_id, doc['document_name'],
                                doc['link'], doc['is_scope'])
     session.commit()
     session.refresh(project)
     session.close()
     return AddMasterProjectLocation(
         master_project=MasterProject.detail(token=token, id=project_id))
def add_project_candidate(session,
                          project_id,
                          freelancer_id,
                          stage="Longlist"):
    if not session.query(MasterProjectModel).filter_by(id=project_id).scalar():
        raise InvalidRequest("Project id does not exist")
    pc = session.query(ProjectCandidateMapModel).filter_by(
        project_id=project_id, freelancer_id=freelancer_id).scalar()
    if not pc:
        pc = ProjectCandidateMapModel(project_id=project_id,
                                      freelancer_id=freelancer_id,
                                      stage=stage)
        session.add(pc)
        session.flush()
    return pc.id
Exemple #16
0
 def mutate(self, info, token, project_ids, freelancer_id):
     verify_admin(token)
     session = get_session()
     for project_id in project_ids:
         project = get_project_by_id(session, project_id)
         if not project:
             raise InvalidRequest(
                 "Project id {} not found".format(project_id))
     add_project_candidates(session, project_ids, freelancer_id)
     session.commit()
     projects = ProjectCandidate.freelancer_projects(
         token=token, freelancer_id=freelancer_id)
     session.close()
     return AddMasterProjectCandidate(candidates=[
         p for p in projects if p.obj.project_id in project_ids
     ])
def edit_project_candidate(session, candidate_id, **kwargs):
    candidates = get_candidates_with_id(session, [candidate_id])
    if not candidates:
        raise InvalidRequest("candidate id doesnt exist")
    for candidate in candidates:
        for key, val in kwargs.items():
            setattr(candidate, key, val)
            freelancer = session.query(FreelancerModel).filter_by(
                id=candidate.freelancer_id).first()
            if kwargs['stage'] == "Longlist":
                freelancer.interview_status = "Pending"
        try:
            from utils.index import insert_freelancer
            insert_freelancer(candidate.freelancer_id)
        except:
            print("failted to re index {}".format(candidate.freelancer_id))

    session.flush()
Exemple #18
0
    def update_attributes(self, session, map_name, map_values):
        print(map_name, map_values)
        if map_name not in MasterProjectAttributeMap.MAP:
            raise InvalidRequest(
                "attribute type {} not supported".format(map_name))
        table = MasterProjectAttributeMap.MAP[map_name]

        session.query(MasterProjectAttributeMap).filter_by(
            map_name=map_name, project_id=self.id).delete()
        for value in map_values:
            map_objs = session.query(table).filter_by(name=value).all()
            if not map_objs:
                map_obj = table(name=value)
                print(table, value, map_obj)
                session.add(map_obj)
                session.flush()
            else:
                map_obj = map_objs[0]
            a = MasterProjectAttributeMap(map_name=map_name,
                                          map_id=map_obj.id,
                                          project_id=self.id)
            session.add(a)
        session.flush()
Exemple #19
0
    def mutate(self, info, *args, **kwargs):
        token = kwargs.pop('token')
        if kwargs.get('project_type', "") == 'freelance' and not kwargs.get(
                'no_of_freelancers', None):
            raise InvalidRequest("Number of freelancers not provided")
        if 'min_years_experience' in kwargs and 'max_years_experience' in kwargs:
            if kwargs['min_years_experience'] >= kwargs['max_years_experience']:
                raise InvalidRequest(
                    "Max experience required should be greater than min experience"
                )

        expertise = kwargs.pop('expertise', [])
        if expertise == "":
            expertise = []
        sectors = kwargs.pop('sectors', [])
        if sectors == "":
            sectors = []
        stakeholders = kwargs.pop('stakeholder_ids', [])
        member_ids = kwargs.pop('member_ids', [])
        director_ids = kwargs.pop('director_ids', [])
        scope_files = kwargs.pop('scope_files', [])
        scope_links = kwargs.pop('scope_links', [])
        location = kwargs.pop('location', None)
        user = verify_admin(token)
        session = get_session()

        # if len(scope_files) == 0 and len(scope_links) == 0:
        #     raise InvalidRequest("A project scope link or file is required")
        if 'id' in kwargs:
            project = get_project_by_id(session, kwargs['id'])
            project.modified_at = datetime.datetime.utcnow()

            if 'project_start_date' in kwargs:
                project.project_start_date = kwargs.pop('project_start_date')
            for key in kwargs:
                setattr(project, key, kwargs[key])
            if 'expertise' in kwargs:
                project.update_attributes(session, 'expertise', expertise)
            if 'sector' in kwargs:
                project.update_attributes(session, 'sector', sectors)
        else:
            project = MasterProjectModel(**kwargs)
            project.admin_id = user.id
            project.modified_at = datetime.datetime.utcnow()

            if 'project_start_date' in kwargs:
                project.project_start_date = kwargs.pop('project_start_date')
            session.add(project)
            session.flush()
            project.update_attributes(session, 'expertise', expertise)
            project.update_attributes(session, 'sector', sectors)

        clear_project_scope_files(session, project.id)
        clear_project_scope_links(session, project.id)
        clear_project_stakeholders(session, project.id)
        clear_project_members(session, project.id)
        clear_project_directors(session, project.id)
        for f in scope_files:
            add_project_scope_file(session, project.id, f)
        for f in scope_links:
            add_project_scope_link(session, project.id, f['name'], f['link'],
                                   f['is_scope'])
        for s in stakeholders:
            add_stakeholder(session, project.id, s)
        for t in member_ids:
            add_team_member(session, project.id, t)
        for d in director_ids:
            add_director(session, project.id, d)

        project.project_status = kwargs[
            'project_status'] if 'project_status' in kwargs else "Market Scan"

        if location:
            project.location_id = add_place(session, location)
            project.city = location.city
            project.country = location.country
        project = get_project_by_id(session, project.id)
        session.commit()
        index_project(project.id)
        return AddMasterProject(project=MasterProject(project))