Skip to content

Commit

Permalink
make mtd sync work
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquesfize committed Jul 2, 2024
1 parent 8fe5093 commit bd40158
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
5 changes: 4 additions & 1 deletion backend/geonature/core/auth/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from geonature.utils.errors import CasAuthentificationError
from geonature.utils.env import db

from pypnusershub.auth.auth_manager import auth_manager


routes = Blueprint("gn_auth", __name__, template_folder="templates")
log = logging.getLogger()
Expand Down Expand Up @@ -78,7 +80,8 @@ def insert_user_and_org(info_user):
"email": info_user["email"],
"active": True,
}
user_info = insert_or_update_role(user_info)
user_ = User(**user_info)
user_info = insert_or_update_role(user_, auth_manager.get_provider("local_provider"), "email")
user = db.session.get(User, user_id)
if not user.groups:
if not current_app.config["CAS"]["USERS_CAN_SEE_ORGANISM_DATA"] or organism_id is None:
Expand Down
16 changes: 10 additions & 6 deletions backend/geonature/core/gn_meta/mtd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def add_unexisting_digitizer(id_digitizer):
:param id_digitizer: as id role from meta info
"""
if (
not db.session.scalars(
select(func.count("*").select_from(User).filter_by(id_role=id_digitizer).limit(1))
not db.session.execute(
select(func.count("*")).select_from(User).filter_by(id_role=id_digitizer).limit(1)
).scalar_one()
> 0
):
Expand Down Expand Up @@ -145,12 +145,14 @@ def process_af_and_ds(af_list, ds_list, id_role=None):
for af in af_list:
actors = af.pop("actors")
with db.session.begin_nested():
start_add_user_time = time.time()
import time as t

start_add_user_time = t.time()
if not id_role:
add_unexisting_digitizer(af["id_digitizer"])
else:
add_unexisting_digitizer(id_role)
user_add_total_time += time.time() - start_add_user_time
user_add_total_time += t.time() - start_add_user_time
af = sync_af(af)
associate_actors(
actors,
Expand All @@ -165,12 +167,14 @@ def process_af_and_ds(af_list, ds_list, id_role=None):
actors = ds.pop("actors")
# CREATE DIGITIZER
with db.session.begin_nested():
start_add_user_time = time.time()
import time as t

start_add_user_time = t.time()
if not id_role:
add_unexisting_digitizer(ds["id_digitizer"])
else:
add_unexisting_digitizer(id_role)
user_add_total_time += time.time() - start_add_user_time
user_add_total_time += t.time() - start_add_user_time
ds = sync_ds(ds, list_cd_nomenclature)
if ds is not None:
associate_actors(actors, CorDatasetActor, "id_dataset", ds.id_dataset)
Expand Down
2 changes: 1 addition & 1 deletion backend/geonature/core/gn_meta/mtd/mtd_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def add_or_update_organism(uuid, nom, email):
"""
# Test if actor already exists to avoid nextVal increase
org_exist = DB.session.execute(
select(exists().select_from(BibOrganismes).filter_by(uuid_organisme=uuid))
select(exists().select_from(BibOrganismes).where(BibOrganismes.uuid_organisme == uuid))
).scalar_one()

if org_exist:
Expand Down

0 comments on commit bd40158

Please sign in to comment.