ponymail-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject incubator-ponymail git commit: Convert utils to standard module with local functions
Date Wed, 14 Dec 2016 00:10:39 GMT
Repository: incubator-ponymail
Updated Branches:
  refs/heads/master 915a68d66 -> fd188dc4d


Convert utils to standard module with local functions

This reduces the namespace changes in the caller function
It also makes it easier to see where the methods are located

Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/fd188dc4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/fd188dc4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/fd188dc4

Branch: refs/heads/master
Commit: fd188dc4d736fe81397a3efa9922e9e487ec66c7
Parents: 915a68d
Author: Sebb <sebb@apache.org>
Authored: Wed Dec 14 00:10:13 2016 +0000
Committer: Sebb <sebb@apache.org>
Committed: Wed Dec 14 00:10:13 2016 +0000

----------------------------------------------------------------------
 site/api/atom.lua          |  9 ++++-----
 site/api/email.lua         |  2 +-
 site/api/lib/utils.lua     | 21 +++++++++++----------
 site/api/mbox.lua          |  4 ++--
 site/api/notifications.lua |  5 ++---
 site/api/preferences.lua   |  7 +++----
 site/api/source.lua        |  3 ++-
 site/api/stats.lua         |  5 ++---
 site/api/thread.lua        |  9 ++++-----
 9 files changed, 31 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/fd188dc4/site/api/atom.lua
----------------------------------------------------------------------
diff --git a/site/api/atom.lua b/site/api/atom.lua
index 17e5d9d..fdb92c4 100644
--- a/site/api/atom.lua
+++ b/site/api/atom.lua
@@ -22,8 +22,7 @@ local elastic = require 'lib/elastic'
 local user = require 'lib/user'
 local aaa = require 'lib/aaa'
 local cross = require 'lib/cross'
-
-require 'lib/utils'
+local utils = require 'lib/utils'
 
 local emls_thrd
 
@@ -129,7 +128,7 @@ function handle(r)
                     if rights then
                         rights = aaa.rights(r, account)
                     end
-                    canUse = canAccessDoc(email, rights)
+                    canUse = utils.canAccessDoc(email, rights)
                 end
             else
                 canUse = true
@@ -152,7 +151,7 @@ function handle(r)
         local doc = elastic.get("mbox", get.mid)
         if doc then
             -- make sure we have the real parent
-            local parent = findParent(r, doc, elastic)
+            local parent = utils.findParent(r, doc, elastic)
 
             -- we got the original email, now let's find and process all kids
             if parent then
@@ -166,7 +165,7 @@ function handle(r)
                             if not rights then
                                 rights = aaa.rights(r, account)
                             end
-                            canUse = canAccessDoc(doc, rights)
+                            canUse = utils.canAccessDoc(doc, rights)
                         end
                     else
                         canUse = true

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/fd188dc4/site/api/email.lua
----------------------------------------------------------------------
diff --git a/site/api/email.lua b/site/api/email.lua
index 14f419d..f59d300 100644
--- a/site/api/email.lua
+++ b/site/api/email.lua
@@ -69,7 +69,7 @@ function handle(r)
         -- Is this a private email? and if so, does the user have access to view it?
         if doc.private then
             if account then
-                canAccess = canAccessDoc(doc, aaa.rights(r, account))
+                canAccess = utils.canAccessDoc(doc, aaa.rights(r, account))
             else
                 r:puts(JSON.encode{
                     error = "You must be logged in to view this email"

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/fd188dc4/site/api/lib/utils.lua
----------------------------------------------------------------------
diff --git a/site/api/lib/utils.lua b/site/api/lib/utils.lua
index 8da74bc..7442312 100644
--- a/site/api/lib/utils.lua
+++ b/site/api/lib/utils.lua
@@ -17,14 +17,8 @@
 
 -- This is lib/utils.lua - utility methods
 
---[[
-This module is intended to be directly required by the caller
-and so should not have any global state.
-For this reason it cannot include other lib files such as elastic
-]]--
-
 -- find the original topic starter
-function findParent(r, doc, elastic)
+local function findParent(r, doc, elastic)
     local step = 0
     -- max 50 steps up in the hierarchy
     while step < 50 do
@@ -53,14 +47,14 @@ end
   returns the full lid, listname and the domain from "<listname.domain>"
    where listname cannot contain any "." chars
 ]]--
-function parseLid(lid)
+local function parseLid(lid)
     return lid:match("^<(([^.]+)%.(.-))>$")
 end
 
 
 -- does the user have the rights to access the mailing list?
 -- N.B. will fail if rights or list_raw are invalid
-function canAccessList(lid, rights)
+local function canAccessList(lid, rights)
     -- we don't need the name
     local flid, _ , domain = parseLid(lid)
     for _, v in pairs(rights) do
@@ -73,7 +67,7 @@ end
 
 -- does the user have the rights to access the document?
 -- N.B. will fail if doc is invalid; may fail if rights is invalid
-function canAccessDoc(doc, rights)
+local function canAccessDoc(doc, rights)
     if doc.private then
         return canAccessList(doc.list_raw, rights)
     else
@@ -89,3 +83,10 @@ end
     Also the functions do not check their parameters.
     This is because they may be called frequently.
 ]]--
+
+return {
+    findParent = findParent,
+    parseLid = parseLid,
+    canAccessList = canAccessList,
+    canAccessDoc = canAccessDoc
+}

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/fd188dc4/site/api/mbox.lua
----------------------------------------------------------------------
diff --git a/site/api/mbox.lua b/site/api/mbox.lua
index bd01364..5ce3c6a 100644
--- a/site/api/mbox.lua
+++ b/site/api/mbox.lua
@@ -21,7 +21,7 @@ local elastic = require 'lib/elastic'
 local cross = require 'lib/cross'
 local user = require 'lib/user'
 local aaa = require 'lib/aaa'
-require 'lib/utils'
+local utils = require 'lib/utils'
 
 local days = {
     31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 30, 31 
@@ -130,7 +130,7 @@ function handle(r)
             if v.private and listAccessible == nil then
                 -- we are dealing with a single list here so only need to check once
                 if account then
-                    listAccessible = canAccessList(lid, aaa.rights(r, account))
+                    listAccessible = utils.canAccessList(lid, aaa.rights(r, account))
                 else
                     listAccessible = false
                 end

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/fd188dc4/site/api/notifications.lua
----------------------------------------------------------------------
diff --git a/site/api/notifications.lua b/site/api/notifications.lua
index 35ea247..80abc72 100644
--- a/site/api/notifications.lua
+++ b/site/api/notifications.lua
@@ -23,8 +23,7 @@ local elastic = require 'lib/elastic'
 local aaa = require 'lib/aaa'
 local user = require 'lib/user'
 local cross = require 'lib/cross'
-
-require 'lib/utils'
+local utils = require 'lib/utils'
 
 function handle(r)
     r.content_type = "application/json"
@@ -62,7 +61,7 @@ function handle(r)
                   if not rights then
                       rights = aaa.rights(r, account)
                   end
-                  canUse = canAccessDoc(doc, rights)
+                  canUse = utils.canAccessDoc(doc, rights)
                 end
             else
                 canUse = true

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/fd188dc4/site/api/preferences.lua
----------------------------------------------------------------------
diff --git a/site/api/preferences.lua b/site/api/preferences.lua
index df1444b..f495947 100644
--- a/site/api/preferences.lua
+++ b/site/api/preferences.lua
@@ -24,8 +24,7 @@ local cross = require 'lib/cross'
 local smtp = require 'socket.smtp'
 local config = require 'lib/config'
 local aaa = require 'lib/aaa'
-
-require 'lib/utils'
+local utils = require 'lib/utils'
 
 --[[
 Get login details (if logged in), mail list counts and descriptions
@@ -321,9 +320,9 @@ Pony Mail - Email for Ponies and People.
         -- i.e. the user won't see the list name if it contains a single private mail they
cannot access
         for x,y in pairs (pdoc.aggregations.from.buckets) do
             local canAccess = false
-            local _, list, domain = parseLid(y.key:lower())
+            local _, list, domain = utils.parseLid(y.key:lower())
             if list and domain and #list > 0 and #domain > 2 then
-                canAccess = canAccessList(y.key:lower(), rights)
+                canAccess = utils.canAccessList(y.key:lower(), rights)
                 if not canAccess then
                     lists[domain] = lists[domain] or {}
                     lists[domain][list] = nil

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/fd188dc4/site/api/source.lua
----------------------------------------------------------------------
diff --git a/site/api/source.lua b/site/api/source.lua
index 7d6c728..f1a003c 100644
--- a/site/api/source.lua
+++ b/site/api/source.lua
@@ -21,6 +21,7 @@ local elastic = require 'lib/elastic'
 local aaa = require 'lib/aaa'
 local user = require 'lib/user'
 local cross = require 'lib/cross'
+local utils = require 'lib/utils'
 
 function handle(r)
     r.content_type = "text/plain"
@@ -40,7 +41,7 @@ function handle(r)
         if doc.private then
             local account = user.get(r)
             if account then
-                canAccess = canAccessDoc(doc, aaa.rights(r, account))
+                canAccess = utils.canAccessDoc(doc, aaa.rights(r, account))
             else
                 r:puts("You must be logged in to view this email")
                 return cross.OK

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/fd188dc4/site/api/stats.lua
----------------------------------------------------------------------
diff --git a/site/api/stats.lua b/site/api/stats.lua
index 70a5816..20b10d0 100644
--- a/site/api/stats.lua
+++ b/site/api/stats.lua
@@ -23,8 +23,7 @@ local user = require 'lib/user'
 local aaa = require 'lib/aaa'
 local config = require 'lib/config'
 local cross = require 'lib/cross'
-
-require 'lib/utils'
+local utils = require 'lib/utils'
 
 local days = {
     31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 30, 31 
@@ -587,7 +586,7 @@ function handle(r)
             end
             canUse = false
             if account then
-                canUse = canAccessDoc(email, rights)
+                canUse = utils.canAccessDoc(email, rights)
             end
         end
         if canUse then

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/fd188dc4/site/api/thread.lua
----------------------------------------------------------------------
diff --git a/site/api/thread.lua b/site/api/thread.lua
index b75ac41..cd78ec7 100644
--- a/site/api/thread.lua
+++ b/site/api/thread.lua
@@ -24,11 +24,10 @@ local aaa = require 'lib/aaa'
 local user = require 'lib/user'
 local cross = require 'lib/cross'
 local config = require 'lib/config'
+local utils = require 'lib/utils'
 
 local emls_thrd
 
-require 'lib/utils'
-
 -- anonymizer func
 local function anonymize(doc)
     if doc.from and doc.from ~= JSON.null and #doc.from > 0 then
@@ -59,7 +58,7 @@ local function fetchChildren(r, pdoc, c, biglist, rights, account)
         -- if we haven't seen this email before, check for its kids and add it to the bunch
         local canAccess = true
         if doc.private then
-            canAccess = canAccessDoc(doc, rights)
+            canAccess = utils.canAccessDoc(doc, rights)
         end
         
         if canAccess and (not biglist[doc['message-id']]) then
@@ -109,7 +108,7 @@ function handle(r)
         end
     end
     if get.timetravel then
-        doc = findParent(r, doc, elastic)
+        doc = utils.findParent(r, doc, elastic)
     end
     local doclist = {}
     
@@ -121,7 +120,7 @@ function handle(r)
         -- if private, can we access it?
         if doc.private then
             if account then
-                canAccess = canAccessDoc(doc, aaa.rights(r, account))
+                canAccess = utils.canAccessDoc(doc, aaa.rights(r, account))
             else
                 r:puts(JSON.encode{
                     error = "You must be logged in to view this email"


Mime
View raw message