<s> from grouper . email_util import send_email <EOL> from grouper . fe . settings import settings <EOL> from grouper . fe . util import GrouperHandler <EOL> from grouper . model_soup import User <EOL> from grouper . models . audit_log import AuditLog <EOL> from grouper . public_key import delete_public_key , get_public_key , KeyNotFound <EOL> class PublicKeyDelete ( GrouperHandler ) : <EOL> def get ( self , user_id = None , name = None , key_id = None ) : <EOL> user = User . get ( self . session , user_id , name ) <EOL> if not user : <EOL> return self . notfound ( ) <EOL> if ( user . name != self . current_user . name ) and not self . current_user . user_admin : <EOL> return self . forbidden ( ) <EOL> try : <EOL> key = get_public_key ( self . session , user . id , key_id ) <EOL> except KeyNotFound : <EOL> return self . notfound ( ) <EOL> self . render ( "<STR_LIT>" , user = user , key = key ) <EOL> def post ( self , user_id = None , name = None , key_id = None ) : <EOL> user = User . get ( self . session , user_id , name ) <EOL> if not user : <EOL> return self . notfound ( ) <EOL> if ( user . name != self . current_user . name ) and not self . current_user . user_admin : <EOL> return self . forbidden ( ) <EOL> try : <EOL> key = get_public_key ( self . session , user . id , key_id ) <EOL> delete_public_key ( self . session , user . id , key_id ) <EOL> except KeyNotFound : <EOL> return self . notfound ( ) <EOL> AuditLog . log ( self . session , self . current_user . id , '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( key . fingerprint ) , <EOL> on_user_id = user . id ) <EOL> email_context = { <EOL> "<STR_LIT>" : self . current_user . name , <EOL> "<STR_LIT>" : user . name , <EOL> "<STR_LIT:action>" : "<STR_LIT>" , <EOL> } <EOL> send_email ( self . session , [ user . name ] , '<STR_LIT>' , '<STR_LIT>' , <EOL> settings , email_context ) <EOL> return self . redirect ( "<STR_LIT>" . format ( user . name ) ) </s>
