- Implemented permission system management inside the game
- changed @chperm to @setperm to avoid confusion with channel commands - added @setgroup command for adding user group permissions - Moved permissions/group setup into settings file to allow admins to tweak without going into evennia engine. - Add all new players to default permission group (defined in settings) - Defined a basic group hierarchy, removed permission 'genperms.builder' in favour of a group named builders instead, containing all relevant permissions. - Filtered out all django's automatic permissions in @setperm/list to make permission system more controlled by admin. - Probably fixed bug that caused new users to not be signed up to channels (more testing needed) - Added Exception handler in unloggedin method create, this was killing tracebacks upon user creation. /Griatch
This commit is contained in:
parent
77f2186d9a
commit
7f7306a6e4
23 changed files with 341 additions and 214 deletions
|
|
@ -175,7 +175,7 @@ def cmd_batchprocess(command):
|
|||
|
||||
source_object = command.source_object
|
||||
|
||||
#check permissions
|
||||
#check permissions; this is a superuser only command.
|
||||
if not source_object.is_superuser():
|
||||
source_object.emit_to(defines_global.NOPERMS_MSG)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -10,10 +10,6 @@ from src import ansi
|
|||
from src.util import functions_general
|
||||
from src.objects.models import Object
|
||||
from src.cmdtable import GLOBAL_CMD_TABLE
|
||||
#from src.imc2.models import IMC2ChannelMapping
|
||||
#from src.imc2.packets import IMC2PacketIceMsgBroadcasted
|
||||
#from src.irc.models import IRCChannelMapping
|
||||
#from src.irc.connection import IRC_CHANNELS
|
||||
|
||||
def cmd_addcom(command):
|
||||
"""
|
||||
|
|
@ -85,9 +81,7 @@ def cmd_addcom(command):
|
|||
except CommChannel.DoesNotExist:
|
||||
# Failed to match iexact on channel's 'name' attribute.
|
||||
source_object.emit_to("Could not find channel %s." % chan_name)
|
||||
|
||||
|
||||
GLOBAL_CMD_TABLE.add_command("addcom", cmd_addcom),
|
||||
GLOBAL_CMD_TABLE.add_command("addcom", cmd_addcom)
|
||||
|
||||
def cmd_delcom(command):
|
||||
"""
|
||||
|
|
@ -275,14 +269,13 @@ def cmd_cdestroy(command):
|
|||
source_object.emit_to("Could not find channel %s." % (cname,))
|
||||
else:
|
||||
is_controlled_by_plr = name_matches[0].controlled_by(source_object)
|
||||
if is_controlled_by_plr:
|
||||
if is_controlled_by_plr or source_object.has_perm("channels.channel_admin"):
|
||||
source_object.emit_to("Channel %s destroyed." % (name_matches[0],))
|
||||
name_matches.delete()
|
||||
else:
|
||||
source_object.emit_to("Permission denied.")
|
||||
return
|
||||
GLOBAL_CMD_TABLE.add_command("@cdestroy", cmd_cdestroy,
|
||||
priv_tuple=("objects.delete_commchannel")),
|
||||
GLOBAL_CMD_TABLE.add_command("@cdestroy", cmd_cdestroy)
|
||||
|
||||
def cmd_cset(command):
|
||||
"""
|
||||
|
|
@ -327,7 +320,7 @@ def cmd_cboot(command):
|
|||
return
|
||||
|
||||
#do we have power over this channel?
|
||||
if not channel.controlled_by(source_object):
|
||||
if not channel.controlled_by(source_object) or source_object.has_perm("channels.channel_admin"):
|
||||
source_object.emit_to("You don't have that power in channel '%s'." % cname)
|
||||
return
|
||||
|
||||
|
|
@ -432,7 +425,7 @@ def cmd_cemit(command):
|
|||
#pipe to external channels (IRC, IMC) eventually mapped to this channel
|
||||
comsys.send_cexternal(cname_parsed, cmessage, caller=source_object)
|
||||
|
||||
GLOBAL_CMD_TABLE.add_command("@cemit", cmd_cemit),
|
||||
GLOBAL_CMD_TABLE.add_command("@cemit", cmd_cemit,priv_tuple=("channels.emit_commchannel",))
|
||||
|
||||
def cmd_cwho(command):
|
||||
"""
|
||||
|
|
@ -503,8 +496,7 @@ def cmd_ccreate(command):
|
|||
# Create and set the object up.
|
||||
new_chan = comsys.create_channel(cname, source_object)
|
||||
source_object.emit_to("Channel %s created." % (new_chan.get_name(),))
|
||||
GLOBAL_CMD_TABLE.add_command("@ccreate", cmd_ccreate,
|
||||
priv_tuple=("objects.add_commchannel",))
|
||||
GLOBAL_CMD_TABLE.add_command("@ccreate", cmd_ccreate)
|
||||
|
||||
def cmd_cchown(command):
|
||||
"""
|
||||
|
|
@ -526,7 +518,7 @@ def cmd_cchown(command):
|
|||
source_object.emit_to("Channel '%s' not found." % cname)
|
||||
return
|
||||
#check so we have ownership to give away.
|
||||
if not channel.controlled_by(source_object):
|
||||
if not channel.controlled_by(source_object) and not source_object.has_perm("channels.channel_admin"):
|
||||
source_object.emit_to("You don't control this channel.")
|
||||
return
|
||||
#find the new owner
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ now.
|
|||
"""
|
||||
import time
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from src.config.models import ConfigValue
|
||||
from src.helpsys.models import HelpEntry
|
||||
from src.objects.models import Object
|
||||
|
|
@ -334,7 +335,7 @@ def cmd_examine(command):
|
|||
# Send it all
|
||||
source_object.emit_to(s)
|
||||
|
||||
GLOBAL_CMD_TABLE.add_command("examine", cmd_examine)
|
||||
GLOBAL_CMD_TABLE.add_command("examine", cmd_examine,priv_tuple=("objects.info",))
|
||||
|
||||
def cmd_quit(command):
|
||||
"""
|
||||
|
|
@ -452,6 +453,31 @@ def cmd_pose(command):
|
|||
source_object.get_location().emit_to_contents(sent_msg)
|
||||
GLOBAL_CMD_TABLE.add_command("pose", cmd_pose)
|
||||
|
||||
def cmd_group(command):
|
||||
"""@group
|
||||
Usage:
|
||||
@group
|
||||
|
||||
This command shows you which user permission groups you are a member of, if any.
|
||||
"""
|
||||
source_object = command.source_object
|
||||
user = User.objects.get(username=source_object.get_name(show_dbref=False,no_ansi=True))
|
||||
s = ""
|
||||
if source_object.is_superuser():
|
||||
s += "\n This is a SUPERUSER account! Group membership does not matter."
|
||||
if not user.is_active:
|
||||
s += "\n ACCOUNT NOT ACTIVE."
|
||||
for g in user.groups.all():
|
||||
s += "\n -- %s" % g
|
||||
for p in g.permissions.all():
|
||||
s += "\n --- %s" % p.name
|
||||
if not s:
|
||||
s = "You are not a member of any groups." % source_object.get_name(show_dbref=False)
|
||||
else:
|
||||
s = "\nYour (%s's) group memberships: %s" % (source_object.get_name(show_dbref=False),s)
|
||||
source_object.emit_to(s)
|
||||
GLOBAL_CMD_TABLE.add_command("@group", cmd_group,auto_help=True)
|
||||
|
||||
|
||||
def cmd_help(command):
|
||||
"""
|
||||
|
|
@ -539,8 +565,8 @@ def cmd_help(command):
|
|||
|
||||
if 'add' in switches:
|
||||
#try to add/replace help text for a command
|
||||
if not source_object.is_staff():
|
||||
source_object.emit_to("Only staff can add new help entries.")
|
||||
if not source_object.has_perm("helpsys.add_help"):
|
||||
source_object.emit_to(defines_global.NOPERMS_MSG)
|
||||
return
|
||||
spl = (topicstr.split(':',1))
|
||||
if len(spl) != 2:
|
||||
|
|
@ -559,11 +585,11 @@ def cmd_help(command):
|
|||
|
||||
elif 'append' in switches or 'app' in switches:
|
||||
#append text to a help entry
|
||||
if not source_object.is_staff():
|
||||
source_object.emit_to("Only staff can append to help entries.")
|
||||
if not source_object.has_perm("helpsys.add_help"):
|
||||
source_object.emit_to(defines_global.NOPERMS_MSG)
|
||||
return
|
||||
spl = (topicstr.split(':',1))
|
||||
if len(spl) != 2:
|
||||
if len(spl) != 2:
|
||||
source_object.emit_to("""Format is help/append <topic>:<text to add>
|
||||
Use the /newline switch to make a new paragraph.""")
|
||||
return
|
||||
|
|
@ -582,8 +608,8 @@ def cmd_help(command):
|
|||
|
||||
elif 'del' in switches or 'delete' in switches:
|
||||
#delete a help entry
|
||||
if not source_object.is_staff():
|
||||
source_object.emit_to("Only staff can add delete help entries.")
|
||||
if not source_object.has_perm("helpsys.del_help"):
|
||||
source_object.emit_to(defines_global.NOPERMS_MSG)
|
||||
return
|
||||
topics = edit_help.del_help(source_object,topicstr)
|
||||
if type(topics) != type(list()):
|
||||
|
|
|
|||
|
|
@ -117,7 +117,8 @@ def cmd_imcstatus(command):
|
|||
retval += '-' * 50
|
||||
|
||||
source_object.emit_to(retval)
|
||||
GLOBAL_CMD_TABLE.add_command("imcstatus", cmd_imcstatus)
|
||||
GLOBAL_CMD_TABLE.add_command("imcstatus", cmd_imcstatus,
|
||||
priv_tuple=('imc2.admin_imc_channels',))
|
||||
|
||||
|
||||
def cmd_IMC2chan(command):
|
||||
|
|
@ -179,5 +180,5 @@ def cmd_IMC2chan(command):
|
|||
source_object.emit_to(outstring)
|
||||
|
||||
GLOBAL_CMD_TABLE.add_command("@imc2chan",cmd_IMC2chan,auto_help=True,staff_help=True,
|
||||
priv_tuple=("objects.add_commchannel",))
|
||||
priv_tuple=("imc2.admin_imc_channels",))
|
||||
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ def cmd_list(command):
|
|||
source_object.emit_to("Flags: "+" ".join(flags.SERVER_FLAGS))
|
||||
else:
|
||||
source_object.emit_to(msg_invalid)
|
||||
GLOBAL_CMD_TABLE.add_command("@list", cmd_list),
|
||||
GLOBAL_CMD_TABLE.add_command("@list", cmd_list,priv_tuple=("genperms.game_info",)),
|
||||
|
||||
def cmd_ps(command):
|
||||
"""
|
||||
|
|
@ -131,4 +131,4 @@ def cmd_stats(command):
|
|||
stats_dict["things"],
|
||||
stats_dict["players"],
|
||||
stats_dict["garbage"]))
|
||||
GLOBAL_CMD_TABLE.add_command("@stats", cmd_stats),
|
||||
GLOBAL_CMD_TABLE.add_command("@stats", cmd_stats, priv_tuple=("genperms.game_info",)),
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ def cmd_IRC2chan(command):
|
|||
source_object.emit_to(outstring)
|
||||
|
||||
GLOBAL_CMD_TABLE.add_command("@irc2chan",cmd_IRC2chan,auto_help=True,staff_help=True,
|
||||
priv_tuple=("objects.add_commchannel",))
|
||||
priv_tuple=("irc.admin_irc_channels",))
|
||||
|
||||
def cmd_IRCjoin(command):
|
||||
"""
|
||||
|
|
@ -101,7 +101,7 @@ def cmd_IRCjoin(command):
|
|||
|
||||
GLOBAL_CMD_TABLE.add_command("@ircjoin",cmd_IRCjoin,auto_help=True,
|
||||
staff_help=True,
|
||||
priv_tuple=("objects.add_commchannel",))
|
||||
priv_tuple=("irc.admin_irc_channels",))
|
||||
|
||||
def cmd_IRCchanlist(command):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ def cmd_teleport(command):
|
|||
|
||||
source_object.move_to(target_obj, quiet=tel_quietly)
|
||||
GLOBAL_CMD_TABLE.add_command("@teleport", cmd_teleport,
|
||||
priv_tuple=("genperms.builder"))
|
||||
priv_tuple=("objects.teleport",))
|
||||
|
||||
def cmd_alias(command):
|
||||
"""
|
||||
|
|
@ -165,7 +165,7 @@ def cmd_wipe(command):
|
|||
target_obj.clear_attribute(attr.get_name())
|
||||
source_object.emit_to("%s - %d attributes wiped." % (target_obj.get_name(),
|
||||
len(attr_matches)))
|
||||
GLOBAL_CMD_TABLE.add_command("@wipe", cmd_wipe)
|
||||
GLOBAL_CMD_TABLE.add_command("@wipe", cmd_wipe,priv_tuple=("objects.wipe",))
|
||||
|
||||
def cmd_set(command):
|
||||
"""
|
||||
|
|
@ -250,7 +250,7 @@ def cmd_set(command):
|
|||
s += '\nFlag %s=%s set.' % (target_name, flag.upper())
|
||||
target.set_flag(flag, True)
|
||||
source_object.emit_to(s[1:])
|
||||
GLOBAL_CMD_TABLE.add_command("@set", cmd_set)
|
||||
GLOBAL_CMD_TABLE.add_command("@set", cmd_set, priv_tuple=("objects.modify_attributes",))
|
||||
|
||||
def cmd_cpattr(command):
|
||||
"""
|
||||
|
|
@ -332,7 +332,7 @@ def cmd_cpattr(command):
|
|||
to_objname, to_attr)
|
||||
source_object.emit_to(s)
|
||||
GLOBAL_CMD_TABLE.add_command("@cpattr", cmd_cpattr,
|
||||
priv_tuple=("genperms.builder",))
|
||||
priv_tuple=("objects.modify_attributes",))
|
||||
|
||||
|
||||
def cmd_mvattr(command):
|
||||
|
|
@ -394,7 +394,7 @@ def cmd_mvattr(command):
|
|||
source_object.emit_to(s)
|
||||
|
||||
GLOBAL_CMD_TABLE.add_command("@mvattr", cmd_mvattr,
|
||||
priv_tuple=("genperms.builder",))
|
||||
priv_tuple=("objects.modify_attributes",))
|
||||
|
||||
def cmd_find(command):
|
||||
"""
|
||||
|
|
@ -420,7 +420,7 @@ def cmd_find(command):
|
|||
else:
|
||||
source_object.emit_to("No name matches found for: %s" % (searchstring,))
|
||||
GLOBAL_CMD_TABLE.add_command("@find", cmd_find,
|
||||
priv_tuple=("genperms.builder"))
|
||||
priv_tuple=("objects.info",))
|
||||
|
||||
def cmd_create(command):
|
||||
"""
|
||||
|
|
@ -474,7 +474,7 @@ def cmd_create(command):
|
|||
|
||||
|
||||
GLOBAL_CMD_TABLE.add_command("@create", cmd_create,
|
||||
priv_tuple=("genperms.builder"),auto_help=True,staff_help=True)
|
||||
priv_tuple=("objects.create",),auto_help=True,staff_help=True)
|
||||
|
||||
def cmd_copy(command):
|
||||
"""Usage:
|
||||
|
|
@ -539,7 +539,7 @@ def cmd_copy(command):
|
|||
reset_text = " (using default attrs/flags)"
|
||||
source_object.emit_to("Copied object '%s'%s%s%s." % (objname,name_text,loc_text,reset_text))
|
||||
GLOBAL_CMD_TABLE.add_command("@copy", cmd_copy,
|
||||
priv_tuple=("genperms.builder"),auto_help=True,staff_help=True)
|
||||
priv_tuple=("objects.create",),auto_help=True,staff_help=True)
|
||||
|
||||
|
||||
|
||||
|
|
@ -552,7 +552,7 @@ def cmd_nextfree(command):
|
|||
nextfree = Object.objects.get_nextfree_dbnum()
|
||||
command.source_object.emit_to("Next free object number: #%s" % nextfree)
|
||||
GLOBAL_CMD_TABLE.add_command("@nextfree", cmd_nextfree,
|
||||
priv_tuple=("genperms.builder"),auto_help=True,staff_help=True)
|
||||
priv_tuple=("objects.info",),auto_help=True,staff_help=True)
|
||||
|
||||
def cmd_open(command):
|
||||
"""
|
||||
|
|
@ -625,7 +625,7 @@ def cmd_open(command):
|
|||
None)
|
||||
source_object.emit_to("You open an unlinked exit - %s" % new_object)
|
||||
GLOBAL_CMD_TABLE.add_command("@open", cmd_open,
|
||||
priv_tuple=("genperms.builder"))
|
||||
priv_tuple=("objects.dig",))
|
||||
|
||||
def cmd_chown(command):
|
||||
"""
|
||||
|
|
@ -655,7 +655,7 @@ def cmd_chown(command):
|
|||
if not target_obj:
|
||||
return
|
||||
|
||||
if not source_object.controls_other(target_obj):
|
||||
if not source_object.controls_other(target_obj) and not source_object.has_perm("objects.admin_ownership"):
|
||||
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
||||
return
|
||||
|
||||
|
|
@ -676,7 +676,7 @@ def cmd_chown(command):
|
|||
# We haven't provided a target.
|
||||
source_object.emit_to("Who should be the new owner of the object?")
|
||||
return
|
||||
GLOBAL_CMD_TABLE.add_command("@chown", cmd_chown)
|
||||
GLOBAL_CMD_TABLE.add_command("@chown", cmd_chown, priv_tuple=("objects.modify_attributes","objects.admin_ownership"))
|
||||
|
||||
def cmd_chzone(command):
|
||||
"""
|
||||
|
|
@ -728,7 +728,7 @@ def cmd_chzone(command):
|
|||
# We haven't provided a target zone.
|
||||
source_object.emit_to("What should the object's zone be set to?")
|
||||
return
|
||||
GLOBAL_CMD_TABLE.add_command("@chzone", cmd_chzone)
|
||||
GLOBAL_CMD_TABLE.add_command("@chzone", cmd_chzone, priv_tuple=("objects.dig",))
|
||||
|
||||
def cmd_link(command):
|
||||
"""
|
||||
|
|
@ -780,7 +780,7 @@ def cmd_link(command):
|
|||
source_object.emit_to("You must provide a destination to link to.")
|
||||
return
|
||||
GLOBAL_CMD_TABLE.add_command("@link", cmd_link,
|
||||
priv_tuple=("genperms.builder"))
|
||||
priv_tuple=("objects.dig",))
|
||||
|
||||
def cmd_unlink(command):
|
||||
"""
|
||||
|
|
@ -806,7 +806,7 @@ def cmd_unlink(command):
|
|||
target_obj.set_home(None)
|
||||
source_object.emit_to("You have unlinked %s." % target_obj.get_name())
|
||||
GLOBAL_CMD_TABLE.add_command("@unlink", cmd_unlink,
|
||||
priv_tuple=("genperms.builder"))
|
||||
priv_tuple=("objects.dig",))
|
||||
|
||||
def cmd_dig(command):
|
||||
"""
|
||||
|
|
@ -933,7 +933,7 @@ def cmd_dig(command):
|
|||
source_object.move_to(new_room)
|
||||
|
||||
GLOBAL_CMD_TABLE.add_command("@dig", cmd_dig,
|
||||
priv_tuple=("genperms.builder"),)
|
||||
priv_tuple=("objects.dig",))
|
||||
|
||||
def cmd_name(command):
|
||||
"""
|
||||
|
|
@ -1080,7 +1080,7 @@ def cmd_recover(command):
|
|||
|
||||
|
||||
GLOBAL_CMD_TABLE.add_command("@recover", cmd_recover,
|
||||
priv_tuple=("genperms.builder"),auto_help=True,staff_help=True)
|
||||
priv_tuple=("objects.create",),auto_help=True,staff_help=True)
|
||||
|
||||
def cmd_destroy(command):
|
||||
"""
|
||||
|
|
@ -1157,4 +1157,4 @@ def cmd_destroy(command):
|
|||
source_object.emit_to("You schedule %s for destruction." % target_obj.get_name())
|
||||
|
||||
GLOBAL_CMD_TABLE.add_command("@destroy", cmd_destroy,
|
||||
priv_tuple=("genperms.builder"),auto_help=True,staff_help=True)
|
||||
priv_tuple=("objects.create",),auto_help=True,staff_help=True)
|
||||
|
|
|
|||
|
|
@ -127,4 +127,4 @@ def cmd_page(command):
|
|||
# Now set the LASTPAGED attribute
|
||||
source_object.set_attribute("LASTPAGED", ','.join(
|
||||
["#%d" % (x.id) for x in targets]))
|
||||
GLOBAL_CMD_TABLE.add_command("page", cmd_page),
|
||||
GLOBAL_CMD_TABLE.add_command("page", cmd_page, priv_tuple=('channels.page',))
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@ This file contains commands that require special permissions to use. These
|
|||
are generally @-prefixed commands, but there are exceptions.
|
||||
"""
|
||||
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.auth.models import Group
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import Permission, Group, User
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.conf import settings
|
||||
from src.objects.models import Object
|
||||
|
|
@ -133,7 +131,7 @@ def cmd_newpassword(command):
|
|||
newpass = eq_args[1]
|
||||
|
||||
if not command.command_argument or len(searchstring) == 0:
|
||||
source_object.emit_to("What player's password do you want to change")
|
||||
source_object.emit_to("What player's password do you want to change?")
|
||||
return
|
||||
if len(newpass) == 0:
|
||||
source_object.emit_to("You must supply a new password.")
|
||||
|
|
@ -256,17 +254,30 @@ def cmd_shutdown(command):
|
|||
GLOBAL_CMD_TABLE.add_command("@shutdown", cmd_shutdown,
|
||||
priv_tuple=("genperms.process_control",))
|
||||
|
||||
def cmd_chperm(command):
|
||||
"""@chperm
|
||||
# permission administration
|
||||
|
||||
# Django automatically creates a host of permissions that we don't want to
|
||||
# mess with, but which are not very useful from inside the game. While these
|
||||
# permissions are ok to use, we only show the permissions that we have defined
|
||||
# in our settings file in order to give better control.
|
||||
APPS_NOSHOW = ("news","admin","auth","config","contentypes",
|
||||
"flatpages","news","sessions","sites")
|
||||
SETTINGS_PERM_NAMES = []
|
||||
for apps in settings.PERM_ALL_DEFAULTS + settings.PERM_ALL_CUSTOM:
|
||||
for permtuples in apps:
|
||||
SETTINGS_PERM_NAMES.append(permtuples[1])
|
||||
|
||||
def cmd_setperm(command):
|
||||
"""@setperm
|
||||
Usage:
|
||||
@chperm[/switch] [<user>] = [<permission>]
|
||||
@setperm[/switch] [<user>] = [<permission>]
|
||||
|
||||
Switches:
|
||||
add : add a permission from <user>
|
||||
del : delete a permission from <user>
|
||||
list : list all permissions, or those set on <user>
|
||||
|
||||
@chperm (change permission) sets/clears individual permission bits on a user.
|
||||
This command sets/clears individual permission bits on a user.
|
||||
Use /list without any arguments to see all available permissions or those
|
||||
defined on the <user> argument.
|
||||
"""
|
||||
|
|
@ -276,32 +287,31 @@ def cmd_chperm(command):
|
|||
|
||||
if not args:
|
||||
if "list" not in switches:
|
||||
source_object.emit_to("Usage: @chperm[/switch] [user] = [permission]")
|
||||
source_object.emit_to("Usage: @setperm[/switch] [user] = [permission]")
|
||||
return
|
||||
else:
|
||||
#just print all available permissions
|
||||
s = "\n---Permission name %s ---Description" % (24 * " ")
|
||||
for p in Permission.objects.all():
|
||||
permlist = [perm for perm in Permission.objects.all() if perm.content_type.app_label not in APPS_NOSHOW and
|
||||
perm.name in SETTINGS_PERM_NAMES]
|
||||
for p in permlist:
|
||||
app = p.content_type.app_label
|
||||
s += "\n%s.%s%s\t%s" % (app, p.codename, (35 - len(app) - len(p.codename)) * " ", p.name)
|
||||
if app not in APPS_NOSHOW:
|
||||
s += "\n%s.%s%s\t%s" % (app, p.codename, (35 - len(app) - len(p.codename)) * " ", p.name)
|
||||
source_object.emit_to(s)
|
||||
return
|
||||
#we have command arguments.
|
||||
arglist = args.split('=',1)
|
||||
obj_name = arglist[0].strip()
|
||||
if not obj_name:
|
||||
source_object.emit_to("Usage: @chperm[/switch] [user] [= permission]")
|
||||
source_object.emit_to("Usage: @setperm[/switch] [user] [= permission]")
|
||||
return
|
||||
obj = source_object.search_for_object(obj_name)
|
||||
if not obj:
|
||||
return
|
||||
if not obj.is_player():
|
||||
source_object.emit_to("Only players may have permissions.")
|
||||
return
|
||||
try:
|
||||
user = User.objects.get(username=obj.get_name(show_dbref=False,no_ansi=True))
|
||||
except:
|
||||
raise
|
||||
user = obj.get_user_account()
|
||||
if not user:
|
||||
return
|
||||
if len(arglist) == 1:
|
||||
#if we didn't have any =, we list the permissions set on <object>.
|
||||
s = ""
|
||||
|
|
@ -312,16 +322,18 @@ def cmd_chperm(command):
|
|||
if obj.is_staff():
|
||||
s += "\n Member of staff (can enter Admin interface)"
|
||||
aperms = user.get_all_permissions()
|
||||
if aperms:
|
||||
s += "\n Extra User permissions:"
|
||||
gperms = user.get_group_permissions()
|
||||
for p in aperms:
|
||||
if p in gperms:
|
||||
s += "\n --- %s (from group)" % p
|
||||
else:
|
||||
s += "\n ---- %s (custom assigned)" % p
|
||||
gperms = user.get_group_permissions()
|
||||
uperms = [perm for perm in aperms if perm not in gperms]
|
||||
if gperms:
|
||||
s += "\n Group-inherited Permissions:"
|
||||
for p in gperms:
|
||||
s += "\n --- %s" % p
|
||||
if uperms:
|
||||
s += "\n Individually granted Permisssions:"
|
||||
for p in uperms:
|
||||
s += "\n ---- %s" % p
|
||||
if not s:
|
||||
s = "User %s has no extra permissions." % obj.get_name()
|
||||
s = "User %s has no permissions." % obj.get_name()
|
||||
else:
|
||||
s = "\nPermissions for user %s: %s" % (obj.get_name(),s)
|
||||
source_object.emit_to(s)
|
||||
|
|
@ -338,11 +350,11 @@ def cmd_chperm(command):
|
|||
except Permission.DoesNotExist:
|
||||
source_object.emit_to("Permission type '%s' is not a valid permission.\nUse @chperm/list for help with valid permission strings." % perm_string)
|
||||
return
|
||||
if not switches:
|
||||
source_object.emit_to("You must supply a switch /add or /del.")
|
||||
return
|
||||
if "add" in switches:
|
||||
#add the permission to this user
|
||||
if not source_object.has_perm("auth.add_permission"):
|
||||
source_object.emit_to(defines_global.NOPERMS_MSG)
|
||||
return
|
||||
#add the permission to this user
|
||||
if user.is_superuser:
|
||||
source_object.emit_to("As a superuser you always have all permissions.")
|
||||
return
|
||||
|
|
@ -350,16 +362,12 @@ def cmd_chperm(command):
|
|||
source_object.emit_to("User already has this permission.")
|
||||
return
|
||||
user.user_permissions.add(permission)
|
||||
user.save()
|
||||
obj.save()
|
||||
user.save();obj.save()
|
||||
source_object.emit_to("%s gained the permission '%s'." % (obj.get_name(), permission.name))
|
||||
obj.emit_to("%s gave you the permission '%s'." % (source_object.get_name(show_dbref=False,no_ansi=True),
|
||||
permission.name))
|
||||
if "del" in switches:
|
||||
#delete the permission from this user
|
||||
if not source_object.has_perm("auth.delete_permission"):
|
||||
source_object.emit_to(defines_global.NOPERMS_MSG)
|
||||
return
|
||||
if user.is_superuser:
|
||||
source_object.emit_to("As a superuser you always have all permissions.")
|
||||
return
|
||||
|
|
@ -367,25 +375,24 @@ def cmd_chperm(command):
|
|||
source_object.emit_to("User is already lacking this permission.")
|
||||
return
|
||||
user.user_permissions.remove(permission)
|
||||
user.save()
|
||||
obj.save()
|
||||
user.save();obj.save()
|
||||
source_object.emit_to("%s lost the permission '%s'." % (obj.get_name(), permission.name))
|
||||
obj.emit_to("%s removed your permission '%s'." % (source_object.get_name(show_dbref=False,no_ansi=True),
|
||||
permission.name))
|
||||
GLOBAL_CMD_TABLE.add_command("@chperm", cmd_chperm,
|
||||
priv_tuple=("auth.change_permission",), auto_help=True, staff_help=True)
|
||||
GLOBAL_CMD_TABLE.add_command("@setperm", cmd_setperm,
|
||||
priv_tuple=("auth.change_permission","genperms.admin_perm"), auto_help=True, staff_help=True)
|
||||
|
||||
def cmd_chgroup(command):
|
||||
"""@chgroup
|
||||
def cmd_setgroup(command):
|
||||
"""@setgroup
|
||||
Usage:
|
||||
@chgroup[/switch] [<user>] [= <group>]
|
||||
@setgroup[/switch] [<user>] [= <group>]
|
||||
|
||||
switches
|
||||
add : add user to a group
|
||||
del : remove user from a group
|
||||
list : list all groups a user is part of, or list all available groups if no user is given
|
||||
|
||||
Changes the group membership of a user.
|
||||
Changes and views the group membership of a user.
|
||||
"""
|
||||
source_object = command.source_object
|
||||
args = command.command_argument
|
||||
|
|
@ -393,7 +400,7 @@ def cmd_chgroup(command):
|
|||
|
||||
if not args:
|
||||
if "list" not in switches:
|
||||
source_object.emit_to("Usage: @chgroup[/switch] [user] [= permission]")
|
||||
source_object.emit_to("Usage: @setgroup[/switch] [user] [= permission]")
|
||||
return
|
||||
else:
|
||||
#just print all available permissions
|
||||
|
|
@ -402,14 +409,15 @@ def cmd_chgroup(command):
|
|||
s += "\n %s" % g.name
|
||||
for p in g.permissions.all():
|
||||
app = p.content_type.app_label
|
||||
s += "\n --- %s.%s%s\t%s" % (app, p.codename, (35 - len(app) - len(p.codename)) * " ", p.name)
|
||||
if app not in APPS_NOSHOW:
|
||||
s += "\n --- %s.%s%s\t%s" % (app, p.codename, (35 - len(app) - len(p.codename)) * " ", p.name)
|
||||
source_object.emit_to(s)
|
||||
return
|
||||
#we have command arguments.
|
||||
arglist = args.split('=',1)
|
||||
obj_name = arglist[0].strip()
|
||||
if not obj_name:
|
||||
source_object.emit_to("Usage: @chgroup[/switch] [user] = [permission]")
|
||||
source_object.emit_to("Usage: @setgroup[/switch] [user] = [permission]")
|
||||
return
|
||||
obj = source_object.search_for_object(obj_name)
|
||||
if not obj:
|
||||
|
|
@ -417,10 +425,9 @@ def cmd_chgroup(command):
|
|||
if not obj.is_player():
|
||||
source_object.emit_to("Only players may be members of permission groups.")
|
||||
return
|
||||
try:
|
||||
user = User.objects.get(username=obj.get_name(show_dbref=False,no_ansi=True))
|
||||
except:
|
||||
raise
|
||||
user = obj.get_user_account()
|
||||
if not user:
|
||||
return
|
||||
if len(arglist) == 1:
|
||||
#if we didn't have any =, we list the groups this user is member of
|
||||
s = ""
|
||||
|
|
@ -429,7 +436,10 @@ def cmd_chgroup(command):
|
|||
if not user.is_active:
|
||||
s += "\n ACCOUNT NOT ACTIVE."
|
||||
for g in user.groups.all():
|
||||
s += "\n --- %s" % g
|
||||
s += "\n --- %s" % g
|
||||
for p in g.permissions.all():
|
||||
app = p.content_type.app_label
|
||||
s += "\n -- %s.%s%s\t%s" % (app, p.codename, (35 - len(app) - len(p.codename)) * " ", p.name)
|
||||
if not s:
|
||||
s = "User %s is not a member of any groups." % obj.get_name()
|
||||
else:
|
||||
|
|
@ -439,15 +449,15 @@ def cmd_chgroup(command):
|
|||
# we supplied an argument on the form obj = group
|
||||
group_string = arglist[1].strip()
|
||||
try:
|
||||
group = Group.objects.get(name=group_string)
|
||||
group = Group.objects.get(name=group_string)
|
||||
except Group.DoesNotExist:
|
||||
source_object.emit_to("Group '%s' is not a valid group. Remember that the name is case-sensitive.\nUse @chperm/list for help with valid group names." % group_string)
|
||||
return
|
||||
if not switches:
|
||||
source_object.emit_to("You must supply a switch /add or /del.")
|
||||
return
|
||||
if "add" in switches:
|
||||
#add the user to this group
|
||||
if not source_object.has_perm("auth.add_group"):
|
||||
source_object.emit_to(defines_global.NOPERMS_MSG)
|
||||
return
|
||||
if user.is_superuser:
|
||||
source_object.emit_to("As a superuser, group access does not matter.")
|
||||
return
|
||||
|
|
@ -455,16 +465,12 @@ def cmd_chgroup(command):
|
|||
source_object.emit_to("User is already a member of this group.")
|
||||
return
|
||||
user.groups.add(group)
|
||||
user.save()
|
||||
obj.save()
|
||||
user.save(); obj.save()
|
||||
source_object.emit_to("%s added to group '%s'." % (obj.get_name(), group.name))
|
||||
obj.emit_to("%s added you to the group '%s'." % (source_object.get_name(show_dbref=False,no_ansi=True),
|
||||
group.name))
|
||||
if "del" in switches:
|
||||
#delete the permission from this user
|
||||
if not source_object.has_perm("auth.delete_group"):
|
||||
source_object.emit_to(defines_global.NOPERMS_MSG)
|
||||
return
|
||||
if user.is_superuser:
|
||||
source_object.emit_to("As a superuser, group access does not matter.")
|
||||
return
|
||||
|
|
@ -473,10 +479,10 @@ def cmd_chgroup(command):
|
|||
return
|
||||
|
||||
user.groups.remove(group)
|
||||
user.save()
|
||||
obj.save()
|
||||
user.save(); obj.save()
|
||||
source_object.emit_to("%s was removed from group '%s'." % (obj.get_name(), group.name))
|
||||
obj.emit_to("%s removed you from group '%s'." % (source_object.get_name(show_dbref=False,no_ansi=True),
|
||||
group.name))
|
||||
GLOBAL_CMD_TABLE.add_command("@chgroup", cmd_chgroup,
|
||||
priv_tuple=("auth.change_group",), auto_help=True, staff_help=True)
|
||||
GLOBAL_CMD_TABLE.add_command("@setgroup", cmd_setgroup,
|
||||
priv_tuple=("auth.change_group","genperms.admin_group"), auto_help=True, staff_help=True)
|
||||
|
||||
|
|
|
|||
|
|
@ -232,4 +232,4 @@ def cmd_search(command):
|
|||
|
||||
display_results(source_object, search_query)
|
||||
GLOBAL_CMD_TABLE.add_command("@search", cmd_search,
|
||||
priv_tuple=("genperms.builder")),
|
||||
priv_tuple=("objects.info")),
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
"""
|
||||
Commands that are available from the connect screen.
|
||||
"""
|
||||
import traceback
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from src.objects.models import Attribute, Object
|
||||
from src import defines_global
|
||||
from src.util import functions_general
|
||||
from src.cmdtable import GLOBAL_UNCON_CMD_TABLE
|
||||
from src.logger import log_errmsg
|
||||
|
||||
def cmd_connect(command):
|
||||
"""
|
||||
|
|
@ -104,7 +105,14 @@ def cmd_create(command):
|
|||
elif len(password) < 3:
|
||||
session.msg("Your password must be at least 3 characters or longer.\n\rFor best security, make it at least 8 characters long, avoid making it a real word and mix numbers into it.")
|
||||
else:
|
||||
Object.objects.create_user(command, uname, email, password)
|
||||
try:
|
||||
Object.objects.create_user(command, uname, email, password)
|
||||
except:
|
||||
# we have to handle traceback ourself at this point, if we don't errors will givo no feedback.
|
||||
session.msg("This is a bug. Please e-mail an admin if the problem persists.\n%s" % traceback.format_exc())
|
||||
log_errmsg(traceback.format_exc())
|
||||
raise
|
||||
|
||||
GLOBAL_UNCON_CMD_TABLE.add_command("create", cmd_create)
|
||||
|
||||
def cmd_quit(command):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue