summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2013-05-27 11:08:33 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2013-05-27 11:08:33 +0100
commit57a8d542932fdebbbfa8fbcec81d7dfb8dfd5dd0 (patch)
tree1b73700370b02e768cb2004d0747acc6d5acc082
parent06fc8a236b59c5a2ad9943329da4bd1cfb00246f (diff)
downloadgitano-57a8d542932fdebbbfa8fbcec81d7dfb8dfd5dd0.tar.bz2
ADMINCOMMAND: Add group rename
This adds a group rename command to allow the administrator to easily rename a group including all subgroup memberships.
-rw-r--r--lib/gitano/admincommand.lua47
1 files changed, 42 insertions, 5 deletions
diff --git a/lib/gitano/admincommand.lua b/lib/gitano/admincommand.lua
index e8c63ad..a89d4e9 100644
--- a/lib/gitano/admincommand.lua
+++ b/lib/gitano/admincommand.lua
@@ -312,6 +312,7 @@ usage: group [list]
group show <groupname>
group add <groupname> <description>
group del <groupname [confirm token]
+ group rename <groupname> <newgroupname> [confirm token]
group description <groupname> <description>
group adduser <groupname> <username>
group deluser <groupname> <username> [confirm token]
@@ -331,16 +332,16 @@ If you add a group to a group, you are stating that everyone in the
sub group is to be considered a member of this group also. Removing a
group undoes this effect.
-To delete a group, remove a user from a group or remove a group from a
-group requires a confirmation token which will be supplied to you if
-missing.
+To delete or rename a group, remove a user from a group or remove a
+group from a group requires a confirmation token which will be
+supplied to you if missing.
]]
local function builtin_group_validate(conf, _, cmdline)
if not cmdline[2] then
cmdline[2] = "list"
end
- local groupsubs = util.set {"list", "show", "add", "del",
+ local groupsubs = util.set {"list", "show", "add", "del", "rename",
"adduser", "deluser", "addgroup", "delgroup", "description"}
if not groupsubs[cmdline[2]] then
log.error("Unknown sub command", cmdline[2], "for group")
@@ -365,6 +366,10 @@ local function builtin_group_validate(conf, _, cmdline)
log.error("Del takes a group name and a confirmation token")
return false
end
+ if cmdline[2] == "rename" and (#cmdline < 4 or #cmdline > 5) then
+ log.error("Rename takes a group name, a new group name [and a token]")
+ return false
+ end
if cmdline[2] == "description" and #cmdline < 4 then
log.error("Description takes a group name and a description")
return false
@@ -464,7 +469,7 @@ local function builtin_group_run(conf, _, cmdline, env)
if not conf.groups[g] then
log.fatal("Unknown group", g)
end
- local token = conf.repo:generate_confirmation()
+ local token = conf.repo:generate_confirmation("delete group " .. g)
if not cmdline[4] then
log.state("In order to delete group", g, "you must supply the following token:")
log.state(token)
@@ -474,6 +479,38 @@ local function builtin_group_run(conf, _, cmdline, env)
conf.groups[g] = nil
reason = "Delete group " .. g
end
+ elseif cmdline[2] == "rename" then
+ local g = cmdline[3]
+ if not conf.groups[g] then
+ log.fatal("Unknown group", g)
+ end
+ local newg = cmdline[4]
+ if conf.groups[newg] then
+ log.fatal("New group", newg, "already exists.")
+ end
+ local token = conf.repo:generate_confirmation("rename group " .. g ..
+ " to " .. newg)
+ if not cmdline[5] then
+ log.state("In order to rename group", g, "to", newg,
+ "you must supply the following token:")
+ log.state(token)
+ elseif cmdline[5] ~= token then
+ log.fatal("Token does not match. Has someone else done administrative actions?")
+ else
+ for gg, gtab in pairs(conf.groups) do
+ if gtab.subgroups[g] then
+ gtab.subgroups[gtab.subgroups[g]] = newg
+ gtab.subgroups[newg] = gtab.subgroups[g]
+ gtab.subgroups[g] = nil
+ gtab.changed_tables()
+ log.state("Renamed:", g, "to", newg,
+ "in subgroup membership of", gg)
+ end
+ end
+ conf.groups[newg] = conf.groups[g]
+ conf.groups[g] = nil
+ reason = "Delete group " .. g
+ end
elseif cmdline[2] == "adduser" then
local g, gtab, u, utab =
cmdline[3], conf.groups[cmdline[3]],