<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import base64 <EOL> import os <EOL> import stat <EOL> import time <EOL> import logging <EOL> from tornado import auth , template , escape <EOL> from viewfinder . backend . base import handler , util <EOL> from viewfinder . backend . db import db_client , schema , vf_schema , user <EOL> from viewfinder . backend . www . admin import admin <EOL> from viewfinder . backend . storage . object_store import ObjectStore <EOL> from viewfinder . backend . www . admin import data_table <EOL> class UserLogHandler ( admin . AdminHandler ) : <EOL> """<STR_LIT>""" <EOL> @ handler . authenticated ( ) <EOL> @ handler . asynchronous ( datastore = True ) <EOL> @ admin . require_permission ( level = '<STR_LIT:root>' ) <EOL> def get ( self ) : <EOL> user_id = self . get_argument ( '<STR_LIT>' , None ) <EOL> user_email = self . get_argument ( '<STR_LIT>' , None ) <EOL> t_dict = { '<STR_LIT>' : user_id , '<STR_LIT>' : user_email } <EOL> t_dict . update ( self . PermissionsTemplateDict ( ) ) <EOL> if user_id is not None : <EOL> if user_id . isdigit ( ) : <EOL> t_dict [ '<STR_LIT>' ] = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> data_source_page = '<STR_LIT>' <EOL> template = '<STR_LIT>' <EOL> else : <EOL> t_dict [ '<STR_LIT>' ] = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> data_source_page = '<STR_LIT>' <EOL> template = '<STR_LIT>' <EOL> t_dict [ '<STR_LIT>' ] = '<STR_LIT>' % ( self . request . host , data_source_page , self . request . query ) <EOL> t_dict [ '<STR_LIT>' ] = list ( ) <EOL> t_dict [ '<STR_LIT>' ] = user_email <EOL> self . render ( template , ** t_dict ) <EOL> else : <EOL> self . render ( '<STR_LIT>' , ** t_dict ) <EOL> class UserLogDataHandler ( data_table . AdminDataTableHandler ) : <EOL> """<STR_LIT>""" <EOL> DB_TABLE = '<STR_LIT>' <EOL> def _FormatResult ( self , key ) : <EOL> loginfo = key . split ( '<STR_LIT:/>' ) <EOL> if loginfo [ <NUM_LIT:2> ] == '<STR_LIT>' : <EOL> loginfo = loginfo [ <NUM_LIT:1> : <NUM_LIT:2> ] + loginfo [ <NUM_LIT:3> : ] <EOL> else : <EOL> loginfo = [ loginfo [ <NUM_LIT:1> ] , None , loginfo [ <NUM_LIT:2> ] , None ] <EOL> url = self . _log_store . GenerateUrl ( key ) <EOL> loginfo . append ( '<STR_LIT>' % ( url , url ) ) <EOL> return loginfo <EOL> def _GetOpLogPrefix ( self , user_id , timestamp = None ) : <EOL> return '<STR_LIT>' % user_id <EOL> @ handler . authenticated ( ) <EOL> @ handler . asynchronous ( datastore = True , log_store = True ) <EOL> @ admin . require_permission ( level = '<STR_LIT:root>' ) <EOL> def get ( self ) : <EOL> user_id = self . get_argument ( '<STR_LIT>' , None ) <EOL> key_prefix = self . _GetOpLogPrefix ( user_id ) <EOL> req = self . ReadTablePageRequest ( self . DB_TABLE ) <EOL> last_key , _ = req . last_key if req . last_key is not None else ( None , None ) <EOL> def _OnGetKeys ( items ) : <EOL> rows = [ self . _FormatResult ( item ) for item in items ] <EOL> last_marker = items [ - <NUM_LIT:1> ] if len ( items ) > <NUM_LIT:0> else '<STR_LIT>' <EOL> self . WriteTablePageResponse ( rows , db_client . DBKey ( last_marker , None ) ) <EOL> self . _log_store . ListKeys ( _OnGetKeys , prefix = key_prefix , marker = last_key , maxkeys = req . length ) <EOL> class UserNameDataHandler ( data_table . AdminDataTableHandler ) : <EOL> """<STR_LIT>""" <EOL> DB_TABLE = '<STR_LIT:user>' <EOL> def _FormatResult ( self , user ) : <EOL> email = escape . url_escape ( user . email ) if user . email else '<STR_LIT:->' <EOL> user_url = '<STR_LIT>' % ( user . user_id , email ) <EOL> return [ user_url . format ( escape . utf8 ( escape . xhtml_escape ( item ) ) ) <EOL> for item in [ user . name or '<STR_LIT:->' , email , str ( user . user_id ) ] ] <EOL> @ handler . authenticated ( ) <EOL> @ handler . asynchronous ( datastore = True ) <EOL> @ admin . require_permission ( level = '<STR_LIT:root>' ) <EOL> def get ( self ) : <EOL> user_search = self . get_argument ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> query_string = ( '<STR_LIT>' , { '<STR_LIT>' : user_search } ) <EOL> req = self . ReadTablePageRequest ( self . DB_TABLE ) <EOL> def _OnGetUsers ( users ) : <EOL> last_key = users [ - <NUM_LIT:1> ] . _GetIndexKey ( ) if len ( users ) > <NUM_LIT:0> else None <EOL> rows = [ self . _FormatResult ( user ) for user in users ] <EOL> self . WriteTablePageResponse ( rows , last_key ) <EOL> user . User . IndexQuery ( self . _client , query_string , [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT:email>' ] , <EOL> callback = _OnGetUsers , limit = req . length , start_index_key = req . last_key ) </s>
