Skip to content

Commit

Permalink
Merge pull request #18 from unlimitedlabs/optionalize_google
Browse files Browse the repository at this point in the history
Make Google Apps integration optional
  • Loading branch information
jrbotros committed Sep 23, 2015
2 parents 91dfb4d + e492a6b commit 6a65d0d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
8 changes: 7 additions & 1 deletion example_project/example_project/orchestra_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ def setup_orchestra(settings_module_name):
settings.AWS_S3_KEY = '' # FILL IN
settings.AWS_S3_SECRET = '' # FILL IN

# REQUIRED: Google API related service email and path to a secret key.
# Feature flag for toggling optional Google Apps integration. If a
# service email and secret key are provided, Google Apps is used to
# structure project data in Drive folders and can be used for
# customizing workflow steps as well.
settings.GOOGLE_APPS = False

# Optional Google API related service email and path to a secret key.
settings.GOOGLE_SERVICE_EMAIL = ''
settings.GOOGLE_P12_PATH = ''

Expand Down
6 changes: 6 additions & 0 deletions orchestra/google_apps/convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from orchestra.google_apps.permissions import write_with_link_permission
from orchestra.google_apps.service import Service
from orchestra.utils.common_regex import image_file_regex
from orchestra.utils.settings import run_if


logger = logging.getLogger(__name__)
Expand All @@ -35,6 +36,7 @@ def _get_image_mimetype(response, title):
return 'image/{}'.format(extension)


@run_if('GOOGLE_APPS')
def add_image(service, folder_id, url):
"""
Add image to a folder.
Expand Down Expand Up @@ -73,6 +75,7 @@ def add_image(service, folder_id, url):
return google_image


@run_if('GOOGLE_APPS')
def create_media_folder_with_images(parent_id, image_links, folder_name):
"""
Given a folder name and a list of image links create a new
Expand All @@ -98,6 +101,7 @@ def create_media_folder_with_images(parent_id, image_links, folder_name):
'image_counter': counter}


@run_if('GOOGLE_APPS')
def create_folder_with_permissions(parent_id, folder_name, permissions=None):
"""
Create drive folder in the specified location with given permissions.
Expand All @@ -116,6 +120,7 @@ def create_folder_with_permissions(parent_id, folder_name, permissions=None):
return folder


@run_if('GOOGLE_APPS')
def create_project_google_folder(project):
"""
Create drive folder for project information
Expand All @@ -133,6 +138,7 @@ def create_project_google_folder(project):
return folder


@run_if('GOOGLE_APPS')
def create_document_from_template(template_id, name,
parent_ids=None, permissions=None):
service = Service(settings.GOOGLE_P12_PATH,
Expand Down
7 changes: 4 additions & 3 deletions orchestra/project_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,20 @@ def create_project(request):
task_class = WorkerCertification.TaskClass.REAL
else:
task_class = WorkerCertification.TaskClass.TRAINING

project = create_project_with_tasks(
args = (
project_details['workflow_slug'],
project_details['description'],
project_details['priority'],
task_class,
project_details['project_data'],
project_details['review_document_url']
)
return {'project_id': project.id}
except KeyError:
raise BadRequest('One of the parameters is missing')

project = create_project_with_tasks(*args)
return {'project_id': project.id}


@api_endpoint(['POST'])
def project_details_url(request):
Expand Down
2 changes: 2 additions & 0 deletions orchestra/tests/google_apps/test_convenience.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest.mock import patch
from unittest.mock import MagicMock

from django.test import override_settings
from django.test import TestCase
from django.conf import settings

Expand All @@ -16,6 +17,7 @@
from orchestra.tests.helpers.google_apps import fake_image_get


@override_settings(GOOGLE_APPS=True)
class TestGoogleAppsConvenience(TestCase):

def setUp(self):
Expand Down
1 change: 1 addition & 0 deletions orchestra/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def setUp(self): # noqa
super(BasicTaskLifeCycleTestCase, self).setUp()
setup_models(self)

@override_settings(GOOGLE_APPS=True)
@patch.object(Service, '_create_drive_service',
new=mock_create_drive_service)
def test_create_project_google_folder(self):
Expand Down

0 comments on commit 6a65d0d

Please sign in to comment.