comment set rols for users

This commit is contained in:
Cayo Puigdefabregas 2024-02-05 14:54:00 +01:00
parent 5c02b424c1
commit 95700e7ba4
3 changed files with 25 additions and 21 deletions

View File

@ -8,12 +8,13 @@ def register_user(email, password, rols="Operator"):
# rols = 'Issuer, Operator, Witness, Verifier'
user = User.query.filter_by(email=email).one()
token_dlt = user.set_new_dlt_keys(password)
result = user.allow_permitions(api_token=token_dlt, rols=rols)
rols = user.get_rols(token_dlt=token_dlt)
rols = [k for k, v in rols]
user.rols_dlt = json.dumps(rols)
# token_dlt = user.set_new_dlt_keys(password)
# result = user.allow_permitions(api_token=token_dlt, rols=rols)
# rols = user.get_rols(token_dlt=token_dlt)
# rols = [k for k, v in rols]
# user.rols_dlt = json.dumps(rols)
db.session.commit()
# db.session.commit()
return result, rols
# return result, rols
return

View File

@ -5,5 +5,5 @@ from ereuse_devicehub.resources.user.models import User
def set_dlt_user(email, password):
u = User.query.filter_by(email=email).one()
api_token = u.set_new_dlt_keys(password)
u.allow_permitions(api_token)
# u.allow_permitions(api_token)
db.session.commit()

View File

@ -140,22 +140,25 @@ class User(UserMixin, Thing):
self.api_keys_dlt = encrypt(password, data)
def allow_permitions(self, api_token=None, rols="Operator"):
if 'dpp' not in app.blueprints.keys():
return
# Is discontinued over IOTA branch
return
if not api_token:
api_token = session.get('token_dlt', '.')
target_user = api_token.split(".")[0]
keyUser1 = app.config.get('API_DLT_TOKEN')
api_dlt = app.config.get('API_DLT')
if not keyUser1 or not api_dlt:
return
# if 'dpp' not in app.blueprints.keys():
# return
apiUser1 = API(api_dlt, keyUser1, "ethereum")
# if not api_token:
# api_token = session.get('token_dlt', '.')
# target_user = api_token.split(".")[0]
# keyUser1 = app.config.get('API_DLT_TOKEN')
# api_dlt = app.config.get('API_DLT')
# if not keyUser1 or not api_dlt:
# return
for rol in rols.split(","):
result = apiUser1.issue_credential(rol.strip(), target_user)
return result
# apiUser1 = API(api_dlt, keyUser1, "ethereum")
# for rol in rols.split(","):
# result = apiUser1.issue_credential(rol.strip(), target_user)
# return result
def get_rols_dlt(self):
return json.loads(self.rols_dlt)