summaryrefslogtreecommitdiffstats
path: root/app/acf-util/roles-controller.lua
blob: adf4b23b3452b95e4247f9600745f79a271e147d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
-- Roles/Group functions
module (..., package.seeall)


default_action = "read"

-- Return your own roles/permissions
read = function(self)
	userid = cfe({ value=self.sessiondata.userinfo.userid, label="User Id" })
	roles = cfe({ type="list", value=self.sessiondata.userinfo.roles, label="Roles" })
	permissions = cfe({ type="table", value = self.sessiondata.permissions, label="Permissions" })
	return cfe({ type="group", value={userid=userid, roles=roles, permissions=permissions} })
end

-- Return roles/permissions for specified user
viewuserroles = function(self)
	if not (self.clientdata.userid) then
		redirect(self)
	end
	userid = cfe({ value=self.clientdata.userid, label="User Id" })
	roles = self.model.get_user_roles(self, userid.value)
	roles.value.userid = userid
	return roles
end

-- Return permissions for specified role
viewroleperms = function(self)
	if not (self.clientdata.role) then
		redirect(self, "getlist")
	end
	role = cfe({ value=self.clientdata.role, label="Role" })
	permissions = self.model.get_role_perms(self, role.value)
	return cfe({ type="group", value={role=role, permissions=permissions} })
end

-- Return list of all permissions
getpermslist = function(self)
	return cfe({ type="group", value={permissions=self.model.get_perms_list(self)} })
end

viewroles = function(self)
	return self.model.view_roles(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")
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")
end

deleterole = function(self)
	return self:redirect_to_referrer(self.model.delete_role(self, self.clientdata.role))
end