diff --git a/manage.py b/manage.py index a9c91c61..a00bdad3 100755 --- a/manage.py +++ b/manage.py @@ -80,18 +80,22 @@ def drop_tables(): @users_manager.option('name', help="User's full name") @users_manager.option('--admin', dest='is_admin', action="store_true", default=False, help="set user as admin") @users_manager.option('--google', dest='google_auth', action="store_true", default=False, help="user uses Google Auth to login") -def create(email, name, is_admin=False, google_auth=False): +@users_manager.option('--password', dest='password', default=None, help="Password for users who don't use Google Auth (leave blank for prompt).") +@users_manager.option('--permissions', dest='permissions', default=models.User.DEFAULT_PERMISSIONS, help="Comma seperated list of permissions (leave blank for default).") +def create(email, name, permissions, 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(permissions, basestring): + permissions = permissions.split(',') + permissions.remove('') # in case it was empty string - permissions = models.User.DEFAULT_PERMISSIONS if is_admin: permissions += ['admin'] user = models.User(email=email, name=name, permissions=permissions) if not google_auth: - password = prompt_pass("Password") + password = password or prompt_pass("Password") user.hash_password(password) try: diff --git a/migrations/add_view_query_permission.py b/migrations/add_view_query_permission.py new file mode 100644 index 00000000..7eb9ccc8 --- /dev/null +++ b/migrations/add_view_query_permission.py @@ -0,0 +1,13 @@ +import peewee +from redash import db +from redash import models + + +if __name__ == '__main__': + db.connect_db() + + previous_default_permissions = models.User.DEFAULT_PERMISSIONS[:] + previous_default_permissions.remove('view_query') + models.User.update(permissions=peewee.fn.array_append(models.User.permissions, 'view_query')).where(peewee.SQL("'view_source' = any(permissions)")).execute() + + db.close_db(None) diff --git a/rd_ui/app/index.html b/rd_ui/app/index.html index 1a74f80f..efc4000e 100644 --- a/rd_ui/app/index.html +++ b/rd_ui/app/index.html @@ -55,7 +55,7 @@