From 60b9867d6a6b01283af2c4599feb28a800fa53eb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Barbora=20Kompi=C5=A1ov=C3=A1?=
 <barbora.kompisova@gmail.com>
Date: Fri, 30 Mar 2018 09:46:53 +0200
Subject: [PATCH] fixed imports

---
 Pipfile                                | 61 +++++++++++++-------------
 portal/__init__.py                     |  4 ++
 portal/database/models.py              |  2 +-
 portal/rest/__init__.py                |  3 +-
 portal/rest/auth/login.py              |  3 +-
 portal/rest/courses/courses.py         |  2 +-
 portal/rest/groups/groups.py           |  2 +-
 portal/rest/projects/projects.py       |  2 +-
 portal/rest/roles/roles.py             |  2 +-
 portal/rest/submissions/submissions.py |  2 +-
 portal/rest/users/users.py             |  4 +-
 portal/service/service.py              |  6 +--
 sample_data/data_init.py               |  2 +-
 13 files changed, 48 insertions(+), 47 deletions(-)

diff --git a/Pipfile b/Pipfile
index 631949c..c25f5ab 100644
--- a/Pipfile
+++ b/Pipfile
@@ -1,30 +1,31 @@
-[[source]]
-
-url = "https://pypi.python.org/simple"
-verify_ssl = true
-name = "pypi"
-
-
-[packages]
-
-flask = "*"
-flask-sqlalchemy = "*"
-pytest = "*"
-flask-restful = "*"
-marshmallow = "*"
-flask-jwt-extended = "*"
-marshmallow-enum = "*"
-storage = { git="git@gitlab.fi.muni.cz:grp-kontr2/kontr-storage-module.git", editable='true'  }
-gitpython = "*"
-flask-oauthlib = "*"
-pyopenssl = "*"
-gunicorn = "*"
-
-
-[dev-packages]
-
-
-
-[requires]
-
-python_version = "3.6"
+[[source]]
+
+url = "https://pypi.python.org/simple"
+verify_ssl = true
+name = "pypi"
+
+
+[packages]
+
+flask = "*"
+flask-sqlalchemy = "*"
+pytest = "*"
+flask-restful = "*"
+marshmallow = "*"
+flask-jwt-extended = "*"
+marshmallow-enum = "*"
+storage = { git="git@gitlab.fi.muni.cz:grp-kontr2/kontr-storage-module.git", editable='true'  }
+gitpython = "*"
+flask-oauthlib = "*"
+pyopenssl = "*"
+gunicorn = "*"
+flask-cors = "*"
+
+
+[dev-packages]
+
+
+
+[requires]
+
+python_version = "3.6"
diff --git a/portal/__init__.py b/portal/__init__.py
index 7a09c08..26084fb 100644
--- a/portal/__init__.py
+++ b/portal/__init__.py
@@ -1,4 +1,5 @@
 from flask import Flask
+from flask_cors import CORS
 from flask_jwt_extended import JWTManager
 from flask_oauthlib.client import OAuth
 
@@ -12,6 +13,7 @@ from storage import Storage
 db = SQLAlchemy()
 jwt = JWTManager()
 oauth = OAuth()
+cors = CORS(resources={f"*": {"origins": "*"}})
 # TODO - urgent
 storage = Storage({
     "submissions_dir": "todo",
@@ -42,6 +44,8 @@ def create_app():
     jwt.init_app(app)
     # init the oauth client
     oauth.init_app(app)
+    # init CORS
+    cors.init_app(app)
     return app
 
 
diff --git a/portal/database/models.py b/portal/database/models.py
index 9aefd32..e574436 100644
--- a/portal/database/models.py
+++ b/portal/database/models.py
@@ -8,7 +8,7 @@ from sqlalchemy.ext.hybrid import hybrid_property
 from sqlalchemy.orm import aliased
 from werkzeug.security import generate_password_hash, check_password_hash
 
-from database import SubmissionState
+from portal.database import SubmissionState
 from portal import db
 from portal.database.mixins import EntityBase
 from portal.database.exceptions import PortalDbError
diff --git a/portal/rest/__init__.py b/portal/rest/__init__.py
index c3128da..8785bd2 100644
--- a/portal/rest/__init__.py
+++ b/portal/rest/__init__.py
@@ -1,8 +1,7 @@
 from marshmallow import Schema, fields, validates_schema, ValidationError
 from marshmallow_enum import EnumField
 
-from portal.database.models import ProjectState
-from database import SubmissionState
+from portal.database.models import ProjectState, SubmissionState
 
 
 class UserSchema(Schema):
diff --git a/portal/rest/auth/login.py b/portal/rest/auth/login.py
index 31630b3..f0d22e3 100644
--- a/portal/rest/auth/login.py
+++ b/portal/rest/auth/login.py
@@ -6,7 +6,7 @@ from flask import Blueprint, request, jsonify
 from portal import jwt
 from portal.service.auth import login_user, login_component
 from portal.service.errors import UnauthorizedError, PortalAPIError
-from service import service
+from portal.service import service
 
 auth = Blueprint('auth', __name__, url_prefix='/auth')
 auth_api = Api(auth)
@@ -50,6 +50,7 @@ class Login(Resource):
             raise PortalAPIError(400, message="Invalid login type.")
 
         response = {
+            'id': client.id,
             'access_token': create_access_token(identity=client.id),
             'refresh_token': create_refresh_token(identity=client.id)
         }
diff --git a/portal/rest/courses/courses.py b/portal/rest/courses/courses.py
index 5a04d1d..e6e864f 100644
--- a/portal/rest/courses/courses.py
+++ b/portal/rest/courses/courses.py
@@ -8,7 +8,7 @@ from portal.service import service
 from portal.service.errors import PortalAPIError, ForbiddenError
 from portal.tools.decorators import error_handler
 from portal.tools.logging import log
-from service import policies
+from portal.service import policies
 
 courses = Blueprint('courses', __name__)
 courses_api = Api(courses)
diff --git a/portal/rest/groups/groups.py b/portal/rest/groups/groups.py
index 5b8a135..f53c9ea 100644
--- a/portal/rest/groups/groups.py
+++ b/portal/rest/groups/groups.py
@@ -8,7 +8,7 @@ from portal.tools.logging import log
 from portal.database.models import Group
 from portal.rest import group_schema, groups_schema, users_schema, user_list_update_schema, group_import_schema
 from portal.service.errors import PortalAPIError, ForbiddenError
-from service import policies
+from portal.service import policies
 
 groups = Blueprint('groups', __name__)
 groups_api = Api(groups)
diff --git a/portal/rest/projects/projects.py b/portal/rest/projects/projects.py
index dd8a415..b0a95b7 100644
--- a/portal/rest/projects/projects.py
+++ b/portal/rest/projects/projects.py
@@ -11,7 +11,7 @@ from portal.tools.logging import log
 from portal.database.models import Project, Submission, Course
 from portal.service import service
 from portal.service.errors import PortalAPIError, ForbiddenError
-from service import policies
+from portal.service import policies
 
 projects = Blueprint('projects', __name__)
 projects_api = Api(projects)
diff --git a/portal/rest/roles/roles.py b/portal/rest/roles/roles.py
index 27f3a31..9d322bd 100644
--- a/portal/rest/roles/roles.py
+++ b/portal/rest/roles/roles.py
@@ -8,7 +8,7 @@ from portal.service import service
 from portal.service.errors import PortalAPIError, ForbiddenError
 from portal.tools.decorators import error_handler
 from portal.tools.logging import log
-from service import policies
+from portal.service import policies
 
 roles = Blueprint('roles', __name__)
 roles_api = Api(roles)
diff --git a/portal/rest/submissions/submissions.py b/portal/rest/submissions/submissions.py
index 89227e1..227e558 100644
--- a/portal/rest/submissions/submissions.py
+++ b/portal/rest/submissions/submissions.py
@@ -7,7 +7,7 @@ from portal.tools.decorators import error_handler
 from portal.tools.logging import log
 from portal.service import service
 from portal.service.errors import PortalAPIError, ForbiddenError
-from service import policies
+from portal.service import policies
 
 submissions = Blueprint('submissions', __name__)
 submissions_api = Api(submissions)
diff --git a/portal/rest/users/users.py b/portal/rest/users/users.py
index 1de896e..75ccf92 100644
--- a/portal/rest/users/users.py
+++ b/portal/rest/users/users.py
@@ -1,10 +1,10 @@
 from flask import Blueprint, request
-from flask_jwt_extended import jwt_required, get_jwt_identity
+from flask_jwt_extended import jwt_required
 from flask_restful import Api, Resource
 
 from portal.rest import user_schema, users_schema, submissions_schema, roles_schema, courses_schema, groups_schema, \
     reviews_schema, user_schema_reduced
-from portal.service.errors import PortalAPIError, ValidationError, ForbiddenError, IncorrectPasswordError
+from portal.service.errors import PortalAPIError, ForbiddenError, IncorrectPasswordError
 from portal.service import service, policies
 from portal.database.models import User
 from portal.tools.logging import log
diff --git a/portal/service/service.py b/portal/service/service.py
index c8a2d7b..fece24c 100644
--- a/portal/service/service.py
+++ b/portal/service/service.py
@@ -4,12 +4,8 @@ from portal.service.errors import ResourceNotFoundError, UnauthorizedError
 from portal.tools.logging import log
 from portal import db
 from portal.database.models import Course, Role, User, Project, Group, Submission, Review, ReviewItem, \
-    ProjectState, Component
-from database import SubmissionState
+    Component, SubmissionState
 from portal import storage
-import copy
-
-from tools.time import NOW
 
 
 def delete_entity(entity):
diff --git a/sample_data/data_init.py b/sample_data/data_init.py
index 7ddc753..c90b755 100644
--- a/sample_data/data_init.py
+++ b/sample_data/data_init.py
@@ -1,5 +1,5 @@
 from portal.database.models import User, Course, Project, Group, Role, Submission, Review, ReviewItem
-from database import SubmissionState
+from portal.database import SubmissionState
 
 
 def init_data(app, db):
-- 
GitLab