Commit e43b852e authored by Jonathan Schaeffer's avatar Jonathan Schaeffer
Browse files

Change users'table name (resif_users)

parent 620e73e6
Pipeline #69149 passed with stage
in 1 minute and 24 seconds
...@@ -55,19 +55,19 @@ def register_privileges(login, tokendict): ...@@ -55,19 +55,19 @@ def register_privileges(login, tokendict):
- Connect to PRIVILEGEDB - Connect to PRIVILEGEDB
- For each fdsn reference, insert the privilege in the access table if not already there - For each fdsn reference, insert the privilege in the access table if not already there
""" """
fdsn_memberships = [] authorizations = []
for em in tokendict['memberof'].split(';'): for em in tokendict['memberof'].split(';'):
application.logger.debug("EPOS membership: "+em) application.logger.debug("EPOS membership: "+em)
if em in application.config['EPOS_FDSN_MAP']: if em in application.config['EPOS_FDSN_MAP']:
application.logger.debug(" ... is in epos fdsn map") application.logger.debug(" ... is in epos fdsn map")
fdsn_memberships.append(application.config['EPOS_FDSN_MAP'][em]) authorizations.append(application.config['EPOS_FDSN_MAP'][em])
# TODO Now get localy defined autorizations, from email adress # Now get localy defined autorizations, from email adress
# 1. Chercher tous les users ayant cet email dans la table resifAuth.users # 1. Chercher tous les users ayant cet email dans la table resifAuth.users
# select login from users where email = '' and expires_at is NULL # select login from users where email = '' and expires_at is NULL
# 2. Pour chaque login récupéré, prendre la liste des réseaux autorisés dans resifInv # 2. Pour chaque login récupéré, prendre la liste des réseaux autorisés dans resifInv
# select network_id, network, start_year, end_year from aut_user where name=%(login)s # select network_id, network, start_year, end_year from resif_users where name=%(login)s
# Ajouter ces tuples à fdsn_membership pour que les autorisations soient accordées à cet utilisateur # Ajouter ces tuples à membership pour que les autorisations soient accordées à cet utilisateur
# #
# #
# Step 1 : # Step 1 :
...@@ -85,7 +85,7 @@ def register_privileges(login, tokendict): ...@@ -85,7 +85,7 @@ def register_privileges(login, tokendict):
permanent_logins.append(l[0]) permanent_logins.append(l[0])
# Step 2 # Step 2
# Maintenant, on enregistre les memberships # Maintenant, on enregistre les authorizations
try: try:
conn = psycopg2.connect(dbname= application.config['RESIFINV_PGDATABASE'], conn = psycopg2.connect(dbname= application.config['RESIFINV_PGDATABASE'],
port = application.config['RESIFINV_PGPORT'], port = application.config['RESIFINV_PGPORT'],
...@@ -103,16 +103,16 @@ def register_privileges(login, tokendict): ...@@ -103,16 +103,16 @@ def register_privileges(login, tokendict):
for l in permanent_logins: for l in permanent_logins:
application.logger.debug("Searching for privileges on login %s", l) application.logger.debug("Searching for privileges on login %s", l)
cur.execute("select network_id, network, start_year, end_year from aut_user where name=%s", (l,)) cur.execute("select network_id, network, start_year, end_year from resif_users where name=%s", (l,))
for ref in cur: for ref in cur:
fdsn_memberships.append({'networkid': ref[0], 'networkcode': ref[1], 'startyear': ref[2], 'endyear': ref[3] }) authorizations.append({'networkid': ref[0], 'networkcode': ref[1], 'startyear': ref[2], 'endyear': ref[3] })
if len(fdsn_memberships) == 0: if len(authorizations) == 0:
application.logger.debug("No membership for user %s", login) application.logger.debug("No membership for user %s", login)
return return
application.logger.debug("FDSN memberships: %s"%(fdsn_memberships)) application.logger.debug("FDSN authorizations: %s"%(authorizations))
# Get the network id # Get the network id
for ref in fdsn_memberships: for ref in authorizations:
ref['login'] = login ref['login'] = login
ref['expires_at'] = datetime.datetime.now()+datetime.timedelta(days=1) ref['expires_at'] = datetime.datetime.now()+datetime.timedelta(days=1)
application.logger.info(ref) application.logger.info(ref)
...@@ -129,7 +129,9 @@ def register_privileges(login, tokendict): ...@@ -129,7 +129,9 @@ def register_privileges(login, tokendict):
ref['networkid'] = cur.fetchone()[0] ref['networkid'] = cur.fetchone()[0]
application.logger.info("Inserting tupple in %s.eida_temp_users: %s", application.config['RESIFINV_PGDATABASE'], ref) application.logger.info("Inserting tupple in %s.eida_temp_users: %s", application.config['RESIFINV_PGDATABASE'], ref)
cur.execute(""" cur.execute("""
insert into eida_temp_users (network_id, network, start_year, end_year, name, expires_at) values (%(networkid)s, %(networkcode)s, %(startyear)s, %(endyear)s, %(login)s, %(expires_at)s) ON CONFLICT DO NOTHING; INSERT INTO eida_temp_users (network_id, network, start_year, end_year, name, expires_at)
VALUES (%(networkid)s, %(networkcode)s, %(startyear)s, %(endyear)s, %(login)s, %(expires_at)s)
ON CONFLICT DO NOTHING;
""", ref) """, ref)
conn.commit() conn.commit()
conn.close() conn.close()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment