diff options
author | Duda Dornelles <ddornell@thoughtworks.com> | 2014-10-15 15:46:53 +0200 |
---|---|---|
committer | Duda Dornelles <ddornell@thoughtworks.com> | 2014-10-15 15:46:58 +0200 |
commit | 160520dbdec17250a74d5f87174cacb3f72eae26 (patch) | |
tree | 8ded99e1dc73bc4c277061b335633511eaa49b35 /service/pixelated | |
parent | b17bba7c89bf495ec882e5beebe97859dbedf094 (diff) |
Extracting features controller
Diffstat (limited to 'service/pixelated')
-rw-r--r-- | service/pixelated/adapter/pixelated_mail.py | 3 | ||||
-rw-r--r-- | service/pixelated/controllers/__init__.py | 1 | ||||
-rw-r--r-- | service/pixelated/controllers/features_controller.py | 32 | ||||
-rw-r--r-- | service/pixelated/user_agent.py | 49 |
4 files changed, 53 insertions, 32 deletions
diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py index 6be2e5bf..6ebcc089 100644 --- a/service/pixelated/adapter/pixelated_mail.py +++ b/service/pixelated/adapter/pixelated_mail.py @@ -26,6 +26,7 @@ from pycryptopp.hash import sha256 class InputMail: + FROM_EMAIL_ADDRESS = None def __init__(self): self._raw_message = None @@ -141,7 +142,7 @@ class InputMail: def to_smtp_format(self): mime_multipart = self.to_mime_multipart() - mime_multipart['From'] = PixelatedMail.from_email_address + mime_multipart['From'] = InputMail.FROM_EMAIL_ADDRESS return mime_multipart.as_string() @staticmethod diff --git a/service/pixelated/controllers/__init__.py b/service/pixelated/controllers/__init__.py index 84d7bf4d..fd14b01b 100644 --- a/service/pixelated/controllers/__init__.py +++ b/service/pixelated/controllers/__init__.py @@ -27,3 +27,4 @@ from flask import Response from home_controller import HomeController from mails_controller import MailsController from tags_controller import TagsController +from features_controller import FeaturesController diff --git a/service/pixelated/controllers/features_controller.py b/service/pixelated/controllers/features_controller.py new file mode 100644 index 00000000..d3438352 --- /dev/null +++ b/service/pixelated/controllers/features_controller.py @@ -0,0 +1,32 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + +from pixelated.controllers import respond_json +import os + + +class FeaturesController: + DISABLED_FEATURES = ['draftReply', 'signatureStatus', 'encryptionStatus', 'contacts'] + + def __init__(self): + pass + + def features(self): + try: + disabled_features = {'logout': os.environ['DISPATCHER_LOGOUT_URL']} + except KeyError: + disabled_features = {} + return respond_json({'disabled_features': self.DISABLED_FEATURES, 'dispatcher_features': disabled_features})
\ No newline at end of file diff --git a/service/pixelated/user_agent.py b/service/pixelated/user_agent.py index 6dca31ae..687433d7 100644 --- a/service/pixelated/user_agent.py +++ b/service/pixelated/user_agent.py @@ -28,7 +28,7 @@ from pixelated.bitmask_libraries.config import LeapConfig from pixelated.bitmask_libraries.provider import LeapProvider from pixelated.bitmask_libraries.auth import LeapAuthenticator, LeapCredentials from pixelated.adapter.mail_service import MailService -from pixelated.adapter.pixelated_mail import PixelatedMail +from pixelated.adapter.pixelated_mail import InputMail from pixelated.adapter.soledad_querier import SoledadQuerier from pixelated.adapter.search import SearchEngine from pixelated.adapter.draft_service import DraftService @@ -38,34 +38,16 @@ from pixelated.adapter.tag_service import TagService static_folder = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "web-ui", "app")) - # this is a workaround for packaging if not os.path.exists(static_folder): static_folder = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "..", "web-ui", "app")) if not os.path.exists(static_folder): static_folder = os.path.join('/', 'usr', 'share', 'pixelated-user-agent') -app = Flask(__name__, static_url_path='', static_folder=static_folder) -DISABLED_FEATURES = ['draftReply', 'signatureStatus', 'encryptionStatus', 'contacts'] - - -def respond_json(entity, status_code=200): - json_response = json.dumps(entity) - response = Response(response=json_response, mimetype="application/json") - response.status_code = status_code - return response - -@app.route('/features') -def features(): - try: - disabled_features = {'logout': os.environ['DISPATCHER_LOGOUT_URL']} - except KeyError: - disabled_features = {} - return respond_json({'disabled_features': DISABLED_FEATURES, 'dispatcher_features': disabled_features}) +app = Flask(__name__, static_url_path='', static_folder=static_folder) -def register_new_user(username): - server_name = app.config['LEAP_SERVER_NAME'] +def register_new_user(username, server_name): certs_home = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "certificates")) config = LeapConfig(certs_home=certs_home) provider = LeapProvider(server_name, config) @@ -75,7 +57,7 @@ def register_new_user(username): session.nicknym.generate_openpgp_key() -def _setup_routes(app, home_controller, mails_controller, tags_controller): +def _setup_routes(app, home_controller, mails_controller, tags_controller, features_controller): # home app.add_url_rule('/', methods=['GET'], view_func=home_controller.home) # mails @@ -91,32 +73,35 @@ def _setup_routes(app, home_controller, mails_controller, tags_controller): app.add_url_rule('/mails', methods=['PUT'], view_func=mails_controller.update_draft) # tags app.add_url_rule('/tags', methods=['GET'], view_func=tags_controller.tags) + # features + app.add_url_rule('/features', methods=['GET'], view_func=features_controller.features) + +def start_user_agent(debug_enabled, app): -def start_user_agent(debug_enabled): with app.app_context(): leap_session = LeapSession.open(app.config['LEAP_USERNAME'], app.config['LEAP_PASSWORD'], app.config['LEAP_SERVER_NAME']) + tag_service = TagService() soledad_querier = SoledadQuerier(soledad=leap_session.account._soledad) - - PixelatedMail.from_email_address = leap_session.account_email() pixelated_mailboxes = PixelatedMailBoxes(leap_session.account, soledad_querier) pixelated_mail_sender = PixelatedMailSender(leap_session.account_email()) - - tag_service = TagService() mail_service = MailService(pixelated_mailboxes, pixelated_mail_sender, tag_service, soledad_querier) search_engine = SearchEngine() - MailboxListener.SEARCH_ENGINE = search_engine search_engine.index_mails(mail_service.all_mails()) draft_service = DraftService(pixelated_mailboxes) + MailboxListener.SEARCH_ENGINE = search_engine + InputMail.FROM_EMAIL_ADDRESS = leap_session.account_email() + home_controller = HomeController() + features_controller = FeaturesController() mails_controller = MailsController(mail_service=mail_service, draft_service=draft_service, search_engine=search_engine) tags_controller = TagsController(search_engine=search_engine) - _setup_routes(app, home_controller, mails_controller, tags_controller) + _setup_routes(app, home_controller, mails_controller, tags_controller, features_controller) app.run(host=app.config['HOST'], debug=debug_enabled, port=app.config['PORT'], use_reloader=False) @@ -138,12 +123,14 @@ def setup(): reactor_manager.start_reactor(logging=debug_enabled) crochet.setup() + app.config.from_pyfile(args.config) if args.register: - register_new_user(args.register) + server_name = app.config['LEAP_SERVER_NAME'] + register_new_user(args.register, server_name) else: - start_user_agent(debug_enabled) + start_user_agent(debug_enabled, app) finally: reactor_manager.stop_reactor_on_exit() |