Skip to content

Instantly share code, notes, and snippets.

@jmchilton
Created January 7, 2013 15:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jmchilton/4475646 to your computer and use it in GitHub Desktop.
Save jmchilton/4475646 to your computer and use it in GitHub Desktop.
Place in galaxy home directory and run to create users.
from scripts.db_shell import *
from galaxy.util.bunch import Bunch
from galaxy.security import GalaxyRBACAgent
bunch = Bunch( **globals() )
bunch.engine = engine
# model.flush() has been removed.
bunch.session = db_session
# For backward compatibility with "model.context.current"
bunch.context = db_session
security_agent = GalaxyRBACAgent( bunch )
security_agent.sa_session = sa_session
def add_user(email, password, key=None):
query = sa_session.query( User ).filter_by( email=email )
if query.count() > 0:
return query.first()
else:
user = User(email)
user.set_password_cleartext(password)
sa_session.add(user)
sa_session.flush()
security_agent.create_private_user_role( user )
if not user.default_permissions:
security_agent.user_set_default_permissions( user,
history=True, dataset=True )
if key is not None:
api_key = APIKeys()
api_key.user_id = user.id
api_key.key = key
sa_session.add(api_key)
sa_session.flush()
return user
add_user("user1", "pass1")
add_user("user2", "pass2")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment