mirror of
https://github.com/valitydev/redash.git
synced 2024-11-07 09:28:51 +00:00
Fix CLI to work with organizations
This commit is contained in:
parent
224998c62a
commit
5e58818043
@ -6,6 +6,7 @@ from redash.query_runner import query_runners, validate_configuration
|
||||
|
||||
manager = Manager(help="Data sources management commands.")
|
||||
|
||||
|
||||
@manager.command
|
||||
def list():
|
||||
"""List currently configured data sources"""
|
||||
@ -27,6 +28,7 @@ def validate_data_source_options(type, options):
|
||||
print "Error: invalid configuration."
|
||||
exit()
|
||||
|
||||
|
||||
@manager.command
|
||||
def new(name=None, type=None, options=None):
|
||||
"""Create new data source"""
|
||||
@ -82,7 +84,8 @@ def new(name=None, type=None, options=None):
|
||||
|
||||
data_source = models.DataSource.create(name=name,
|
||||
type=type,
|
||||
options=options)
|
||||
options=options,
|
||||
org=models.Organization.get_by_slug('default'))
|
||||
print "Id: {}".format(data_source.id)
|
||||
|
||||
|
||||
|
@ -7,7 +7,7 @@ manager = Manager(help="Users management commands. This commands assume single o
|
||||
@manager.option('email', help="email address of the user to grant admin to")
|
||||
def grant_admin(email):
|
||||
try:
|
||||
user = models.User.get_by_email(email)
|
||||
user = models.User.get_by_email_and_org(email, models.Organization.get_by_slug('default'))
|
||||
|
||||
user.groups.append('admin')
|
||||
user.save()
|
||||
@ -17,33 +17,38 @@ def grant_admin(email):
|
||||
print "User [%s] not found." % email
|
||||
|
||||
|
||||
# TODO(@arikfr): This needs to be updated to the new org/groups scheme to work.
|
||||
# @manager.option('email', help="User's email")
|
||||
# @manager.option('name', help="User's full name")
|
||||
# @manager.option('--admin', dest='is_admin', action="store_true", default=False, help="set user as admin")
|
||||
# @manager.option('--google', dest='google_auth', action="store_true", default=False, help="user uses Google Auth to login")
|
||||
# @manager.option('--password', dest='password', default=None, help="Password for users who don't use Google Auth (leave blank for prompt).")
|
||||
# @manager.option('--groups', dest='groups', default=models.User.DEFAULT_GROUPS, help="Comma seperated list of groups (leave blank for default).")
|
||||
# def create(email, name, groups, is_admin=False, google_auth=False, password=None):
|
||||
# print "Creating user (%s, %s)..." % (email, name)
|
||||
# print "Admin: %r" % is_admin
|
||||
# print "Login with Google Auth: %r\n" % google_auth
|
||||
# if isinstance(groups, basestring):
|
||||
# groups= groups.split(',')
|
||||
# groups.remove('') # in case it was empty string
|
||||
#
|
||||
# if is_admin:
|
||||
# groups += ['admin']
|
||||
#
|
||||
# user = models.User(email=email, name=name, groups=groups)
|
||||
# if not google_auth:
|
||||
# password = password or prompt_pass("Password")
|
||||
# user.hash_password(password)
|
||||
#
|
||||
# try:
|
||||
# user.save()
|
||||
# except Exception, e:
|
||||
# print "Failed creating user: %s" % e.message
|
||||
@manager.option('email', help="User's email")
|
||||
@manager.option('name', help="User's full name")
|
||||
@manager.option('--admin', dest='is_admin', action="store_true", default=False, help="set user as admin")
|
||||
@manager.option('--google', dest='google_auth', action="store_true", default=False, help="user uses Google Auth to login")
|
||||
@manager.option('--password', dest='password', default=None, help="Password for users who don't use Google Auth (leave blank for prompt).")
|
||||
@manager.option('--groups', dest='groups', default=None, help="Comma seperated list of groups (leave blank for default).")
|
||||
def create(email, name, groups, is_admin=False, google_auth=False, password=None):
|
||||
print "Creating user (%s, %s)..." % (email, name)
|
||||
print "Admin: %r" % is_admin
|
||||
print "Login with Google Auth: %r\n" % google_auth
|
||||
|
||||
org = models.Organization.get_by_slug('default')
|
||||
if isinstance(groups, basestring):
|
||||
groups= groups.split(',')
|
||||
groups.remove('') # in case it was empty string
|
||||
groups = [int(g) for g in groups]
|
||||
|
||||
if groups is None:
|
||||
groups = [models.Group.get(models.Group.name=="default", models.Group.org==org).id]
|
||||
|
||||
if is_admin:
|
||||
groups += [models.Group.get(models.Group.name=="admin", models.Group.org==org).id]
|
||||
|
||||
user = models.User(email=email, name=name, groups=groups)
|
||||
if not google_auth:
|
||||
password = password or prompt_pass("Password")
|
||||
user.hash_password(password)
|
||||
|
||||
try:
|
||||
user.save()
|
||||
except Exception, e:
|
||||
print "Failed creating user: %s" % e.message
|
||||
|
||||
|
||||
@manager.option('email', help="email address of user to delete")
|
||||
@ -56,7 +61,7 @@ def delete(email):
|
||||
@manager.option('email', help="email address of the user to change password for")
|
||||
def password(email, password):
|
||||
try:
|
||||
user = models.User.get_by_email(email)
|
||||
user = models.User.get_by_email_and_org(email, models.Organization.get_by_slug('default'))
|
||||
|
||||
user.hash_password(password)
|
||||
user.save()
|
||||
|
Loading…
Reference in New Issue
Block a user