You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

53 regels
1.6 KiB

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