Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
from app.api.admin_sales.fees import AdminSalesFeesList
from app.api.admin_sales.invoices import AdminSalesInvoicesList
from app.api.full_text_search.events import EventSearchResultList
from app.api.import_jobs import ImportJobList

# users
api.route(UserList, 'user_list', '/users')
Expand Down Expand Up @@ -623,3 +624,6 @@

# Full text search w/ Elastic Search
api.route(EventSearchResultList, 'event_search_results', '/search/events')

# Import Jobs
api.route(ImportJobList, 'image_job_detail', '/import-jobs')
2 changes: 1 addition & 1 deletion app/api/helpers/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def get_filename_from_cd(cd):
def write_file(file, data):
"""simple write to file"""
fp = open(file, 'w')
fp.write(str(data, 'utf-8'))
fp.write(str(data))
fp.close()


Expand Down
Empty file added app/api/import_job.py
Empty file.
32 changes: 32 additions & 0 deletions app/api/import_jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from flask_rest_jsonapi import ResourceDetail, ResourceList

from flask_jwt import current_identity as current_user
from app.api.schema.import_jobs import ImportJobSchema
from app.models import db
from app.api.helpers.db import safe_query
from app.models.import_job import ImportJob
from app.models.user import User
from app.api.helpers.permissions import jwt_required
from app.api.helpers.permission_manager import has_access


class ImportJobList(ResourceList):
"""
List ImportJob
"""
def query(self, view_kwargs):
query_ = self.session.query(ImportJob)
user_id = current_user.id
user = safe_query(self, User, 'id', user_id, 'user_id')
if not has_access('is_user_itself', user_id=user.id):
raise ForbiddenException({'source': ''}, 'Access Forbidden')
query_ = query_.join(User, User.id == ImportJob.user_id).filter(User.id == user.id)
return query_

decorators = (jwt_required,)
schema = ImportJobSchema
data_layer = {'session': db.session,
'model': ImportJob,
'methods': {
'query': query
}}
29 changes: 29 additions & 0 deletions app/api/schema/import_jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from marshmallow.validate import Range
from marshmallow_jsonapi import fields
from marshmallow_jsonapi.flask import Relationship

from app.api.helpers.utilities import dasherize
from marshmallow_jsonapi.flask import Schema
from utils.common import use_defaults


@use_defaults()
class ImportJobSchema(Schema):
"""
Api schema for ImportJob Model
"""

class Meta:
"""
Meta class for ImportJob Api Schema
"""
type_ = 'import-job'
self_view = 'v1.image_job_detail'
self_view_kwargs = {'id': '<id>'}
inflect = dasherize

id = fields.Str(dump_only=True)
task = fields.Str(allow_none=False)
starts_at = fields.DateTime(required=True, timezone=True)
result = fields.Str(allow_none=True)
result_status = fields.Str(allow_none=True)
2 changes: 2 additions & 0 deletions app/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def __init__(self,
privacy=None,
event_topic_id=None,
event_sub_topic_id=None,
events_orga_id=None,
ticket_url=None,
copyright=None,
code_of_conduct=None,
Expand Down Expand Up @@ -247,6 +248,7 @@ def __init__(self,
self.event_topic_id = event_topic_id
self.copyright = copyright
self.event_sub_topic_id = event_sub_topic_id
self.events_orga_id = events_orga_id
self.ticket_url = ticket_url
self.code_of_conduct = code_of_conduct
self.schedule_published_on = schedule_published_on
Expand Down
61 changes: 61 additions & 0 deletions docs/api/api_blueprint.apib
Original file line number Diff line number Diff line change
Expand Up @@ -25338,6 +25338,7 @@ Get the details of the panel permission.
}
}


# Group Favourite Events

This Group's APIs can be used for adding a particular event to the favourite list of the user.
Expand Down Expand Up @@ -25517,3 +25518,63 @@ This Group's APIs can be used for adding a particular event to the favourite lis
"version": "1.0"
}
}


# Group Import Jobs

This Group's APIs are used for getting info of import jobs

## Import Jobs Collection [/v1/import-jobs{?page%5bsize%5d,page%5bnumber%5d,sort,filter}]

### List All Orders [GET]
Get a list of all import jobs

+ Request

+ Headers

Accept: application/vnd.api+json

Authorization: JWT <Auth Key>

+ Response 200 (application/vnd.api+json)

{
"data": [
{
"type": "import-job",
"attributes": {
"result-status": "SUCCESS",
"starts-at": "2019-01-08T17:24:01.971880+00:00",
"task": "fcc49d97-aff8-4f77-a98b-cfcdbae9f5eb",
"result": "5"
},
"id": "12",
"links": {
"self": "/v1/import-jobs?id=12"
}
},
{
"type": "import-job",
"attributes": {
"result-status": "FAIL",
"starts-at": "2019-01-08T17:10:57.133569+00:00",
"task": "99f150b8-705b-4452-bd6a-f53f68c21c4a",
"result": "5"
},
"id": "11",
"links": {
"self": "/v1/import-jobs?id=11"
}
}
],
"links": {
"self": "/v1/import-jobs"
},
"meta": {
"count": 2
},
"jsonapi": {
"version": "1.0"
}
}