Beispiel #1
0
    def delete_domain(id: int):
        if not is_teacher():
            return ERRORS.INVALID_CREDENTIALS

        d: Domaine = Domaine.query.filter_by(id_domaine=id).one_or_none()

        if not d:
            return ""

        other_domain: Domaine = Domaine.query.filter_by(
            domaine="other").one_or_none()
        domain_id = None

        if other_domain:
            domain_id = other_domain.id_domaine

            if other_domain.id_domaine == id:

                return ERRORS.BAD_REQUEST

        Stage.query.filter_by(id_domaine=id).update({"id_domaine": domain_id})
        Emploi.query.filter_by(id_domaine=id).update({"id_domaine": domain_id})

        db_session.delete(d)
        db_session.commit()

        return ""
Beispiel #2
0
    def merge_companies():
        if not is_teacher():
            return ERRORS.INVALID_CREDENTIALS

        r = get_request()

        if not r.is_json:
            return ERRORS.BAD_REQUEST

        data = r.json

        if not {'main', 'children'} <= set(data):
            return ERRORS.MISSING_PARAMETERS

        main, children = data['main'], data['children']

        if type(main) is not int or type(children) is not list:
            return ERRORS.BAD_REQUEST

        main_company: Entreprise = Entreprise.query.filter_by(
            id_entreprise=main).one_or_none()

        if not main_company:
            return ERRORS.COMPANY_NOT_FOUND

        children_companies: List[Entreprise] = []
        for c in children:
            if type(c) is not int:
                return ERRORS.BAD_REQUEST

            ent = Entreprise.query.filter_by(id_entreprise=c).one_or_none()
            if not ent:
                return ERRORS.COMPANY_NOT_FOUND

            children_companies.append(ent)

        # For each job/internship relied to children_companies, set main_company
        for c in children_companies:
            Emploi.query.filter_by(id_entreprise=c.id_entreprise).update(
                {'id_entreprise': main_company.id_entreprise})
            Stage.query.filter_by(id_entreprise=c.id_entreprise).update(
                {'id_entreprise': main_company.id_entreprise})

        # Delete every children company
        for c in children_companies:
            Contact.query.filter_by(id_entreprise=c.id_entreprise).update(
                {'id_entreprise': main_company.id_entreprise})
            db_session.delete(c)

        db_session.commit()
        return ""
Beispiel #3
0
    def merge_domains():
        if not is_teacher():
            return ERRORS.INVALID_CREDENTIALS

        r = get_request()

        if not r.is_json:
            return ERRORS.BAD_REQUEST

        data = r.json

        if not {'main', 'children'} <= set(data):
            return ERRORS.MISSING_PARAMETERS

        main, children = data['main'], data['children']

        if type(main) is not int or type(children) is not list:
            return ERRORS.BAD_REQUEST

        main_domaine: Domaine = Domaine.query.filter_by(
            id_domaine=main).one_or_none()

        if not main_domaine:
            return ERRORS.DOMAIN_NOT_FOUND

        children_domains: List[Domaine] = []
        for c in children:
            if type(c) is not int:
                return ERRORS.BAD_REQUEST

            ent = Domaine.query.filter_by(id_domaine=c).one_or_none()
            if not ent:
                return ERRORS.DOMAIN_NOT_FOUND

            children_domains.append(ent)

        # For each domain relied to children_domains, set main_domaine
        for c in children_domains:
            Stage.query.filter_by(id_domaine=c.id_domaine).update(
                {'id_domaine': main_domaine.id_domaine})
            Emploi.query.filter_by(id_domaine=c.id_domaine).update(
                {'id_domaine': main_domaine.id_domaine})

        # Delete every children domain
        for c in children_formations:
            db_session.delete(c)

        db_session.commit()
        return ""
Beispiel #4
0
    def merge_formations():
        if not is_teacher():
            return ERRORS.INVALID_CREDENTIALS

        r = get_request()

        if not r.is_json:
            return ERRORS.BAD_REQUEST

        data = r.json

        if not {'main', 'children'} <= set(data):
            return ERRORS.MISSING_PARAMETERS

        main, children = data['main'], data['children']

        if type(main) is not int or type(children) is not list:
            return ERRORS.BAD_REQUEST

        main_formation: Formation = Formation.query.filter_by(
            id_form=main).one_or_none()

        if not main_formation:
            return ERRORS.FORMATION_NOT_FOUND

        children_formations: List[Formation] = []
        for c in children:
            if type(c) is not int:
                return ERRORS.BAD_REQUEST

            ent = Formation.query.filter_by(id_form=c).one_or_none()
            if not ent:
                return ERRORS.FORMATION_NOT_FOUND

            children_formations.append(ent)

        # For each student relied to children_formations, set main_formation
        for c in children_formations:
            Etudiant.query.filter_by(reorientation=c.id_form).update(
                {'reorientation': main_formation.id_form})
            Etudiant.query.filter_by(cursus_anterieur=c.id_form).update(
                {'cursus_anterieur': main_formation.id_form})

        # Delete every children company
        for c in children_formations:
            db_session.delete(c)

        db_session.commit()
        return ""
Beispiel #5
0
    def delete_contact(id: int):
        if not is_teacher():
            return ERRORS.INVALID_CREDENTIALS

        c = Contact.query.filter_by(id_contact=id).one_or_none()

        if not c:
            return ""

        Emploi.query.filter_by(id_contact=id).update({"id_contact": None})
        Stage.query.filter_by(id_contact=id).update({"id_contact": None})

        db_session.delete(c)
        db_session.commit()

        return ""
Beispiel #6
0
    def delete_company(id: int):
        if not is_teacher():
            return ERRORS.INVALID_CREDENTIALS

        c: Entreprise = Entreprise.query.filter_by(
            id_entreprise=id).one_or_none()

        if not c:
            return ""

        # Delete all manuel
        Stage.query.filter_by(id_entreprise=id).delete()
        Emploi.query.filter_by(id_entreprise=id).delete()
        Contact.query.filter_by(id_entreprise=id).delete()

        db_session.delete(c)
        db_session.commit()

        return ""
Beispiel #7
0
    def delete_job(id: int):
        job: Emploi = Emploi.query.filter_by(id_emploi=id).one_or_none()

        if job is None:
            return ""  # 200 OK deleted

        stu = get_student_or_none()

        if not stu:
            return ERRORS.STUDENT_NOT_FOUND

        if not is_teacher() and stu.id_etu != job.id_etu:
            return ERRORS.INVALID_CREDENTIALS

        # Properly delete job (maybe cascade is not working)
        stu.refresh_update()
        db_session.delete(job)
        db_session.commit()

        return ""
Beispiel #8
0
  def invalidate_token():
    r = get_request()
    token = r.headers.get('Authorization').replace('Bearer ', '', 1)

    if is_teacher():
      Token.query.filter_by(token=token).delete()
      db_session.commit()
      return ""
    else:
      current_etu_id = get_user().id_etu
      t: Token = Token.query.filter_by(token=token).one_or_none()

      if not t:
        return ERRORS.NOT_FOUND

      if t.id_etu == current_etu_id:
        db_session.delete(t)
        db_session.commit()
      else:
        return ERRORS.INVALID_CREDENTIALS
Beispiel #9
0
  def delete_internship(id: int):
    internship: Stage = Stage.query.filter_by(id_stage=id).one_or_none()

    if internship is None:
      return "" # 200 OK deleted

    stu = get_student_or_none()

    if not stu:
      return ERRORS.STUDENT_NOT_FOUND

    if not is_teacher() and stu.id_etu != internship.id_etu:
      return ERRORS.INVALID_CREDENTIALS

    # Properly delete internship (maybe cascade is not working)
    stu.refresh_update()
    db_session.delete(internship)
    db_session.commit()

    return ""
def deleteObjectAttributes(userId, attributeId):
    objectAttribute = getSingleObjectAttribute(userId, int(attributeId))
    if objectAttribute:
        db_session.delete(objectAttribute)
        db_session.commit()
Beispiel #11
0
def deleteRoute(userId, routeId):
    routeGroup = getRoute(userId, {'id':routeId})
    if routeGroup:
        db_session.delete(routeGroup)
        db_session.commit()