From 9e413af6933deb459bba3136b6617e0959245248 Mon Sep 17 00:00:00 2001 From: Ludovic Coues Date: Wed, 11 May 2016 15:37:16 +0200 Subject: [PATCH] provide more details about apps to template --- conf.json.example | 26 +++++++++++++++++++------- helpers.lua | 13 ++++++++----- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/conf.json.example b/conf.json.example index 84e5118..9eec6c9 100644 --- a/conf.json.example +++ b/conf.json.example @@ -17,14 +17,26 @@ "Email": "mail", "Name": "cn" }, - "users": { - "myuser": { - "example.com/myapp": "My App", - "example.com/myapp2": "My second App" + "apps": { + "app_id": { + "id": "app_id", + "name": "App Name", + "url": "example.com/app", + "description": "The app description" }, - "myuser2": { - "example.org/myapp": "My other domain App", - "example.com/myapp2": "My second App" + "second_app": { + "id": "second_app", + "name": "Another App", + "url": "example.org/that" } + }, + "users": { + "myuser": [ + "app_id", + "second_app" + ], + "myuser2": [ + "app_id" + ] } } diff --git a/helpers.lua b/helpers.lua index 1f23411..f43867f 100644 --- a/helpers.lua +++ b/helpers.lua @@ -208,8 +208,10 @@ function has_access(user, url) end -- Loop through user's ACLs and return if the URL is authorized. - for u, _ in pairs(conf["users"][user]) do + for _, app_id in pairs(conf["users"][user]) do + -- Get the url from the apps list + u = conf["apps"][app_id]["url"] -- Replace the original domain by a local one if you are connected from -- a non-global domain name. if ngx.var.host == conf["local_portal_domain"] then @@ -491,14 +493,15 @@ function get_data_for(view) -- Add user's accessible URLs using the ACLs. -- It is typically used to build the app list. - for url, name in pairs(conf["users"][user]) do + for _, app_id in pairs(conf["users"][user]) do + app = conf["apps"][app_id] if ngx.var.host == conf["local_portal_domain"] then - url = string.gsub(url, conf["original_portal_domain"], conf["local_portal_domain"]) + app["url"] = string.gsub(app["url"], conf["original_portal_domain"], conf["local_portal_domain"]) end - table.insert(sorted_apps, name) + table.insert(sorted_apps, app_id) table.sort(sorted_apps) - table.insert(data["app"], index_of(sorted_apps, name), { url = url, name = name }) + table.insert(data["app"], index_of(sorted_apps, app_id), app) end end