Skip to content

Commit

Permalink
Merge pull request #387 from lucernae/update_master
Browse files Browse the repository at this point in the history
Update master
  • Loading branch information
lucernae authored Nov 24, 2017
2 parents 4c83358 + 1d14fef commit 5252b37
Show file tree
Hide file tree
Showing 68 changed files with 1,049 additions and 228 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ geonode/static/lib/css/leaflet.fullscreen.css
geonode/static/lib/css/Leaflet.NavBar.css
geonode/static/lib/css/leaflet-measure.css
geonode/static/lib/css/leaflet-plugins.min.css
geonode/static/lib/css/easy-button.css
geonode/static/lib/css/bootstrap-tokenfield.css
geonode/static/lib/js/assets.min.js
geonode/static/lib/js/Control.Opacity.js
Expand Down Expand Up @@ -64,6 +65,8 @@ geonode/static/lib/js/waypoints.js
geonode/static/lib/js/angular.min.js
geonode/static/lib/js/angular.min.js.map
geonode/static/lib/js/ZeroClipboard.min.js
geonode/static/lib/js/clipboard.js
geonode/static/lib/js/easy-button.js
geonode/static/lib/js/moment.min.js
geonode/static/lib/css/bootstrap-treeview.css
geonode/static/lib/js/bootstrap-treeview.js
Expand Down
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ env:
# This is the location of docker network bridge
# So QGIS server can access this address
SITEURL: http://localhost:8000/
GEONODE_PROJECT_PATH: /home/travis/build/kartoza/geonode/
QGIS_SERVER_PORT: 9000
ON_TRAVIS: True
CELERY_ALWAYS_EAGER: True

Expand Down Expand Up @@ -49,16 +49,16 @@ install:
- pip install codecov

before_script:
- paver setup

# For QGIS Server
# For QGIS Server Travis steps
- scripts/misc/qgis_server_setup.sh before_script

- paver setup

script:
- paver run_tests --coverage

after_script:
# For QGIS Server
# For QGIS Server Travis steps
- scripts/misc/qgis_server_setup.sh after_script

# Cleanup
Expand Down
6 changes: 3 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ GeoNode Installation

If you just want to try GeoNode, it is recommended to use Ubuntu 14.04 and install the latest stable release of GeoNode.::

sudo add-apt-repository ppa:geonode/release
sudo add-apt-repository ppa:geonode/stable
sudo apt-get update
sudo apt-get install geonode

Expand Down Expand Up @@ -76,7 +76,7 @@ Or if you want to use the provided Makefile::
255.255.255.255 broadcasthost
::1 localhost

To access GeoNode just enter the following url: http://geonode/ on your web browser.
To access GeoNode just enter the following url: http://geonode/ on your web browser.
For GeoServer: http://geonode/geoserver/web/

Ubuntu
Expand Down Expand Up @@ -104,7 +104,7 @@ Ubuntu development build instructions using an isolated virtual environment (tes
# Install pip dependencies
pip install -r requirements.txt --no-deps
pip install -e .
pip install pygdal==1.10.1
pip install pygdal==1.11.3.3

For Ubuntu 16.04 you should create your virtual-env like this instead (so with site packages)::

Expand Down
8 changes: 5 additions & 3 deletions docker-compose-qgis-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ version: '2'
services:

qgis-server:
image: kartoza/qgis-server:LTR
image: kartoza/geonode_qgis-server
volumes:
# Mount this volume from current directory to
# The absolute path, so these files were mounted
# with the same path
- './:${GEONODE_PROJECT_PATH}'
- './otf-project:/opt/qgis-server/plugins/otf-project'
environment:
- QGIS_LOG_FILE=/tmp/qgis-server/qgis.log
- QGIS_SERVER_LOG_FILE=/tmp/qgis-server/qgis-server.log
Expand All @@ -16,5 +18,5 @@ services:
# QGIS-Server:LTR cgi needs it
- QGIS_PROJECT_FILE=
ports:
- "9000:80"
- "${QGIS_SERVER_PORT}:80"
network_mode: "bridge"
6 changes: 3 additions & 3 deletions docs/reference/developers/settings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ API settings

API_LIMIT_PER_PAGE
------------------
Default: ``0``
Default: ``20``

Number of items returned by the API. 0 equals no limit

Expand Down Expand Up @@ -550,12 +550,12 @@ PINAX_NOTIFICATIONS_QUEUE_ALL

Default: `False`

A boolean that specifies if user notifications should be queued and send outside main web application process. If set to `True`, additional sending script, `python manage.py emit_notices` should be called periodically.
A boolean that specifies if user notifications should be queued and send outside main web application process. If set to `True`, additional sending script, `python manage.py emit_notices` should be called periodically.

PINAX_NOTIFICATIONS_BACKENDS
----------------------------

Default:
Default:

.. code::

Expand Down
34 changes: 27 additions & 7 deletions geonode/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,23 @@ def dehydrate_layers_count(self, bundle):
if not is_admin and not is_staff:
if is_manager:
groups = request.user.groups.all()
group_list_all = []
try:
group_list_all = request.user.group_list_all().values('group')
except:
pass
public_groups = GroupProfile.objects.exclude(access="private").values('group')
try:
anonymous_group = Group.objects.get(name='anonymous')
filter_set = filter_set.filter(
Q(group__isnull=True) | Q(group__in=groups) |
Q(group__in=public_groups) | Q(group=anonymous_group) |
Q(group__in=group_list_all) | Q(group__in=public_groups) |
Q(group=anonymous_group) |
Q(owner__username__iexact=str(request.user)))
except:
filter_set = filter_set.filter(
Q(group__isnull=True) | Q(group__in=groups) |
Q(group__in=public_groups) |
Q(group__in=group_list_all) | Q(group__in=public_groups) |
Q(owner__username__iexact=str(request.user)))

else:
Expand All @@ -285,17 +291,23 @@ def dehydrate_layers_count(self, bundle):
if not is_admin and not is_staff:
if is_manager:
groups = request.user.groups.all()
group_list_all = []
try:
group_list_all = request.user.group_list_all().values('group')
except:
pass
public_groups = GroupProfile.objects.exclude(access="private").values('group')
try:
anonymous_group = Group.objects.get(name='anonymous')
filter_set = filter_set.filter(
Q(group__isnull=True) | Q(group__in=groups) |
Q(group__in=public_groups) | Q(group=anonymous_group) |
Q(group__in=public_groups) | Q(group__in=group_list_all) |
Q(group=anonymous_group) |
Q(owner__username__iexact=str(request.user)))
except:
filter_set = filter_set.filter(
Q(group__isnull=True) | Q(group__in=groups) |
Q(group__in=public_groups) |
Q(group__in=group_list_all) | Q(group__in=public_groups) |
Q(owner__username__iexact=str(request.user)))
else:
filter_set = filter_set.filter(Q(is_published=True) |
Expand All @@ -312,14 +324,22 @@ def dehydrate_layers_count(self, bundle):
filter_set = filter_set
elif request.user:
groups = request.user.groups.all()
group_list_all = []
try:
group_list_all = request.user.group_list_all().values('group')
except:
pass
if anonymous_group:
filter_set = filter_set.filter(
Q(group__isnull=True) | Q(group__in=groups) |
Q(group__in=public_groups) | Q(group=anonymous_group))
Q(group__in=group_list_all) | Q(group__in=public_groups) |
Q(group=anonymous_group) |
Q(owner__username__iexact=str(request.user)))
else:
filter_set = filter_set.filter(
Q(group__isnull=True) |
Q(group__in=public_groups) | Q(group__in=groups))
Q(group__isnull=True) | Q(group__in=public_groups) |
Q(group__in=group_list_all) | Q(group__in=groups) |
Q(owner__username__iexact=str(request.user)))
else:
if anonymous_group:
filter_set = filter_set.filter(
Expand Down
43 changes: 43 additions & 0 deletions geonode/api/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
#
#########################################################################

from tastypie.authentication import ApiKeyAuthentication
from tastypie.authorization import DjangoAuthorization
from tastypie.exceptions import Unauthorized
from tastypie.compat import get_user_model, get_username_field

from guardian.shortcuts import get_objects_for_user
from tastypie.http import HttpUnauthorized

from geonode import geoserver, qgis_server
from geonode.utils import check_ogc_backend
Expand Down Expand Up @@ -74,6 +77,46 @@ def delete_detail(self, object_list, bundle):
bundle.obj.get_self_resource())


class GeonodeApiKeyAuthentication(ApiKeyAuthentication):
"""
Override ApiKeyAuthentication to prevent 401 response when no api key is provided.
"""

def is_authenticated(self, request, **kwargs):
"""
Finds the user and checks their API key.
Should return either ``True`` if allowed, ``False`` if not or an
``HttpResponse`` if you need something custom.
"""

try:
username, api_key = self.extract_credentials(request)
except ValueError:
return self._unauthorized()

if not username or not api_key:
return True

username_field = get_username_field()
User = get_user_model()

try:
lookup_kwargs = {username_field: username}
user = User.objects.get(**lookup_kwargs)
except (User.DoesNotExist, User.MultipleObjectsReturned):
return self._unauthorized()

if not self.check_active(user):
return False

key_auth_check = self.get_key(user, api_key)
if key_auth_check and not isinstance(key_auth_check, HttpUnauthorized):
request.user = user

return key_auth_check


class GeoNodeStyleAuthorization(GeoNodeAuthorization):
"""Object level API authorization based on GeoNode granular
permission system
Expand Down
Loading

0 comments on commit 5252b37

Please sign in to comment.