Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

52 lignes
1.5 KiB

  1. import frappe
  2. from frappe import _
  3. import frappe.www.list
  4. no_cache = 1
  5. def get_context(context):
  6. if frappe.session.user == 'Guest':
  7. frappe.throw(_("You need to be logged in to access this page"), frappe.PermissionError)
  8. active_tokens = frappe.get_all("OAuth Bearer Token",
  9. filters=[["user", "=", frappe.session.user]],
  10. fields=["client"], distinct=True, order_by="creation")
  11. client_apps = []
  12. for token in active_tokens:
  13. creation = get_first_login(token.client)
  14. app = {
  15. "name": token.get("client"),
  16. "app_name": frappe.db.get_value("OAuth Client", token.get("client"), "app_name"),
  17. "creation": creation
  18. }
  19. client_apps.append(app)
  20. app = None
  21. if "app" in frappe.form_dict:
  22. app = frappe.get_doc("OAuth Client", frappe.form_dict.app)
  23. app = app.__dict__
  24. app["client_secret"] = None
  25. if app:
  26. context.app = app
  27. context.apps = client_apps
  28. def get_first_login(client):
  29. login_date = frappe.get_all("OAuth Bearer Token",
  30. filters=[["user", "=", frappe.session.user], ["client", "=", client]],
  31. fields=["creation"], order_by="creation", limit=1)
  32. login_date = login_date[0].get("creation") if login_date and len(login_date) > 0 else None
  33. return login_date
  34. @frappe.whitelist()
  35. def delete_client(client_id):
  36. active_client_id_tokens = frappe.get_all("OAuth Bearer Token", filters=[["user", "=", frappe.session.user], ["client","=", client_id]])
  37. for token in active_client_id_tokens:
  38. frappe.delete_doc("OAuth Bearer Token", token.get("name"), ignore_permissions=True)