summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2012-04-23 20:10:26 +0000
committerTed Trask <ttrask01@yahoo.com>2012-04-23 20:10:26 +0000
commitdd21a41cfd3018a1685805cf48a0c022b3a912c4 (patch)
tree8175fef47e9378341d9bb2bf4dc95167ab870049 /app
parentedf4f15251158dd0bd3aeb7a2ad7b872c1c59fb3 (diff)
downloadacf-core-dd21a41cfd3018a1685805cf48a0c022b3a912c4.tar.bz2
acf-core-dd21a41cfd3018a1685805cf48a0c022b3a912c4.tar.xz
Modified roles controller to use new handle_form function
Diffstat (limited to 'app')
-rw-r--r--app/Makefile7
-rw-r--r--app/acf-util/roles-controller.lua12
-rw-r--r--app/acf-util/roles-editrole-html.lsp67
l---------app/acf-util/roles-getpermslist-html.lsp1
-rw-r--r--app/acf-util/roles-model.lua64
l---------app/acf-util/roles-newrole-html.lsp1
-rw-r--r--app/acf-util/roles-read-html.lsp (renamed from app/acf-util/roles-html.lsp)0
l---------app/acf-util/roles-viewroleperms-html.lsp1
-rw-r--r--app/acf-util/roles-viewroles-html.lsp2
l---------app/acf-util/roles-viewuserroles-html.lsp1
10 files changed, 62 insertions, 94 deletions
diff --git a/app/Makefile b/app/Makefile
index 9f47121..d52c50a 100644
--- a/app/Makefile
+++ b/app/Makefile
@@ -5,11 +5,12 @@ APP_DIST= \
acf-util/logon-controller.lua \
acf-util/logon-model.lua \
acf-util/roles-controller.lua \
+ acf-util/roles-getpermslist-html.lsp \
acf-util/roles-model.lua \
- acf-util/roles-html.lsp \
+ acf-util/roles-read-html.lsp \
+ acf-util/roles-viewroleperms-html.lsp \
acf-util/roles-viewroles-html.lsp \
- acf-util/roles-editrole-html.lsp \
- acf-util/roles-newrole-html.lsp \
+ acf-util/roles-viewuserroles-html.lsp \
acf-util/roles.menu \
acf-util/password-controller.lua \
acf-util/password-html.lsp \
diff --git a/app/acf-util/roles-controller.lua b/app/acf-util/roles-controller.lua
index adf4b23..c02d693 100644
--- a/app/acf-util/roles-controller.lua
+++ b/app/acf-util/roles-controller.lua
@@ -43,19 +43,13 @@ viewroles = function(self)
end
newrole = function(self)
- return self.handle_form(self,
- function() return self.model.getpermissions(self) end,
- function(value) return self.model.setpermissions(self, value, true) end,
- self.clientdata, "Create", "Create New Role", "New Role Created")
+ return self.handle_form(self, self.model.getpermissions, self.model.setnewpermissions, self.clientdata, "Create", "Create New Role", "New Role Created")
end
editrole = function(self)
- return self.handle_form(self,
- function() return self.model.getpermissions(self, self.clientdata.role) end,
- function(value) return self.model.setpermissions(self, value, false) end,
- self.clientdata, "Save", "Edit Role", "Role Saved")
+ return self.handle_form(self, self.model.getpermissions, self.model.setpermissions, self.clientdata, "Save", "Edit Role", "Role Saved")
end
deleterole = function(self)
- return self:redirect_to_referrer(self.model.delete_role(self, self.clientdata.role))
+ return self.handle_form(self, self.model.get_delete_role, self.model.delete_role, self.clientdata, "Delete", "Delete Role", "Role Deleted")
end
diff --git a/app/acf-util/roles-editrole-html.lsp b/app/acf-util/roles-editrole-html.lsp
deleted file mode 100644
index d464cd1..0000000
--- a/app/acf-util/roles-editrole-html.lsp
+++ /dev/null
@@ -1,67 +0,0 @@
-<% local form, viewtable, page_info = ... %>
-<% require("htmlviewfunctions") %>
-
-<H1><%= html.html_escape(form.label) %></H1>
-<%
- htmlviewfunctions.displayformstart(form, page_info)
- -- If editing existing role, disable role
- if page_info.action ~= "newrole" then
- form.value.role.readonly = true
- end
- htmlviewfunctions.displayformitem(form.value.role, "role")
-
- -- copied this code from viewfunctions so we can disable the default boxes
- local myitem = form.value.permissions
- myitem.name = "permissions"
- io.write("<DT")
- if myitem.errtxt then
- myitem.class = "error"
- io.write(' class="error"')
- end
- io.write(">" .. html.html_escape(myitem.label) .. "</DT>\n")
- io.write("<DD>")
- -- FIXME multiple select doesn't work in haserl, so use series of checkboxes
- myitem.class = nil
- local tempname = myitem.name
- local tempval = myitem.value or {}
- local reversedefault = {}
- for x,val in ipairs(myitem.default or {}) do
- reversedefault[val] = x
- end
- local reverseval = {}
- for x,val in ipairs(tempval) do
- reverseval[val] = x
- end
- local reverseopt = {}
- for x,val in ipairs(myitem.option) do
- reverseopt[val] = x
- myitem.value = val
- myitem.checked = reverseval[val]
- if reversedefault[val] then myitem.disabled = true else myitem.disabled = nil end
- myitem.name = tempname .. "." .. x
- io.write(html.form.checkbox(myitem) .. html.html_escape(val) .. "<br>\n")
- end
- -- Check for values not in options
- if myitem.errtxt then
- myitem.class = "error"
- io.write('<p class="error">\n')
- end
- for x,val in ipairs(tempval) do
- if not reverseopt[val] then
- myitem.value = val
- myitem.checked = true
- io.write(html.form.checkbox(myitem) .. html.html_escape(val) .. "<br>\n")
- end
- end
- if myitem.errtxt then
- io.write('</p>\n')
- end
- myitem.name = tempname
- myitem.value = tempval
-
- if myitem.descr then io.write('<P CLASS="descr">' .. string.gsub(html.html_escape(myitem.descr), "\n", "<BR>") .. "</P>\n") end
- if myitem.errtxt then io.write('<P CLASS="error">' .. string.gsub(html.html_escape(myitem.errtxt), "\n", "<BR>") .. "</P>\n") end
- io.write("</DD>\n")
-
- htmlviewfunctions.displayformend(form)
-%>
diff --git a/app/acf-util/roles-getpermslist-html.lsp b/app/acf-util/roles-getpermslist-html.lsp
new file mode 120000
index 0000000..58601a3
--- /dev/null
+++ b/app/acf-util/roles-getpermslist-html.lsp
@@ -0,0 +1 @@
+roles-read-html.lsp \ No newline at end of file
diff --git a/app/acf-util/roles-model.lua b/app/acf-util/roles-model.lua
index cbd9f38..2181a70 100644
--- a/app/acf-util/roles-model.lua
+++ b/app/acf-util/roles-model.lua
@@ -31,29 +31,48 @@ view_roles = function(self)
return cfe({ type="group", value={defined_roles=defined_roles_cfe, default_roles=default_roles_cfe} })
end
-getpermissions = function(self, role)
+getpermissions = function(self, clientdata)
+ local role_cfe = cfe({ value=clientdata.role or "", label="Role", seq=1 })
+
+ local tmp, all_perms = roles.get_all_permissions(self)
+ table.sort(all_perms)
local my_perms = {}
local default_perms = {}
- if role then
+ if clientdata.role then
+ role_cfe.readonly = true
local tmp
- tmp, my_perms, default_perms = roles.get_role_perm(self, role)
+ tmp, my_perms, default_perms = roles.get_role_perm(self, clientdata.role)
my_perms = my_perms or {}
default_perms = default_perms or {}
- else
- role = ""
+ if #default_perms > 0 then
+ -- Mark the default permissions as disabled
+ local rev = {}
+ for i,d in ipairs(default_perms) do
+ rev[d] = i
+ end
+ local newall = {}
+ for i,p in ipairs(all_perms) do
+ local tmp = {value=p, label=p}
+ if rev[p] then
+ tmp.disabled = true
+ end
+ newall[#newall+1] = tmp
+ end
+ all_perms = newall
+ end
end
-
- local tmp, all_perms = roles.get_all_permissions(self)
- table.sort(all_perms)
- local permissions_cfe = cfe({ type="multi", value=my_perms, option=all_perms, label="Role permissions", default=default_perms })
- local role_cfe = cfe({ value=role, label="Role" })
+ local permissions_cfe = cfe({ type="multi", value=my_perms, option=all_perms, label="Role permissions", seq=2 })
return cfe({ type="table", value={role=role_cfe, permissions=permissions_cfe} })
end
-setpermissions = function(self, permissions, newrole)
+setnewpermissions = function(self, permissions, action)
+ return setpermissions(self, permissions, action, true)
+end
+
+setpermissions = function(self, permissions, action, newrole)
-- Validate entries and create error strings
local result = true
if newrole then
@@ -79,7 +98,26 @@ setpermissions = function(self, permissions, newrole)
return permissions
end
+get_delete_role = function(self, clientdata)
+ local defined_roles, default_roles = roles.list_roles(self)
+ local role = cfe({ type="select", value = clientdata.role or "", label="Role", option=defined_roles })
+ return cfe({ type="group", value={role=role}, label="Delete Role" })
+end
+
delete_role = function(self, role)
- local result, cmdresult = roles.delete_role(self, role)
- return cfe({ value=cmdresult })
+ local result, cmdresult = roles.delete_role(self, role.value.role.value)
+ if not result then
+ role.value.role.errtxt = cmdresult
+ role.errtxt = "Failed to Delete Role"
+ else
+ -- remove the just deleted role
+ for i,r in ipairs(role.value.role.option) do
+ if r == role.value.role.value then
+ role.value.role.value =""
+ role.value.role.option[i] = nil
+ break
+ end
+ end
+ end
+ return role
end
diff --git a/app/acf-util/roles-newrole-html.lsp b/app/acf-util/roles-newrole-html.lsp
deleted file mode 120000
index dc2b56b..0000000
--- a/app/acf-util/roles-newrole-html.lsp
+++ /dev/null
@@ -1 +0,0 @@
-roles-editrole-html.lsp \ No newline at end of file
diff --git a/app/acf-util/roles-html.lsp b/app/acf-util/roles-read-html.lsp
index 32000af..32000af 100644
--- a/app/acf-util/roles-html.lsp
+++ b/app/acf-util/roles-read-html.lsp
diff --git a/app/acf-util/roles-viewroleperms-html.lsp b/app/acf-util/roles-viewroleperms-html.lsp
new file mode 120000
index 0000000..58601a3
--- /dev/null
+++ b/app/acf-util/roles-viewroleperms-html.lsp
@@ -0,0 +1 @@
+roles-read-html.lsp \ No newline at end of file
diff --git a/app/acf-util/roles-viewroles-html.lsp b/app/acf-util/roles-viewroles-html.lsp
index 04b4a98..c775737 100644
--- a/app/acf-util/roles-viewroles-html.lsp
+++ b/app/acf-util/roles-viewroles-html.lsp
@@ -19,7 +19,7 @@
<dd>
[<a href='viewroleperms?role=<%= html.html_escape(role) %>'>View this role</a>]
[<a href='editrole?role=<%= html.html_escape(role) %>&redir=<%= html.html_escape(page_info.orig_action) %>'>Edit this role</a>]
- [<a href='deleterole?role=<%= html.html_escape(role) %>'>Delete this role</a>]
+ [<a href='deleterole?role=<%= html.html_escape(role) %>&submit=true'>Delete this role</a>]
</dd></TD></TR>
<% end %>
<% end %>
diff --git a/app/acf-util/roles-viewuserroles-html.lsp b/app/acf-util/roles-viewuserroles-html.lsp
new file mode 120000
index 0000000..58601a3
--- /dev/null
+++ b/app/acf-util/roles-viewuserroles-html.lsp
@@ -0,0 +1 @@
+roles-read-html.lsp \ No newline at end of file