#NEWLINE# @ logged ( ) #NEWLINE# def create_external_user( self , external_user , external_id , system , group_names ) : #NEWLINE# #INDENT# session = self . Session ( ) #NEWLINE# try : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# auth_type = session . query ( model . DbAuthType ) . filter_by ( name = system ) . one ( ) #NEWLINE# auth = auth_type . auths [ 0 ] #NEWLINE# #UNINDENT# except ( NoResultFound , KeyError ) : #NEWLINE# #INDENT# raise DbErrors . DbUserNotFoundError ( ( "System '%s' not found in database" % system ) ) #NEWLINE# #UNINDENT# groups = [ ] #NEWLINE# for group_name in group_names : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# group = session . query ( model . DbGroup ) . filter_by ( name = group_name ) . one ( ) #NEWLINE# #UNINDENT# except NoResultFound : #NEWLINE# #INDENT# raise DbErrors . DbUserNotFoundError ( ( "Group '%s' not found in database" % group_name ) ) #NEWLINE# #UNINDENT# groups . append ( group ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# role = session . query ( model . DbRole ) . filter_by ( name = external_user . role . name ) . one ( ) #NEWLINE# user = model . DbUser ( external_user . login , external_user . full_name , external_user . email , role = role ) #NEWLINE# user_auth = model . DbUserAuth ( user , auth , configuration = external_id ) #NEWLINE# for group in groups : #NEWLINE# #INDENT# group . users . append ( user ) #NEWLINE# #UNINDENT# session . add ( user ) #NEWLINE# session . add ( user_auth ) #NEWLINE# session . commit ( ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# log . log ( DatabaseGateway , log . level . Warning , ( "Couldn't create user: %s" % group ) ) #NEWLINE# log . log_exc ( DatabaseGateway , log . level . Info ) #NEWLINE# raise DbErrors . DatabaseError ( "Couldn't create user! Contact administrator" ) #NEWLINE# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# session . close ( )