Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
b8e8b3f
Add /api/m/projects using new api_query.py and api_marshal.py
will-moore Jun 14, 2016
180fddb
Add /version/ to url, ignored for now
will-moore Jun 14, 2016
fff45a1
Add pip install omero-marshal to .travis.yml
will-moore Jun 14, 2016
cdabd97
Fix copyright date
will-moore Jun 14, 2016
061dd6a
Remove -r from pip install omero-marshall
will-moore Jun 14, 2016
f68ddef
Add support for ?owner=1&group=2 to /projects/
will-moore Jun 14, 2016
8e8bd88
childCount false be default
will-moore Jun 14, 2016
e0ce1d8
Add omero-marshal to common requirements-common.txt file
will-moore Jun 15, 2016
c39eadc
Remove omero-marshal from .travis.yml
will-moore Jun 15, 2016
54a3916
Use request.GET instead of request.REQUEST
will-moore Jun 15, 2016
0983701
Restrict api urls to supported versions
will-moore Jun 22, 2016
2cca1d9
Added api_base and api_versions with urls to browse
will-moore Jun 22, 2016
73be9c5
Add /token /servers and /login urls
will-moore Jun 23, 2016
5ddfae1
url renaming - /api/ is 'api_versions'
will-moore Jun 23, 2016
61b2193
Use class-based LoginView in webgateway & webclient
will-moore Jun 23, 2016
37c8a31
Fix use of webclient login from webadmin/urls.py
will-moore Jun 23, 2016
6c75189
Improve CSRF handling with JsonResponseForbidden
will-moore Jun 24, 2016
0b683ff
webgateway @login_required() returns json on_not_logged_in()
will-moore Jun 24, 2016
1103e75
ApiProjects class-based view to handle post()
will-moore Jun 24, 2016
35f3fab
@jsonp decorator Content-Type should reflect json vv javascript
will-moore Jun 29, 2016
66bb052
Added first test to integration/test_api_login.py
will-moore Jun 29, 2016
469a7f5
Added more helper methods to integration/weblibrary.py
will-moore Jun 29, 2016
4ef71e1
Added test_base_url and test_login_csrf to test_api_login.py
will-moore Jun 29, 2016
5fd6261
flake8 fixes to webgateway/views.py
will-moore Jun 29, 2016
74a8a68
useragent 'OMERO.webapi' in LoginView and @login_required
will-moore Jul 4, 2016
ed539ff
New OmeroWeb integration test: test_api_projects.py
will-moore Jul 5, 2016
e32820a
Rename class ApiProjects to ProjectsView
will-moore Jul 5, 2016
81ea17f
Adding lots more tests to test_api_projects.py
will-moore Jul 5, 2016
04db357
Always return Json response to CSRF error
will-moore Jul 7, 2016
4b4e49a
New python examples script at Json_Api/Login.py
will-moore Jul 25, 2016
3973b80
Simplify Json_Api/Login.py, add 'Referer' to POSTs
will-moore Jul 25, 2016
cbef1c3
Added ProjectView with get(), put() & delete() for single Project
will-moore Jul 25, 2016
6e5de82
Added Project get, update & delete to examples Login.py
will-moore Jul 25, 2016
728c1f1
Include 'Referer' in header of PUT and DELETE requests in Login.py
will-moore Jul 25, 2016
1f645ef
flake8 fix
will-moore Jul 25, 2016
5763299
flake8 fixes
will-moore Jul 25, 2016
6db5f13
Add pagination test of limit & page params to test_api_projects.py
will-moore Jul 25, 2016
7e61557
Add test of 'normalise' and 'childCount' to test_api_projects.py
will-moore Jul 25, 2016
440ce90
Don't use JsonResponse from django.http. Not in Django 1.6
will-moore Jul 26, 2016
c8ae6e1
Add testing of 'callback' param to test_api_projects.py
will-moore Jul 26, 2016
b2bb2c1
Add test_login_get() to test_api_login.py
will-moore Jul 26, 2016
2a13de3
Use conn.getObject('Project', pid) in ProjectView.get()
will-moore Jul 26, 2016
0080a36
Test /projects/ POST and /project/:id/ GET
will-moore Jul 26, 2016
fe6d154
Project put() can use simple dict {'name':'foo'}
will-moore Jul 27, 2016
66da4e4
New test for project put() in test_api_projects.py
will-moore Jul 27, 2016
eadc288
Set headers in request.session in Login.py example
will-moore Jul 27, 2016
3d614a7
Added delete test to test_api_projects.py
will-moore Jul 27, 2016
e1373b3
Test project 404 for get, put & delete
will-moore Jul 27, 2016
bc64d6f
Test versions 404 in test_api_login.py
will-moore Jul 27, 2016
eec8198
flake8 fix
will-moore Jul 27, 2016
923678f
Merge remote-tracking branch 'origin/develop' into webgateway_api2
will-moore Aug 10, 2016
4bcfae9
Fix failing test_api_projects.py tests
will-moore Aug 11, 2016
f8998a2
LoginView handles form validation errors
will-moore Aug 19, 2016
03aaec2
Added guest and 'no password' tests to test_api_login.py
will-moore Aug 19, 2016
f89e186
Add login tests for no username, server or invalid
will-moore Aug 19, 2016
54d15a9
Refactor 4 login tests into single test with parametrize()
will-moore Aug 19, 2016
a4d9442
flake8 fix
will-moore Aug 24, 2016
28bf952
New test to show ValidationException on marshal and saveObject()
will-moore Aug 30, 2016
4647155
Project PUT needs @type to be in json
will-moore Aug 31, 2016
264e714
Updated test_project_update() to test @type needed
will-moore Aug 31, 2016
20b0056
test that PUT after delete creates new object
will-moore Aug 31, 2016
f62c912
New test_marshal_projects_not_logged_in
will-moore Aug 31, 2016
34f67dd
@jsonp returns Errors as json instead of text/javascript
will-moore Aug 31, 2016
9ac5114
test_validation_exception
will-moore Aug 31, 2016
79a772d
Use p.unloadDetails() instead of del json['omero:details']
will-moore Aug 31, 2016
d37f9fb
Use ProjectsView.post() instead of ProjectView.put() for saving
will-moore Sep 1, 2016
333f47e
Add 'schema_url': OME_SCHEMA_URL to api_base json
will-moore Sep 1, 2016
e6edd21
Update test for OME_SCHEMA_URL
will-moore Sep 1, 2016
15503a0
Update tests to use /projects/ POST for saving
will-moore Sep 1, 2016
eb8eaa7
Update requirements.txt to use sbesson/omero_marshal/ 5.3.0
will-moore Sep 1, 2016
33ab1d6
Move /projects/ POST to /save/ for use by all objects
will-moore Sep 1, 2016
8fc674b
Enforce /save/ PUT has @id and POST doesn't
will-moore Sep 1, 2016
3844e85
Use obj.unloadDetails() in SaveView
will-moore Sep 1, 2016
6081465
Started new project group test
will-moore Sep 1, 2016
d7a3f46
Remove /webgateway/ from /webgateway/api/ urls
will-moore Sep 1, 2016
d9eceb2
Add get placeholder to /save/ url
will-moore Sep 2, 2016
118e5d9
PUT to /save/ with @id checks objects exists
will-moore Sep 2, 2016
4690436
POST to /save/ uses obj.getDetails().group.id.val to set group
will-moore Sep 2, 2016
4594f11
Update test_project_create_other_group to work with prev fix
will-moore Sep 2, 2016
3b2d89e
Make sure we're checking status codes in weblibrary
will-moore Sep 2, 2016
255b3a4
Revert to using omero_marshal master branch
will-moore Sep 5, 2016
6fe589c
Use keys 'data' and 'experimenterGroups' for json
will-moore Sep 5, 2016
84d8e49
Update tests to use 'data' and 'experimenterGroups' keys
will-moore Sep 5, 2016
3677d7b
New test_login_example tests users' workflow
will-moore Sep 5, 2016
aca312b
Use 'data' to hold json response data instead of 'servers' or 'versions'
will-moore Sep 5, 2016
c6235cf
Update examples/Training/python/Json_Api/Login.py
will-moore Sep 5, 2016
bcd77c2
Update to API_VERSIONS = ['0.1']
will-moore Sep 5, 2016
23f5d01
Merge remote-tracking branch 'origin/develop' into webgateway_api2
will-moore Sep 6, 2016
cbd88f6
Remove 404 check from PUT /save/
will-moore Sep 6, 2016
ff36688
Silence broken test of 404 for PUT deleted object
will-moore Sep 6, 2016
c7f54f9
Use JsonResponse to replace similar omeroweb.http Responses
will-moore Sep 6, 2016
6b99dd2
Handle errors appropriately, not always 500 error
will-moore Sep 7, 2016
a52d5cd
Try to test various error codes
will-moore Sep 7, 2016
dd34d62
Use status=400 as default for error in @jsonp
will-moore Sep 7, 2016
f89cdf3
Fix test_validation_exception with duplicate tags
will-moore Sep 7, 2016
66494ca
Moved 5 error tests to new test_api_errors.py
will-moore Sep 7, 2016
c5e4101
Rename _csrf_put_response_json() -> _csrf_put_json()
will-moore Sep 7, 2016
698a72e
Must specify group for PUT or POST to /save
will-moore Sep 8, 2016
751c9b9
Update tests with save/?group=:id
will-moore Sep 8, 2016
68dc41f
Fix failing tests by return dict to @jsonp JsonResponse
will-moore Sep 8, 2016
7782910
@jsonp still needs to support non-dict data JsonResponse()
will-moore Sep 8, 2016
b9764df
Fix breaking tests
will-moore Sep 8, 2016
78524c1
POST creation returns status 201 response
will-moore Sep 8, 2016
4eeab66
Update tests to expect 201 on POST creation
will-moore Sep 8, 2016
181cf90
flake8 fixes
will-moore Sep 13, 2016
04d1e86
Error status=500 with custom try/except for omero_marshal decode()
will-moore Sep 13, 2016
9e8623a
Update test_api_errors.py with new status codes & messages
will-moore Sep 13, 2016
0844df4
Merge remote-tracking branch 'origin/develop' into webgateway_api2
will-moore Sep 13, 2016
da02cfe
Revert "Fix failing tests by return dict to @jsonp JsonResponse"
will-moore Sep 13, 2016
3c83cb2
PEP8 and doc fixes
will-moore Sep 16, 2016
d0752a3
Merge remote-tracking branch 'origin/develop' into webgateway_api2
will-moore Sep 16, 2016
995500a
More PEP8 renaming
will-moore Sep 16, 2016
9843b25
Use @pytest paramatize to cover more login options
will-moore Sep 16, 2016
e09e67c
Adding more webclient login tests
will-moore Sep 19, 2016
04586dd
Doc string for WebclientLoginView.get()
will-moore Sep 19, 2016
1bf4942
Remove **kwargs and @jsonp from LoginView methods
will-moore Sep 19, 2016
3320388
def handle_not_logged_in() error and form args optional
will-moore Sep 19, 2016
b0132ee
Add comments to clarify 'server_id' access in @jsonp
will-moore Sep 19, 2016
a4d678c
Remove omero.ServerError, catch ApiUsageException in @jsonp
will-moore Sep 19, 2016
3d10944
Doc strings for webgateway LoginView
will-moore Sep 19, 2016
1cd20c2
Remove unused check if user is Inactive after login
will-moore Sep 19, 2016
0c38a1e
Remove 'not not' => boolean and add doc strings
will-moore Sep 19, 2016
f8f833e
Removing duplicate requirements-common.txt line
will-moore Sep 20, 2016
d471cf5
flake8 fix
will-moore Sep 20, 2016
51d1c8e
Use new @json_response decorator for /api/ methods
will-moore Sep 20, 2016
7bcd568
Revert server_id handling change to @jsonp
will-moore Sep 20, 2016
9359db0
Fixing tests from previous commits
will-moore Sep 20, 2016
a607715
flake8 fix
will-moore Sep 20, 2016
d460a93
Docs and marshal_projects() renamed _objects()
will-moore Sep 20, 2016
fcfe009
marshal_objects extras is dict instead of list
will-moore Sep 20, 2016
e260602
Use string formatting with versions for url regexes
will-moore Sep 20, 2016
b5b892e
PEP8 variable name fixes in integration tests
will-moore Sep 21, 2016
997036c
flake8 fix
will-moore Sep 21, 2016
453a366
Use tuple for API_VERSIONS
will-moore Sep 22, 2016
e6a942f
Use status=405 for Login and Save GET placeholders
will-moore Sep 22, 2016
8f1e92e
Allow non-dict json data in @render_response decorator
will-moore Sep 22, 2016
7394c74
Add TODO for settings.API_VERSIONS
will-moore Sep 22, 2016
a9a8961
Tiny test fix from PEP8 changes
will-moore Sep 22, 2016
c91c71e
Fix test_login_get to expect status 405
will-moore Sep 23, 2016
446754f
Make build_url() configurable with 'omero.web.api.absolute_url'
will-moore Sep 23, 2016
270ef79
Raise custom BadRequestError instead of returning JsonResponse(400)
will-moore Sep 23, 2016
f996556
flake8 fixes
will-moore Sep 23, 2016
6912420
Missing api_exceptions.py
will-moore Sep 23, 2016
c42be11
Merge remote-tracking branch 'origin/develop' into webgateway_api2
will-moore Sep 27, 2016
9db49b1
Merge remote-tracking branch 'origin/develop' into webgateway_api2
will-moore Oct 5, 2016
586f1c0
views api methods never return HttpResponse
will-moore Oct 13, 2016
3008e34
move web host to properties
atarkowska Oct 13, 2016
5e7f9f5
Update examples Login.py to use ?group=<gid> on save
will-moore Oct 13, 2016
3512cfc
Comment out 'csrfmiddlewaretoken' in Login.py example login
will-moore Oct 13, 2016
f9c1c1b
Update CSRF warning
will-moore Oct 13, 2016
37f3b24
Moving json_response() to class-based decorator
will-moore Oct 25, 2016
9c51b0e
json_response class handles success or error with separate methods
will-moore Oct 25, 2016
f31fb65
Add docs for query_projects()
will-moore Oct 25, 2016
bd6c4d3
Remove __getarrt__ workaround on @json_response decorator
will-moore Oct 26, 2016
2330774
flake8 fix
will-moore Oct 26, 2016
3d0e563
Update test_project_update with PR #4829 fix
will-moore Oct 26, 2016
d4de580
Merge remote-tracking branch 'origin/develop' into webgateway_api2
will-moore Oct 28, 2016
e484d2e
Update to omero-marshal 0.4.1 in requirements-common.txt
will-moore Oct 31, 2016
e4a6c6a
Using 'omero-marshal==0.4.1' in requirements.txt
will-moore Oct 31, 2016
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
8 changes: 5 additions & 3 deletions components/tools/OmeroWeb/omeroweb/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

import logging
import traceback
from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.http import Http404, HttpResponse, HttpResponseRedirect, \
JsonResponse
from django.http import HttpResponseForbidden, StreamingHttpResponse

from django.conf import settings
Expand All @@ -36,7 +37,6 @@
from django.template import RequestContext
from django.core.cache import cache

from omeroweb.http import HttpJsonResponse
from omeroweb.utils import reverse_with_params
from omeroweb.connector import Connector
from omero.gateway.utils import propertiesToDict
Expand Down Expand Up @@ -558,7 +558,9 @@ def wrapper(request, *args, **kwargs):
# allows us to return the dict as json (NB: BlitzGateway objects
# don't serialize)
if template is None or template == 'json':
return HttpJsonResponse(context)
# We still need to support non-dict data:
safe = type(context) is dict
return JsonResponse(context, safe=safe)
else:
# allow additional processing of context dict
ctx.prepare_context(request, context, *args, **kwargs)
Expand Down

This file was deleted.

17 changes: 10 additions & 7 deletions components/tools/OmeroWeb/omeroweb/feedback/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@

from django.conf import settings
from django.template import loader as template_loader
from django.http import HttpResponse, HttpResponseRedirect
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
from django.http import HttpResponseServerError, HttpResponseNotFound
from django.http import HttpResponseForbidden
from django.template import RequestContext
from django.views.defaults import page_not_found
from django.core.urlresolvers import reverse
Expand Down Expand Up @@ -131,12 +130,16 @@ def send_comment(request):
##############################################################################
# handlers


def csrf_failure(request, reason=""):
logger.warn('csrf_failure: Forbidden')
t = template_loader.get_template("403_csrf.html")
c = RequestContext(request, {})
return HttpResponseForbidden(t.render(c))
"""
Always return Json response
since this is accepted by browser and API users
"""
error = ("CSRF Error. You need to include valid CSRF tokens for any"
" POST, PUT, PATCH or DELETE operations."
" You have to include CSRF token in the POST data or"
" add the token to the HTTP header.")
return JsonResponse({"message": error}, status=403)


def handler500(request):
Expand Down
13 changes: 3 additions & 10 deletions components/tools/OmeroWeb/omeroweb/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
#
#
# Copyright (C) 2011-2014 University of Dundee & Open Microscopy Environment.
# Copyright (C) 2011-2016 University of Dundee & Open Microscopy Environment.
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -19,14 +19,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

import json

from django.http import HttpResponse, HttpResponseServerError


class HttpJavascriptResponse(HttpResponse):
def __init__(self, content):
HttpResponse.__init__(self, content, content_type="text/javascript")
HttpResponse.__init__(self, content,
content_type="application/javascript")


class HttpJavascriptResponseServerError(HttpResponseServerError):
Expand All @@ -35,12 +34,6 @@ def __init__(self, content):
self, content, content_type="text/javascript")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we already update responses, would be worth to clean up them all

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there's no built-in Django response that has the 500 status code and 'javascript' as the content_type, we still need to create our own for this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I wasn't clear, please make sure it will go to follow up trello card.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I was talking about replacing content_type="application/javascript"



class HttpJsonResponse(HttpResponse):
def __init__(self, content):
HttpResponse.__init__(
self, json.dumps(content), content_type="application/json")


class HttpJPEGResponse(HttpResponse):
def __init__(self, content):
HttpResponse.__init__(self, content, content_type="image/jpeg")
16 changes: 15 additions & 1 deletion components/tools/OmeroWeb/omeroweb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,15 @@ def leave_none_unset_int(s):
("Workers silent for more than this many seconds are killed "
"and restarted. Check Gunicorn Documentation "
"http://docs.gunicorn.org/en/stable/settings.html#timeout")],

"omero.web.api.absolute_url":
["API_ABSOLUTE_URL",
None,
str_slash,
("URL to use for generating urls within API json responses. "
"By default this is None, and we use Django's "
"request.build_absolute_uri() to generate absolute urls "
"based on each request. If set to a string or empty string, "
"this will be used as prefix to relative urls.")],

# Public user
"omero.web.public.enabled":
Expand Down Expand Up @@ -1155,6 +1163,12 @@ def report_settings(module):
# FEEDBACK_APP: 6 = OMERO.web
FEEDBACK_APP = 6

# For any given release of api, we may support
# one or more versions of the api.
# E.g. /api/v1.0/
# TODO - need to decide how this is configured, strategy for extending etc.
API_VERSIONS = ('0.1',)
Copy link
Copy Markdown
Member

@atarkowska atarkowska Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I don't understand that? I meant API_VERSIONS = (0,1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the future would be handle to have that in the application package in main __init__.py

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to have the full 'how we're going to handle versions' discussion before we change anything here. This is really just a placeholder for this PR. I'll add a TODO note in the code here.


# IGNORABLE_404_STARTS:
# Default: ('/cgi-bin/', '/_vti_bin', '/_vti_inf')
# IGNORABLE_404_ENDS:
Expand Down
2 changes: 2 additions & 0 deletions components/tools/OmeroWeb/omeroweb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def redirect_urlpatterns():
(r'^(?i)url/', include('omeroweb.webredirect.urls')),
(r'^(?i)feedback/', include('omeroweb.feedback.urls')),

(r'^(?i)api/', include('omeroweb.webgateway.urls_api')),

url(r'^index/$', 'omeroweb.webclient.views.custom_index',
name="webindex_custom"),
)
Expand Down
5 changes: 3 additions & 2 deletions components/tools/OmeroWeb/omeroweb/webadmin/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
from django.conf.urls import url, patterns

from omeroweb.webadmin import views
from omeroweb.webclient import views as webclient_views
from omeroweb.webclient.views import WebclientLoginView

# url patterns
urlpatterns = patterns(
'',
url(r'^$', views.index, name="waindex"),
url(r'^login/$', webclient_views.login, name="walogin"),
url(r'^login/$', WebclientLoginView.as_view(),
name="walogin"),
url(r'^logout/$', views.logout, name="walogout"),
url(r'^forgottenpassword/$', views.forgotten_password,
name="waforgottenpassword"),
Expand Down
2 changes: 1 addition & 1 deletion components/tools/OmeroWeb/omeroweb/webclient/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
views.load_template, {'menu': 'history'},
name="history"),

url(r'^login/$', views.login, name="weblogin"),
url(r'^login/$', views.WebclientLoginView.as_view(), name="weblogin"),
url(r'^logout/$', views.logout, name="weblogout"),
url(r'^active_group/$',
views.change_active_group,
Expand Down
Loading