<s> from modularodm import fields <EOL> from framework . auth . core import Auth <EOL> from website . addons . base import exceptions <EOL> from website . addons . base import AddonOAuthUserSettingsBase , AddonOAuthNodeSettingsBase <EOL> from website . addons . base import StorageAddonBase <EOL> from website . addons . s3 . provider import S3Provider <EOL> from website . addons . s3 . serializer import S3Serializer <EOL> from website . addons . s3 . settings import ENCRYPT_UPLOADS_DEFAULT <EOL> class S3UserSettings ( AddonOAuthUserSettingsBase ) : <EOL> oauth_provider = S3Provider <EOL> serializer = S3Serializer <EOL> class S3NodeSettings ( StorageAddonBase , AddonOAuthNodeSettingsBase ) : <EOL> oauth_provider = S3Provider <EOL> serializer = S3Serializer <EOL> bucket = fields . StringField ( ) <EOL> encrypt_uploads = fields . BooleanField ( default = ENCRYPT_UPLOADS_DEFAULT ) <EOL> @ property <EOL> def folder_name ( self ) : <EOL> return self . bucket <EOL> @ property <EOL> def folder_id ( self ) : <EOL> return self . bucket <EOL> @ property <EOL> def folder_path ( self ) : <EOL> return self . bucket <EOL> def fetch_folder_name ( self ) : <EOL> return self . folder_name <EOL> @ property <EOL> def display_name ( self ) : <EOL> return u'<STR_LIT>' . format ( self . config . full_name , self . bucket ) <EOL> def set_folder ( self , folder_id , auth ) : <EOL> self . bucket = str ( folder_id ) <EOL> self . save ( ) <EOL> self . nodelogger . log ( action = "<STR_LIT>" , extra = { '<STR_LIT>' : str ( folder_id ) } , save = True ) <EOL> @ property <EOL> def complete ( self ) : <EOL> return self . has_auth and self . bucket is not None <EOL> def authorize ( self , user_settings , save = False ) : <EOL> self . user_settings = user_settings <EOL> self . nodelogger . log ( action = '<STR_LIT>' , save = save ) <EOL> def clear_settings ( self ) : <EOL> self . bucket = None <EOL> def deauthorize ( self , auth = None , log = True ) : <EOL> """<STR_LIT>""" <EOL> self . clear_settings ( ) <EOL> self . clear_auth ( ) <EOL> if log : <EOL> self . nodelogger . log ( action = '<STR_LIT>' , save = True ) <EOL> def delete ( self , save = True ) : <EOL> self . deauthorize ( log = False ) <EOL> super ( S3NodeSettings , self ) . delete ( save = save ) <EOL> def serialize_waterbutler_credentials ( self ) : <EOL> if not self . has_auth : <EOL> raise exceptions . AddonError ( '<STR_LIT>' ) <EOL> return { <EOL> '<STR_LIT>' : self . external_account . oauth_key , <EOL> '<STR_LIT>' : self . external_account . oauth_secret , <EOL> } <EOL> def serialize_waterbutler_settings ( self ) : <EOL> if not self . bucket : <EOL> raise exceptions . AddonError ( '<STR_LIT>' ) <EOL> return { <EOL> '<STR_LIT>' : self . bucket , <EOL> '<STR_LIT>' : self . encrypt_uploads <EOL> } <EOL> def create_waterbutler_log ( self , auth , action , metadata ) : <EOL> url = self . owner . web_url_for ( '<STR_LIT>' , path = metadata [ '<STR_LIT:path>' ] , provider = '<STR_LIT>' ) <EOL> self . owner . add_log ( <EOL> '<STR_LIT>' . format ( action ) , <EOL> auth = auth , <EOL> params = { <EOL> '<STR_LIT>' : self . owner . parent_id , <EOL> '<STR_LIT>' : self . owner . _id , <EOL> '<STR_LIT:path>' : metadata [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : self . bucket , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : url , <EOL> '<STR_LIT>' : url + '<STR_LIT>' <EOL> } <EOL> } , <EOL> ) <EOL> def after_delete ( self , node , user ) : <EOL> self . deauthorize ( Auth ( user = user ) , log = True ) </s>
