From b57a4de94d002f187230110b3f6d4c31c2d9f382 Mon Sep 17 00:00:00 2001
From: Anton Bagliy <taccessviolation@gmail.com>
Date: Tue, 23 Apr 2019 16:54:38 +0300
Subject: [PATCH] FIX: token table #430

---
 db/postgresql/issue430_authtoken_delete.sql   | 19 +++++++++++++++++++
 .../classes/Controller/Office/AuthTokens.php  |  2 +-
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 db/postgresql/issue430_authtoken_delete.sql

diff --git a/db/postgresql/issue430_authtoken_delete.sql b/db/postgresql/issue430_authtoken_delete.sql
new file mode 100644
index 000000000..13c9a7106
--- /dev/null
+++ b/db/postgresql/issue430_authtoken_delete.sql
@@ -0,0 +1,19 @@
+DROP FUNCTION IF EXISTS public.getauthtokens(paccountid integer);
+CREATE OR REPLACE FUNCTION public.getauthtokens(paccountid integer)
+ RETURNS TABLE("AccountID" integer, "Created" timestamp without time zone, "Accessed" timestamp without time zone, "Mask" integer, "Token" character varying)
+ LANGUAGE sql
+AS $function$
+-- select * from public.getauthtokens(:paccountid 	-- put the paccountid parameter value instead of 'paccountid' (int4));
+-- если вызывать select  public.getauthtokens(...); выдает таблицу с одним солбцом - все данные склены в список
+    SELECT accountID as "AccountID",
+           created as "Created",
+           accessed as "Accessed",
+           mask as "Mask",
+           token as "Token"
+    FROM auth_tokens
+    INNER JOIN accounts ON accounts.ID = auth_tokens.AccountID
+    WHERE
+        auth_tokens.AccountID = pAccountID OR
+        pAccountID = 0
+    ORDER BY auth_tokens.Created DESC;
+$function$;
diff --git a/~dev_rating/application/classes/Controller/Office/AuthTokens.php b/~dev_rating/application/classes/Controller/Office/AuthTokens.php
index 5d87b9070..4efc1939b 100644
--- a/~dev_rating/application/classes/Controller/Office/AuthTokens.php
+++ b/~dev_rating/application/classes/Controller/Office/AuthTokens.php
@@ -4,7 +4,7 @@ class Controller_Office_AuthTokens extends Controller_Environment_Office
 {
     public function action_index() {
         $this->twig->set([
-            'Tokens' => Model_Account::getAuthTokens(),
+            'Tokens' => Model_Account::getAuthTokens($this->user["ID"]),
         ])->set_filename(static::OFFICE . 'tokens');
     }
 }
\ No newline at end of file
-- 
GitLab