summaryrefslogtreecommitdiff
path: root/sql/modules
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-12-02 23:24:27 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-12-02 23:24:27 +0000
commitecc87a1c586ead2042499eca21e0e14d726b5ce8 (patch)
treefce3f039df564c0980b4bd327e3bb33048f45522 /sql/modules
parenta581e9f50c6a4a22c8fbfd24348cd40835784d44 (diff)
Correcting behavior of session timeout to release locks and create new session.
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1928 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'sql/modules')
-rw-r--r--sql/modules/Payment.sql2
-rw-r--r--sql/modules/Roles.sql6
-rw-r--r--sql/modules/Session.sql43
3 files changed, 48 insertions, 3 deletions
diff --git a/sql/modules/Payment.sql b/sql/modules/Payment.sql
index afd4abcc..c39e6945 100644
--- a/sql/modules/Payment.sql
+++ b/sql/modules/Payment.sql
@@ -316,7 +316,7 @@ $$
DECLARE resultrow record;
BEGIN
FOR resultrow IN
- SELECT curr FROM ar
+ SELECT curr AS curr FROM ar
WHERE amount <> paid
OR paid IS NULL
AND in_account_class=2
diff --git a/sql/modules/Roles.sql b/sql/modules/Roles.sql
index 1425ff87..8ae539e9 100644
--- a/sql/modules/Roles.sql
+++ b/sql/modules/Roles.sql
@@ -1,3 +1,4 @@
+GRANT ALL ON SCHEMA public TO public; -- required for Pg 8.2
-- Contacts
CREATE ROLE lsmb_<?lsmb dbname ?>__read_contact
WITH INHERIT NOLOGIN;
@@ -1382,5 +1383,6 @@ grant select on menu_node, menu_attribute, menu_acl to public;
GRANT select on chart, gifi, country to public;
grant select on employee to public;
GRANT SELECT ON parts, partsgroup TO public;
- GRANT SELECT ON language TO public;
-GRANT SELECT ON business, exchangerate, shipto, tax TO public;
+ GRANT SELECT ON language, project TO public;
+GRANT SELECT ON business, exchangerate, department, shipto, tax TO public;
+
diff --git a/sql/modules/Session.sql b/sql/modules/Session.sql
new file mode 100644
index 00000000..a44ed924
--- /dev/null
+++ b/sql/modules/Session.sql
@@ -0,0 +1,43 @@
+CREATE OR REPLACE FUNCTION session_check(in_session_id int, in_token text)
+RETURNS session AS
+$$
+DECLARE out_row session%ROWTYPE;
+BEGIN
+ UPDATE session
+ SET last_used = now()
+ WHERE session_id = in_session_id
+ AND token = in_token
+ AND last_used > now() - (SELECT value FROM defaults
+ WHERE setting_key = 'timeout')::interval
+ AND users_id = (select id from users
+ where username = SESSION_USER);
+ IF FOUND THEN
+ SELECT * INTO out_row WHERE session_id = in_session_id;
+ ELSE
+ DELETE FROM SESSION
+ WHERE users_id IN (select id from users
+ where username = SESSION_USER);
+ -- the above query also releases all discretionary locks by the
+ -- session
+
+ IF NOT FOUND THEN
+ SELECT id FROM users WHERE username = SESSION_USER;
+ IF NOT FOUND THEN
+ RAISE EXCEPTION 'User Not Known';
+ END IF;
+
+ END IF;
+ INSERT INTO session(users_id, token, last_used, transaction_id)
+ SELECT id, md5(random()), now(), 0
+ FROM users WHERE username = SESSION_USER;
+ -- TODO-- remove transaction_id field from session table
+
+ SELECT * INTO out_row FROM session
+ WHERE session_id = currval('session_session_id_seq');
+ END IF;
+ RETURN out_row;
+END;
+$$ LANGUAGE PLPGSQL;
+
+COMMENT ON FUNCTION session_check(int, text) IS
+$$ Return code is 0 for failure, 1 for success. $$;