def am_deleteuser(annroot, userhome, options): """ Delete Annalist/Django user account. annroot is the root directory for theannalist software installation. userhome is the home directory for the host system user issuing the command. options contains options parsed from the command line. returns 0 if all is well, or a non-zero status code. This value is intended to be used as an exit status code for the calling program. """ prompt_prefix = "Delete user" if len(options.args) > 1: print("Unexpected arguments for %s: (%s)"%(options.command, " ".join(options.args)), file=sys.stderr) return am_errors.AM_UNEXPECTEDARGS sitesettings = get_site_settings(annroot, userhome, options) if not sitesettings: return am_errors.AM_NOSETTINGS user_name = get_user_name(options, prompt_prefix) # from django.contrib.auth.models import User # import deferred until after sitesettings import userqueryset = User.objects.filter(username=user_name) if not userqueryset: print("User %s does not exist"%user_name, file=sys.stderr) return am_errors.AM_USERNOTEXISTS userqueryset.delete() site = am_get_site(sitesettings) delete_user_permissions(site, user_name) return am_errors.AM_SUCCESS
def am_deleteuser(annroot, userhome, options): """ Delete Annalist/Django user account. annroot is the root directory for theannalist software installation. userhome is the home directory for the host system user issuing the command. options contains options parsed from the command line. returns 0 if all is well, or a non-zero status code. This value is intended to be used as an exit status code for the calling program. """ prompt_prefix = "Delete user" if len(options.args) > 1: print("Unexpected arguments for %s: (%s)"%(options.command, " ".join(options.args)), file=sys.stderr) return am_errors.AM_UNEXPECTEDARGS sitesettings = am_get_site_settings(annroot, userhome, options) if not sitesettings: return am_errors.AM_NOSETTINGS user_name = get_user_name(options, prompt_prefix) # from django.contrib.auth.models import User # import deferred until after sitesettings import userqueryset = User.objects.filter(username=user_name) if not userqueryset: print("User %s does not exist"%user_name, file=sys.stderr) return am_errors.AM_USERNOTEXISTS userqueryset.delete() site = am_get_site(sitesettings) delete_user_permissions(site, user_name) return am_errors.AM_SUCCESS
def get_settings_site(annroot, userhome, options): """ Get settings and site data based on command line options provided returns: (status, settings, site) where 'settings' and/or 'site' are None if not found. """ status = am_errors.AM_SUCCESS settings = am_get_settings(annroot, userhome, options) site = None if not settings: print("Settings not found (%s)" % (options.configuration), file=sys.stderr) status = am_errors.AM_NOSETTINGS if status == am_errors.AM_SUCCESS: sitesettings = am_get_site_settings(annroot, userhome, options) if not sitesettings: print("Site settings not found (%s)" % (options.configuration), file=sys.stderr) status = am_errors.AM_NOSETTINGS if status == am_errors.AM_SUCCESS: site = am_get_site(sitesettings) return (status, settings, site)
def create_site_permissions(sitesettings, user_details, permissions): site = am_get_site(sitesettings) if not 'label' in user_details: user_details['label'] = ("%(first_name)s %(last_name)s" % user_details) if not 'comment' in user_details: user_details['comment'] = ( "User %(name)s: site permissions for %(first_name)s %(last_name)s" % user_details) user = create_user_permissions(site, user_details['name'], user_details['uri'], user_details['label'], user_details['comment'], permissions) return am_errors.AM_SUCCESS
def create_site_permissions(sitesettings, user_details, permissions): site = am_get_site(sitesettings) if not 'label' in user_details: user_details['label'] = ( "%(first_name)s %(last_name)s"%user_details ) if not 'comment' in user_details: user_details['comment'] = ( "User %(name)s: site permissions for %(first_name)s %(last_name)s"%user_details ) user = create_user_permissions( site, user_details['name'], user_details['uri'], user_details['label'], user_details['comment'], permissions ) return am_errors.AM_SUCCESS
def get_settings_site(annroot, userhome, options): """ Get settings and site data based on command line options provided returns: (status, settings, site) where 'settings' and/or 'site' are None if not found. """ status = am_errors.AM_SUCCESS settings = am_get_settings(annroot, userhome, options) site = None if not settings: print("Settings not found (%s)"%(options.configuration), file=sys.stderr) status = am_errors.AM_NOSETTINGS if status == am_errors.AM_SUCCESS: sitesettings = am_get_site_settings(annroot, userhome, options) if not sitesettings: print("Site settings not found (%s)"%(options.configuration), file=sys.stderr) status = am_errors.AM_NOSETTINGS if status == am_errors.AM_SUCCESS: site = am_get_site(sitesettings) return (status, settings, site)