Commit 774acc0d authored by Ted Trask's avatar Ted Trask

Started making changes for acf-core-0.15

Changed viewfunctions library to htmlviewfunctions
Changed editusersettings, editmyusersettings, and createuser to use new handle_form functionality
Removed views for above actions by moving customization to model - seq and readonly
Changed deleteuser to be a form
parent d55292ad
......@@ -17,7 +17,7 @@ editusers = function( self )
end
deleteuser = function( self )
return self:redirect_to_referrer(self.model.delete_user(self.clientdata.username))
return controllerfunctions.handle_form(self, self.model.get_delete_user, self.model.set_delete_user, self.clientdata, "Delete", "Delete User", "User Deleted")
end
listmessages = function( self )
......@@ -79,15 +79,19 @@ callbackmymessage = function( self )
end
editusersettings = function( self )
return controllerfunctions.handle_form(self, function() return self.model.get_usersettings(self.clientdata.username) end, self.model.update_usersettings, self.clientdata, "Save", "Edit Settings", "Settings Saved")
return controllerfunctions.handle_form(self, self.model.get_usersettings, self.model.update_usersettings, self.clientdata, "Save", "Edit Settings", "Settings Saved")
end
editmyusersettings = function( self )
return controllerfunctions.handle_form(self, function() return self.model.get_usersettings(self.sessiondata.userinfo.userid) end, self.model.update_usersettings, self.clientdata, "Save", "Edit Settings", "Settings Saved")
self.clientdata.username = nil
if self.sessiondata.userinfo then
self.clientdata.username = self.sessiondata.userinfo.userid
end
return controllerfunctions.handle_form(self, self.model.get_usersettings, self.model.update_usersettings, self.clientdata, "Save", "Edit Settings", "Settings Saved")
end
createuser = function( self )
return controllerfunctions.handle_form(self, function() return self.model.get_usersettings() end, self.model.create_usersettings, self.clientdata, "Create", "Create User", "User Created")
return controllerfunctions.handle_form(self, self.model.get_usersettings, self.model.create_usersettings, self.clientdata, "Create", "Create User", "User Created")
end
processdialplanxml = function( self )
......
vmail-editusersettings-html.lsp
\ No newline at end of file
vmail-editusersettings-html.lsp
\ No newline at end of file
<% local form, viewlibrary, page_info = ...
require("viewfunctions")
%>
<H1>Settings for <%= html.html_escape(form.value.firstname.value).." "..html.html_escape(form.value.lastname.value) %> (<%= html.html_escape(form.value.username.value) %>)</H1>
<%
if page_info.action ~= "createuser" and form.value.username then
form.value.username.readonly = true
end
if form.value["vm-password"] then form.value["vm-password"].type = "password" end
if form.value["vm-password-confirm"] then form.value["vm-password-confirm"].type = "password" end
local order = {"username", "firstname", "lastname", "vm-password", "vm-password-confirm", "vm-mailto", "vm-email-all-messages", "vm-attach-file", "vm-keep-local-after-email", "vm-notify-mailto", "vm-notify-email-all-messages"}
displayform(form, order, nil, page_info)
%>
<% local view, viewlibrary, page_info, session = ...
require("viewfunctions")
require("htmlviewfunctions")
%>
<% -- Pregenerate the list of users
......@@ -206,7 +206,7 @@ end
});
</script>
<% displaycommandresults({"deletemessage", "deletemymessage", "forwardmessage", "forwardmymessage", "emailmessage", "emailmymessage", "movemessage", "movemymessage", "callbackmessage", "callbackmymessage"}, session) %>
<% htmlviewfunctions.displaycommandresults({"deletemessage", "deletemymessage", "forwardmessage", "forwardmymessage", "emailmessage", "emailmymessage", "movemessage", "movemymessage", "callbackmessage", "callbackmymessage"}, session) %>
<h1>Messages</h1>
<DL>
......
<% local view, viewlibrary, page_info, session = ...
require("viewfunctions")
require("htmlviewfunctions")
%>
<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"></script>
......@@ -11,7 +11,7 @@ require("viewfunctions")
});
</script>
<% displaycommandresults({"createuser", "deleteuser", "editusersettings"}, session) %>
<% htmlviewfunctions.displaycommandresults({"createuser", "deleteuser", "editusersettings"}, session) %>
<h1>Users</h1>
<DL><TABLE id="list" class="tablesorter"><THEAD>
......@@ -29,7 +29,7 @@ require("viewfunctions")
<%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/editusersettings?username="..v.username, label="Edit "} %>
<% end %>
<% if viewlibrary.check_permission("deleteuser") then %>
<%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/deleteuser?username="..v.username, label="Delete ", class="deleteuser"} %>
<%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/deleteuser?username="..v.username.."&submit=true", label="Delete ", class="deleteuser"} %>
<% end %>
</TD>
<TD><%= html.html_escape(v.username) %></TD>
......
......@@ -3,9 +3,9 @@ module (..., package.seeall)
-- Load libraries
require("modelfunctions")
require("posix")
require("fs")
require("format")
require("validator")
fs = require("acf.fs")
format = require("acf.format")
validator = require("acf.validator")
require("luasql.sqlite3")
require("session")
......@@ -34,20 +34,20 @@ local table_creation_scripts = {
"CREATE INDEX values_uid_nid_idx on voicemail_values (uid, nid)",
},
voicemail_params = {
"CREATE TABLE voicemail_params (nid INTEGER PRIMARY KEY, name VARCHAR(255) UNIQUE, type VARCHAR(255), label VARCHAR(255), descr VARCHAR(255), value VARCHAR(255))",
"CREATE TABLE voicemail_params (nid INTEGER PRIMARY KEY, name VARCHAR(255) UNIQUE, type VARCHAR(255), label VARCHAR(255), descr VARCHAR(255), value VARCHAR(255), seq INTEGER)",
"CREATE INDEX params_name_idx ON voicemail_params (name)",
"INSERT INTO voicemail_params VALUES(null, 'username', 'text', 'Extension', '', '')",
"INSERT INTO voicemail_params VALUES(null, 'firstname', 'text', 'User First Name', '', '')",
"INSERT INTO voicemail_params VALUES(null, 'lastname', 'text', 'User Last Name', '', '')",
"INSERT INTO voicemail_params VALUES(null, 'vm-password', 'text', 'Voicemail Password', 'Passwords must be all numbers and at least three digits', '')",
"INSERT INTO voicemail_params VALUES(null, 'vm-password-confirm', 'text', 'Enter again to confirm', '', '')",
"INSERT INTO voicemail_params VALUES(null, 'vm-mailto', 'text', 'Email Address', 'Email a notification, including audio file if enabled', '')",
"INSERT INTO voicemail_params VALUES(null, 'vm-email-all-messages', 'boolean', 'Email Enable', '', 'false')",
"INSERT INTO voicemail_params VALUES(null, 'vm-attach-file', 'boolean', 'Attach voicemail to email', 'Option to attach audio file to email', 'false')",
"INSERT INTO voicemail_params VALUES(null, 'vm-keep-local-after-email', 'boolean', 'Keep voicemail', 'When disabled, the message will be deleted from the voicemailbox after any notification email is sent (whether or not email is enabled). This allows receiving voicemail via email alone, rather than having the voicemail available from the Web interface or by telephone. CAUTION: \"Email Address\" must be valid and \"Email Enable\" and \"Attach voicemail to email\" must be enabled, OTHERWISE YOUR MESSAGES WILL BE LOST FOREVER.', 'true')",
"INSERT INTO voicemail_params VALUES(null, 'vm-notify-mailto', 'text', 'Pager Email Address', 'Email a short notification', '')",
"INSERT INTO voicemail_params VALUES(null, 'vm-notify-email-all-messages', 'boolean', 'Pager Email Enable', '', 'false')",
"INSERT INTO voicemail_params VALUES(null, 'callmenumber', 'text', 'Call Me Number', '', '')",
"INSERT INTO voicemail_params VALUES(null, 'username', 'text', 'Extension', '', '', '1')",
"INSERT INTO voicemail_params VALUES(null, 'firstname', 'text', 'User First Name', '', '', '2')",
"INSERT INTO voicemail_params VALUES(null, 'lastname', 'text', 'User Last Name', '', '', '3')",
"INSERT INTO voicemail_params VALUES(null, 'vm-password', 'password', 'Voicemail Password', 'Passwords must be all numbers and at least three digits', '', '4')",
"INSERT INTO voicemail_params VALUES(null, 'vm-password-confirm', 'password', 'Enter again to confirm', '', '', '5')",
"INSERT INTO voicemail_params VALUES(null, 'vm-mailto', 'text', 'Email Address', 'Email a notification, including audio file if enabled', '', '6')",
"INSERT INTO voicemail_params VALUES(null, 'vm-email-all-messages', 'boolean', 'Email Enable', '', 'false', '7')",
"INSERT INTO voicemail_params VALUES(null, 'vm-attach-file', 'boolean', 'Attach voicemail to email', 'Option to attach audio file to email', 'false', '8')",
"INSERT INTO voicemail_params VALUES(null, 'vm-keep-local-after-email', 'boolean', 'Keep voicemail', 'When disabled, the message will be deleted from the voicemailbox after any notification email is sent (whether or not email is enabled). This allows receiving voicemail via email alone, rather than having the voicemail available from the Web interface or by telephone. CAUTION: \"Email Address\" must be valid and \"Email Enable\" and \"Attach voicemail to email\" must be enabled, OTHERWISE YOUR MESSAGES WILL BE LOST FOREVER.', 'true', '9')",
"INSERT INTO voicemail_params VALUES(null, 'vm-notify-mailto', 'text', 'Pager Email Address', 'Email a short notification', '', '10')",
"INSERT INTO voicemail_params VALUES(null, 'vm-notify-email-all-messages', 'boolean', 'Pager Email Enable', '', 'false', '11')",
"INSERT INTO voicemail_params VALUES(null, 'callmenumber', 'text', 'Call Me Number', '', '', '12')",
},
voicemail_folders = {
"CREATE TABLE voicemail_folders (in_folder VARCHAR(255) PRIMARY KEY, label VARCHAR(255))",
......@@ -151,6 +151,7 @@ local runscript = function(script)
end
end
local runsqlcommand
runsqlcommand = function(sql)
local res, err = con:execute(sql)
if not res and err then
......@@ -165,6 +166,7 @@ runsqlcommand = function(sql)
end
end
local getselectresponse
getselectresponse = function(sql)
local retval = {}
local res, err = pcall(function()
......@@ -259,6 +261,7 @@ local getuserparams = function(username)
end
if retval.username and username then
retval.username.value = username
retval.username.readonly = true
local users = listusers(username)
if #users == 1 then
......@@ -359,6 +362,34 @@ local function validateconfig(newconfig)
return success, newconfig
end
local delete_user = function(username)
local users = listusers(username)
if #users == 0 then
return false, "User does not exist"
else
-- Delete all of the user's voicemails
local messages = list_messages(username)
if #messages.value then
for i,m in ipairs(messages.value) do
delete_message(m.uuid)
end
end
-- Remove the user parameters
local sql = "DELETE FROM voicemail_values " .. generatewhereclause(nil, nil, nil, users[1].uid)
runsqlcommand(sql)
-- Remove the user password
sql = "DELETE FROM voicemail_prefs " .. generatewhereclause(username)
runsqlcommand(sql)
-- Remove the user
sql = "DELETE FROM voicemail_users " .. generatewhereclause(nil, nil, nil, users[1].uid)
runsqlcommand(sql)
result = "Voicemail User Deleted"
-- Remove the greetings
fs.remove_directory(recording_path..(users[1].domain or config.domain).."/"..username)
end
return true
end
-- ################################################################################
-- PUBLIC FUNCTIONS
......@@ -681,55 +712,41 @@ list_users = function()
return cfe({ type="structure", value=users, label="Voicemail Users", errtxt=errtxt })
end
delete_user = function(username)
get_delete_user = function(clientdata)
local result = {}
result.username = cfe({ value=clientdata.username or "", label="User Name" })
return cfe({ type="group", value=result, label="Delete User" })
end
set_delete_user = function(deleterequest)
local result = ""
local errtxt
errtxt = nil
if not username or username == "" then
errtxt = "User does not exist"
else
local success = true
if not deleterequest.value.username.value == "" then
deleterequest.value.username.errtxt = "User does not exist"
success = false
end
if success then
local res, err = pcall(function()
local connected = databaseconnect()
local users = listusers(username)
if #users == 0 or username == "" then
errtxt = "User does not exist"
else
-- Delete all of the user's voicemails
local messages = list_messages(username)
if #messages.value then
for i,m in ipairs(messages.value) do
delete_message(m.uuid)
end
end
-- Remove the user parameters
sql = "DELETE FROM voicemail_values " .. generatewhereclause(nil, nil, nil, users[1].uid)
runsqlcommand(sql)
-- Remove the user password
sql = "DELETE FROM voicemail_prefs " .. generatewhereclause(username)
runsqlcommand(sql)
-- Remove the user
sql = "DELETE FROM voicemail_users " .. generatewhereclause(nil, nil, nil, users[1].uid)
runsqlcommand(sql)
result = "Voicemail User Deleted"
-- Remove the greetings
fs.remove_directory(recording_path..(users[1].domain or config.domain).."/"..username)
end
success, deleterequest.errtxt = delete_user(deleterequest.value.username.value)
if connected then databasedisconnect() end
end)
if not res and err then
errtxt = err
deleterequest.errtxt = err
end
else
deleterequest.errtxt = "Failed to delete user"
end
return cfe({ value=result, errtxt=errtxt, label="Delete User Result" })
return deleterequest
end
get_usersettings = function(username)
get_usersettings = function(clientdata)
local retval = {}
local errtxt
local res, err = pcall(function()
local connected = databaseconnect()
retval = getuserparams(username)
retval = getuserparams(clientdata.username)
if connected then databasedisconnect() end
end)
if not res and err then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment