Example #1
0
    def mutate(root, info, datetime_job):
        params = datetime_job["params"]

        mlist = qual_client.get_j4u_mailinglist()
        mlist_id = mlist["id"]
        distrib = qual_client.create_distribution(
            params["surveyId"],
            mlist_id,
            parse(params["surveyEnd"]),
            datetime_job["name"],
        )
        distrib_id = distrib["id"]
        params["distribId"] = distrib_id

        datetime_job["execution_date"] = (
            datetime_job["execution_date"]
            .replace(tzinfo=timezone.utc)
            .astimezone(tz=None)
        )

        new_datetime_job = DatetimeJobModel(**datetime_job)

        db_session.add(new_datetime_job)
        db_session.commit()
        return CreateDatetimeJob(datetime_job=new_datetime_job)
Example #2
0
    def mutate(root, info, group_id, group_data):
        group = GroupModel.query.get(group_id)
        for k, v in group_data.items():
            setattr(group, k, v)

        db_session.add(group)
        db_session.commit()
        group = GroupModel.query.get(group_id)
        return UpdateGroupConfig(group=group)
Example #3
0
    def mutate(root, info, activity):
        activity = enrich(activity, info.context.user)

        res = ActivityModel(**activity)

        db_session.add(res)
        db_session.commit()

        return CreateActivity(activity=res)
Example #4
0
    def mutate(root, info, cohort_id, cohort_data):
        cohort = CohortModel.query.get(cohort_id)
        print(cohort)
        for k, v in cohort_data.items():
            setattr(cohort, k, v)

        db_session.add(cohort)
        db_session.commit()

        print(cohort)
        print(cohort.name)
        return UpdateCohort(cohort=cohort)
Example #5
0
    def mutate(root, info, token):
        try:
            user_id = extract_from_token(token)["user_id"]
        except jwt.DecodeError:
            raise token_errors.InvalidVerificationLink()
        except jwt.ExpiredSignatureError:
            raise token_errors.ExpiredVerificationLink()

        user = UserModel.query.filter(UserModel.id == int(user_id)).first()
        user.verified = True
        db_session.add(user)
        db_session.commit()

        return VerifyUser(verified=True)
Example #6
0
def to_db(df, configs):
    name_to_config_id = {x.engine_name: x.id for x in configs}

    users = User.query.filter(User.survey_id.in_(df.index.tolist()),
                              User.form_done == False).all()
    print(f"Updating {len(users)} users ...")
    for user in users:
        features = df.loc[str(user.survey_id)]
        features = list(zip(features.index, features))
        features = [
            Feature(feature_config_id=name_to_config_id[k],
                    user_id=user.id,
                    value=v) for k, v in features
        ]
        user.form_done = True
        user.form_done_at = date.today()
        db_session.add(user)
        db_session.bulk_save_objects(features)
        db_session.commit()
    print(f"Done updating.")
    return users
Example #7
0
    def mutate(root, info, user, token):
        try:
            group_id = extract_from_token(token)["group_id"]
        except jwt.DecodeError:
            raise token_errors.InvalidSignupLink()
        except jwt.ExpiredSignatureError:
            raise token_errors.ExpiredSignupLink()

        try:
            group = GroupModel.query.filter(GroupModel.id == group_id).first()
            new_user = UserModel(**user, group=group)
            db_session.add(new_user)
            db_session.flush()

            verification_token = create_auth_token(new_user.id, 3600 * 24 * 1)
            verification_url = f"{config.APP_URL}/verify?token={verification_token}"

            send_mail(
                to=[new_user.email],
                subject="J4U verification du compte",
                template="verification",
                link=verification_url,
            )
            qual_client.create_contact(new_user.email)
            db_session.commit()
            return CreateUser(user=new_user)

        except SQLAlchemyError as err:
            error = parse_db_error(err)
            raise error
        except ContactAlreadyExists as err:
            print(err)
            db_session.commit()
            return CreateUser(user=new_user)
        except Exception as err:
            raise err
Example #8
0
def seed_testing():
    print("Start seeding mysql ...")

    fcs = []
    for x in features_configs:
        fc = FeatureConfig(**x)
        fcs.append(fc)
    db_session.add_all(fcs)
    db_session.flush()

    groups = []
    for (name, baseline_id), (_, cruiser_id) in zip(baseline_ids.items(),
                                                    cruiser_ids.items()):
        g = Group(
            name=name,
            baseline_id=baseline_id,
            cruiser_id=cruiser_id,
        )
        groups.append(g)

    admin = User(
        civilite="M",
        role="ADMIN",
        first_name="admin",
        last_name="nimda",
        birth_date="2019-01-01",
        phone="0658062948",
        email="*****@*****.**",
        password="******",
        verified=True,
        group=groups[2],
    )

    group_based_users = []
    group_based_features = []
    for group in groups:
        for i, month in it.product(range(2), range(1, 4)):
            group_mail = "".join(
                [x for x in group.name.lower() if x.isalnum()])
            day = i + 5
            form_done_at = f"2019-{month}-{day}"
            email = f"{group_mail}-{month}-{day}@yopmail.com"
            print(email)

            # qual_client.create_contact(email)

            user = User(
                civilite="M",
                role="USER",
                first_name="John",
                last_name="Doe",
                birth_date="2000-01-01",
                phone=str(random.randint(1e6, 1e7)),
                email=email,
                password="******",
                survey_id=str(random.randint(1e8, 1e9)),
                verified=True,
                form_done=True,
                form_done_at=form_done_at,
                group=group,
            )
            db_session.add(user)
            db_session.flush()
            for fc in fcs:
                f = Feature(user_id=user.id, feature_config_id=fc.id, value=3)
                group_based_features.append(f)

    db_session.add(admin)
    db_session.add_all(group_based_users)
    db_session.flush()
    db_session.bulk_save_objects(group_based_features)

    db_session.add_all(groups)
    db_session.commit()
    print("Seeding done.")
Example #9
0
    def mutate(root, info, id):
        DatetimeJobModel.query.filter_by(id=id).delete()
        db_session.commit()

        return DeleteDatetimeJob(ok=True)
Example #10
0
    def mutate(root, info, cohort_data):
        cohort = CohortModel(**cohort_data)

        db_session.add(cohort)
        db_session.commit()
        return CreateCohort(cohort=cohort)