cgi-bin/tek/class/loona.lua
changeset 201 d52b05a9fe9c
parent 199 8b5fc485edf4
child 206 450cd443de9f
     1.1 --- a/cgi-bin/tek/class/loona.lua	Wed Oct 10 10:37:29 2007 +0200
     1.2 +++ b/cgi-bin/tek/class/loona.lua	Fri Nov 23 01:46:43 2007 +0100
     1.3 @@ -5,7 +5,7 @@
     1.4  --	See copyright notice in COPYRIGHT
     1.5  --
     1.6  
     1.7 -local Atom = require "tek.class.atom"
     1.8 +local Class = require "tek.class"
     1.9  local lib = require "tek.lib"
    1.10  local luahtml = require "tek.lib.luahtml"
    1.11  local posix = require "tek.os.posix"
    1.12 @@ -26,30 +26,28 @@
    1.13  	xpcall = xpcall
    1.14  }
    1.15  
    1.16 -local table, string, assert, unpack, ipairs, pairs, type, require =
    1.17 -	table, string, assert, unpack, ipairs, pairs, type, require
    1.18 -local setmetatable, setfenv, getfenv = setmetatable, setfenv, getfenv
    1.19 +local table, string, assert, unpack, ipairs, pairs, type, require, setfenv =
    1.20 +	table, string, assert, unpack, ipairs, pairs, type, require, setfenv
    1.21  local open, remove, rename, getenv, time, date =
    1.22  	io.open, os.remove, os.rename, os.getenv, os.time, os.date
    1.23 +local setmetatable = setmetatable
    1.24  
    1.25  -------------------------------------------------------------------------------
    1.26  --	Module setup:
    1.27  -------------------------------------------------------------------------------
    1.28  
    1.29 -module "tek.class.loona"
    1.30 -
    1.31 -_VERSION = 4
    1.32 -_REVISION = 4
    1.33 +module("tek.class.loona", Class)
    1.34 +_VERSION = "LOona Class 5.0"
    1.35  
    1.36  -------------------------------------------------------------------------------
    1.37  --	class Session:
    1.38  -------------------------------------------------------------------------------
    1.39  
    1.40 -local Session = Atom:newclass()
    1.41 +local Session = Class:newClass()
    1.42  
    1.43  function Session.new(class, self)
    1.44  
    1.45 -	self = Atom.new(class, self or { })
    1.46 +	self = Class.new(class, self or { })
    1.47  
    1.48  	assert(self.id, "No session Id")
    1.49   	assert(self.sessiondir, "No session directory")
    1.50 @@ -83,7 +81,7 @@
    1.51  --	class Loona
    1.52  -------------------------------------------------------------------------------
    1.53  
    1.54 -local Loona = Atom:newclass(getfenv())
    1.55 +local Loona = _M
    1.56  
    1.57  
    1.58  function Loona:dbmsg(msg, detail)
    1.59 @@ -251,8 +249,20 @@
    1.60  
    1.61  
    1.62  function Loona:indexsections()
    1.63 +	local userperm = self.session and self.session.data.permissions
    1.64 +	userperm = userperm and userperm ~= "" and "[" .. userperm .. "]"
    1.65  	self:recursesections(self.sections, function(self, s, e)
    1.66 -		e.notvalid = (not self.secure and e.secure) or
    1.67 +		local permitted = true
    1.68 +		local sectperm = e.permissions
    1.69 +		if sectperm and sectperm ~= "" then
    1.70 +			permitted = false
    1.71 +			if userperm then
    1.72 +				local num = sectperm:len()
    1.73 +				sectperm:gsub(userperm, function() num = num - 1 end)
    1.74 +				permitted = num == 0
    1.75 +			end
    1.76 +		end
    1.77 +		e.notvalid = not permitted or (not self.secure and e.secure) or
    1.78  			(not self.authuser_visible and e.secret) or nil
    1.79  		e.notvisible = e.notvalid or not self.authuser_visible and e.hidden or nil
    1.80  		s[e.name] = e
    1.81 @@ -703,8 +713,8 @@
    1.82  	local contentdir = self.contentdir
    1.83  	local edit, show, hidden, extramsg, changed
    1.84  
    1.85 -	if self.authuser_edit or self.authuser_profile or self.authuser_modifyprofile or self_authuser_attr
    1.86 -		or self.authuser_menu then
    1.87 +	if self.authuser_edit or self.authuser_profile or
    1.88 +		self.authuser_modifyprofile or self.authuser_menu then
    1.89  
    1.90  		local hiddenvars = table.concat( {
    1.91  			self:hidden("lang", self.args.lang),
    1.92 @@ -796,6 +806,14 @@
    1.93  						</tr>
    1.94  						<tr>
    1.95  							<td align="right">
    1.96 +								]] .. self.locale.PERMISSIONS .. [[
    1.97 +							</td>
    1.98 +							<td>
    1.99 +								<input size="30" maxlength="50" name="editpermissions" />
   1.100 +							</td>
   1.101 +						</tr>
   1.102 +						<tr>
   1.103 +							<td align="right">
   1.104  								]] .. self.locale.REDIRECT .. [[
   1.105  							</td>
   1.106  							<td>
   1.107 @@ -810,7 +828,8 @@
   1.108  			<hr />
   1.109  			]])
   1.110  
   1.111 -		elseif self.args.actioneditprops and editkey == "main" and self.authuser_attr then
   1.112 +		elseif self.args.actioneditprops and editkey == "main" and
   1.113 +			self.authuser_menu then
   1.114  			hidden = true
   1.115  			if self.ispubprofile then
   1.116  				self:out([[<h2><span class="warn">]] .. self.locale.WARNING_YOU_ARE_IN_PUBLISHED_PROFILE ..[[</span></h2>]])
   1.117 @@ -864,6 +883,14 @@
   1.118  						</tr>
   1.119  						<tr>
   1.120  							<td align="right">
   1.121 +								]] .. self.locale.PERMISSIONS .. [[
   1.122 +							</td>
   1.123 +							<td>
   1.124 +								<input size="30" maxlength="50" name="editpermissions" value="]] .. (self.section.permissions or "") .. [[" />
   1.125 +							</td>
   1.126 +						</tr>
   1.127 +						<tr>
   1.128 +							<td align="right">
   1.129  								]] .. self.locale.REDIRECT .. [[
   1.130  							</td>
   1.131  							<td>
   1.132 @@ -1084,7 +1111,7 @@
   1.133  		end)
   1.134  	end
   1.135  
   1.136 -	if self.authuser_profile or self.authuser_edit or self.authuser_menu or self.authuser_attr then
   1.137 +	if self.authuser_profile or self.authuser_edit or self.authuser_menu then
   1.138  		self:out([[
   1.139  		<hr />
   1.140  		<div class="edit">]])
   1.141 @@ -1107,7 +1134,7 @@
   1.142  				if self.authuser_edit then
   1.143  					self:out('- ' .. self:uilink(self.sectionpath, "[" .. self.locale.EDIT .. "]", "actionedit=true", "editkey=" .. editkey) .. " ")
   1.144  				end
   1.145 -				if editkey == "main" and self.authuser_attr then
   1.146 +				if editkey == "main" and self.authuser_menu then
   1.147  					self:out('- ' .. self:uilink(self.sectionpath, "[" .. self.locale.PROPERTIES .. "]", "actioneditprops=true", "editkey=" .. editkey) .. " ")
   1.148  				end
   1.149  				if (fname == savename or not self.section.subs) and (self.authuser_edit and self.authuser_menu) then
   1.150 @@ -1272,6 +1299,8 @@
   1.151  						self.args.edittitle or nil,
   1.152  					redirect = self.args.editredirect ~= "" and
   1.153  						self.args.editredirect or nil,
   1.154 +					permissions = self.args.editpermissions ~= "" and
   1.155 +						self.args.editpermissions or nil,
   1.156  					hidden = self.args.editvisibility and true,
   1.157  					secret = self.args.editsecrecy and true,
   1.158  					secure = self.args.editsecure and true,
   1.159 @@ -1301,6 +1330,8 @@
   1.160  				self.args.edittitle or nil
   1.161  			self.section.redirect =
   1.162  				self.args.editredirect ~= "" and self.args.editredirect or nil
   1.163 +			self.section.permissions =
   1.164 +				self.args.editpermisisons ~= "" and self.args.editpermissions or nil
   1.165  			save = true
   1.166  
   1.167  		elseif self.args.actionup then
   1.168 @@ -1523,7 +1554,7 @@
   1.169  
   1.170  function Loona.new(class, self)
   1.171  
   1.172 -	self = Atom.new(class, self or { })
   1.173 +	self = Class.new(class, self or { })
   1.174  
   1.175  	local parsed, msg
   1.176  
   1.177 @@ -1625,22 +1656,24 @@
   1.178  	else
   1.179  		self.authuser_edit = self.session.data.permissions:find("e") and true
   1.180  		self.authuser_menu = self.session.data.permissions:find("m") and true
   1.181 -		self.authuser_attr = self.session.data.permissions:find("a") and true
   1.182  		self.authuser_profile = self.session.data.permissions:find("p") and true
   1.183  		self.authuser_modifyprofile = self.session.data.permissions:find("c") and true
   1.184  		self.authuser_visible = self.session.data.permissions:find("v") and true
   1.185  		self.authuser_debug = self.session.data.permissions:find("d") and true
   1.186  	end
   1.187  
   1.188 +
   1.189  	-- Get lang, locale, profile, section
   1.190  
   1.191  	self:init()
   1.192 +
   1.193  	if self.authuser then -- TODO?
   1.194  		self:handlechanges()
   1.195  	else
   1.196  		self.args.profile = nil
   1.197  	end
   1.198  
   1.199 +
   1.200  	-- Current document
   1.201  
   1.202  	self.document = self.requestdocument .. "/" .. self.sectionpath