Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
JuliePessoa committed Mar 18, 2019
2 parents 09f9f99 + 7640118 commit 375f441
Show file tree
Hide file tree
Showing 368 changed files with 27,351 additions and 2,067 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,14 @@ paket-files/
frontend/config.js
support/config.js
landing/config.js
feature-toggles/config.js
webchat/config.js

frontend/firebase-config.js
support/firebase-config.js
webchat/firebase-config.js
backend/firebase_config.py
feature-toggles/firebase-config.js

backend/app_version.py

Expand All @@ -549,6 +551,7 @@ backend/Pipfile
#Frontend tests
frontend/test/package-lock.json
frontend/test/yarn.lock
feature-toggles/test/yarn.lock

# Webchat tests
webchat/test/package-lock.json
Expand Down
13 changes: 11 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ pipeline {

}
stages {
stage('build') {
steps {
sh './setup_env_test clean'
sh './setup_frontend_tests'
}
}
stage('Tests') {
steps {
parallel(
"Backend": {
sh './ecis test server --clean'
sh './ecis test server'
},
"Frontend": {
sh './ecis test client --clean'
sh './ecis test client'
},
"Feature": {
sh './ecis test feature'
}
)
}
Expand Down
67 changes: 65 additions & 2 deletions backend/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
from models import Comment
from models import Invite
from models import Event
from models import Feature
from utils import NotAuthorizedException
from google.appengine.ext import ndb
from google.appengine.api import search

INDEX_INSTITUTION = 'institution'
INDEX_USER = 'user'
INDEX_EVENT = 'event'
TEXT = 'At vero eos et accusamus et iusto odio dignissimos \
ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti \
quos dolores et quas molestias excepturi sint occaecati cupiditate \
Expand All @@ -37,6 +39,22 @@
delectus, ut aut reiciendis voluptatibus maiores alias consequatur \
aut perferendis doloribus asperiores repellat.'

features = [
{
"name": 'manage-inst-edit',
"enable_mobile": "DISABLED",
"enable_desktop": "ALL",
"translation_dict": {
"pt-br": "Editar informações da instituição"
}
}
]

def create_features():
for feature in features:
if not Feature.get_by_id(feature['name']):
Feature.create(**feature)


def add_comments_to_post(user, user_reply, post, institution, comments_qnt=3):
"""Add comments to post."""
Expand Down Expand Up @@ -165,7 +183,8 @@ def clear_data_store():
delete_all_in_index(index_institution)
index_user = search.Index(name=INDEX_USER)
delete_all_in_index(index_user)

index_event = search.Index(name=INDEX_EVENT)
delete_all_in_index(index_event)

class BaseHandler(webapp2.RequestHandler):
"""Base Handler."""
Expand Down Expand Up @@ -313,7 +332,7 @@ def get(self):
'address': address_key,
'actuation_area': 'GOVERNMENT_AGENCIES',
'description': 'Ministério da Saúde',
'photo_url': 'https://i1.wp.com/notta.news/wp-content/uploads/2017/08/tbg_20170713080909_62787.jpg?w=1024',
'photo_url': 'https://firebasestorage.googleapis.com/v0/b/development-cis.appspot.com/o/images%2Fministerio_da_saude_logo-1551970633722?alt=media&token=a658e366-a3b6-4699-aa98-95dc79eff3b5',
'email': '[email protected]',
'phone_number': '61 3315-2425',
'state': 'active',
Expand Down Expand Up @@ -520,11 +539,55 @@ def get(self):
splab.posts = []
splab.put()

create_features()

jsonList.append({"msg": "database initialized with a few posts"})

self.response.write(json.dumps(jsonList))

class CreateFeaturesHandler(BaseHandler):
def get(self):
create_features()
self.response.write({"msg": "database initialized with a few features"})


class UpdateHandler(BaseHandler):
"""Temporary handler.
It handles with the entities update for some attributes.
"""

def get(self):
"""Retrieve all users and institutions to
create their new attributes avoiding an error in production.
"""
from datetime import datetime

users = User.query().fetch()

for user in users:
user.last_seen_institutions = datetime.now()
user.put()

existing_institutions = Institution.query().fetch()

for institution in existing_institutions:
institution.creation_date = datetime.now()
institution.put()

existing_events = Event.query().fetch()

for event in existing_events:
event.put()

self.response.write("worked")



app = webapp2.WSGIApplication([
('/admin/reset', ResetHandler),
('/admin/create-features', CreateFeaturesHandler),
('/admin/update', UpdateHandler)
], debug=True)


Expand Down
3 changes: 2 additions & 1 deletion backend/custom_exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from .notAuthorizedException import *
from .queryException import *
from .queueException import *
from .notAllowedException import *

exceptions = [entityException, fieldException, notAuthorizedException, queryException, queueException]
exceptions = [entityException, fieldException, notAuthorizedException, queryException, queueException, notAllowedException]

__all__ = [prop for exception in exceptions for prop in exception.__all__]
10 changes: 10 additions & 0 deletions backend/custom_exceptions/notAllowedException.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Not Allowed Exception."""

__all__ = ['NotAllowedException']

class NotAllowedException(Exception):
"""Not Allowed Exception."""

def __init__(self, msg=None):
"""Init method."""
super(NotAllowedException, self).__init__(msg or 'Operation not allowed.')
9 changes: 7 additions & 2 deletions backend/fcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ def send_push_notifications(data, tokens):
tokens: The devices' tokens that will receive
the notification.
"""
validate_object(data, ['title', 'body', 'click_action'])
validate_object(data, [
'title',
'body_message',
'click_action',
'type'
])

title = data['title']
body = data['body']
body = {'data': data['body_message'], 'type': data['type']}
click_action = data['click_action']

if tokens:
Expand Down
7 changes: 6 additions & 1 deletion backend/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
from .invite_user_handler import *
from .institution_parent_handler import *
from .institution_children_handler import *
from .event_followers_handler import *
from .feature_toggle_handler import *
from .current_state_email_request_handler import *

handlers = [
base_handler, erro_handler, event_collection_handler, event_handler,
Expand All @@ -61,6 +64,8 @@
user_request_collection_handler, user_timeline_handler, vote_handler,
invite_hierarchy_collection_handler, invite_user_collection_handler,
invite_institution_handler, invite_user_handler, institution_parent_handler,
institution_children_handler]
institution_children_handler, event_followers_handler, feature_toggle_handler,
current_state_email_request_handler
]

__all__ = [prop for handler in handlers for prop in handler.__all__]
29 changes: 29 additions & 0 deletions backend/handlers/current_state_email_request_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
"""Current state link request email handler."""

import json

from util import login_required
from utils import json_response
from . import BaseHandler
from send_email_hierarchy import RequestStateEmailSender

__all__ = ['CurrentStateEmailRequestHandler']


class CurrentStateEmailRequestHandler(BaseHandler):
"""Current state email request handler."""

@login_required
@json_response
def post(self, user):
body = json.loads(self.request.body)

subject = "Link para preenchimento de formulario"

email_sender = RequestStateEmailSender(**{
'receiver': user.email,
'subject': subject,
'body': body
})
email_sender.send_email()
4 changes: 2 additions & 2 deletions backend/handlers/event_collection_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def get_filtered_events(filters, user):
december = month == 12
begin_selected_month_utc = datetime(year, month, 1, 3)
end_selected_month_utc = datetime(year if not december else year+1, month+1 if not december else 1, 1, 3)
query = ndb.gql("SELECT __key__ FROM Event WHERE institution_key IN :1 AND state =:2 AND start_time < DATETIME(:3)",
user.follows, 'published', end_selected_month_utc.strftime("%Y-%m-%d %H:%M:%S"))
query = ndb.gql("SELECT __key__ FROM Event WHERE institution_key IN :1 AND start_time < DATETIME(:2)",
user.follows, end_selected_month_utc.strftime("%Y-%m-%d %H:%M:%S"))
if query.count() > 0:
return ndb.gql("SELECT * FROM Event WHERE __key__ IN :1 AND end_time >= DATETIME(:2)",
query.fetch(), begin_selected_month_utc.strftime("%Y-%m-%d %H:%M:%S")).order(Event.end_time, Event.key)
Expand Down
40 changes: 40 additions & 0 deletions backend/handlers/event_followers_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
"""Event Followers Handler."""
import json
from google.appengine.ext import ndb

from models import Event
from utils import Utils
from util import login_required
from utils import NotAuthorizedException
from utils import json_response
from . import BaseHandler

__all__ = ['EventFollowersHandler']

class EventFollowersHandler(BaseHandler):
"""Event Followers Handler."""

@json_response
@login_required
def post(self, user, event_urlsafe):
"""."""
event = ndb.Key(urlsafe=event_urlsafe).get()

Utils._assert(event.state != 'published',
'The event is not published',
NotAuthorizedException)

event.add_follower(user)

@json_response
@login_required
def delete(self, user, event_urlsafe):
"""."""
event = ndb.Key(urlsafe=event_urlsafe).get()

Utils._assert(event.state != 'published',
'The event is not published',
NotAuthorizedException)

event.remove_follower(user)
39 changes: 39 additions & 0 deletions backend/handlers/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from utils import json_response
from util import JsonPatch
from . import BaseHandler
from service_entities import enqueue_task

__all__ = ['EventHandler']

Expand Down Expand Up @@ -56,6 +57,25 @@ def delete(self, user, event_urlsafe):
event.last_modified_by_name = user.name
event.put()

params = {
'receiver_key': event.author_key.urlsafe(),
'sender_key': user.key.urlsafe(),
'entity_key': event.key.urlsafe(),
'entity_type': 'DELETED_EVENT',
'current_institution': user.current_institution.urlsafe(),
'sender_institution_key': event.institution_key.urlsafe(),
'field': 'followers',
'title': event.title
}

enqueue_task('multiple-notification', params)

enqueue_task('send-push-notification', {
'type': 'DELETED_EVENT',
'receivers': [follower.urlsafe() for follower in event.followers],
'entity': event.key.urlsafe()
})

@json_response
@login_required
def patch(self, user, event_urlsafe):
Expand Down Expand Up @@ -85,3 +105,22 @@ def patch(self, user, event_urlsafe):

"""Update event."""
event.put()

params = {
'receiver_key': event.author_key.urlsafe(),
'sender_key': user.key.urlsafe(),
'entity_key': event.key.urlsafe(),
'entity_type': 'UPDATED_EVENT',
'current_institution': user.current_institution.urlsafe(),
'sender_institution_key': event.institution_key.urlsafe(),
'field': 'followers',
'title': event.title
}

enqueue_task('multiple-notification', params)

enqueue_task('send-push-notification', {
'type': 'UPDATED_EVENT',
'receivers': [follower.urlsafe() for follower in event.followers],
'entity': event.key.urlsafe()
})
Loading

0 comments on commit 375f441

Please sign in to comment.