Skip to content

Commit

Permalink
batch: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanga committed Apr 29, 2022
1 parent 8add763 commit 68926e7
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 199 deletions.
15 changes: 0 additions & 15 deletions .github/ISSUE_TEMPLATE.md

This file was deleted.

2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ assignees: ''

### Environmental Information

- Onadata version:
- Onadata version:

### Problem description

Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

### Side effects of implementing this change

### Before submitting this PR for review, please make sure you have:

- [ ] Included tests
- [ ] Updated documentation
**Before submitting this PR for review, please make sure you have:**

- [ ] Included tests
- [ ] Updated documentation

Closes #
30 changes: 15 additions & 15 deletions CONTRIBUTING.MD
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,37 @@ The following is a set of guidelines for contributing to Ona Data. Following the

In case you have encountered any issue within the project, please make sure:

- You are using the [latest release](http://github.com/onaio/onadata/releases).
- You have setup the project according to the [Installation Documentation](https://api.ona.io/static/docs/install.html).
- You are using the [latest release](http://github.com/onaio/onadata/releases).
- You have setup the project according to the [Installation Documentation](https://api.ona.io/static/docs/install.html).

After confirming the above, make sure the issue has not been reported on our [issues page](https://github.com/onaio/onadata/issues). If it hasn't been reported, [open a ticket](https://github.com/onaio/onadata/issues/new) containing:

- Information about your system environment (Operating System, local settings, etc.).
- What you expected to happen, and what actually happened.
- Out of place / weird logs and any other interesting information
- All steps to reproduce the issue.
- Information about your system environment (Operating System, local settings, etc.).
- What you expected to happen, and what actually happened.
- Out of place / weird logs and any other interesting information
- All steps to reproduce the issue.

### 2. Suggest Enhancements or New Features ⚡

Feature and enhancement requests are always welcome! We ask you ensure the following details are provided while [opening a ticket](https://github.com/onaio/onadata/issues/new), in order to start a constructive discussion:

- Describe the feature/enhancement in detail.
- Explain why the feature/enhancement is needed.
- Describe how the feature/enhancement should work
- List any advantages & disadvantages of implementing the feature/enhancement
- Describe the feature/enhancement in detail.
- Explain why the feature/enhancement is needed.
- Describe how the feature/enhancement should work
- List any advantages & disadvantages of implementing the feature/enhancement

### 3. Code contributions / Pull requests 💻

Pull requests are wholeheartedly welcome!❤️ If you are unsure about how to make your first pull request, here are some helpful resources:

- [Creating a pull request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request)
- [How to create effective pull requests](https://dev.to/mpermar/how-to-create-effective-pull-requests-2m8e)
- [Creating a pull request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request)
- [How to create effective pull requests](https://dev.to/mpermar/how-to-create-effective-pull-requests-2m8e)

In order to make it easier for us to facilitate the smooth merging of your pull request, please make sure the following standards are met within your pull request.

- Ensure your git commits are signed. _Read about signing commits [here](https://help.github.com/en/github/authenticating-to-github/signing-commits)_
- Code & commits follow our [styleguides](#Styleguides).
- Implement / Update tests that need to be updated and ensure that they pass. _Running all the tests within this project may be tough and time consuming. But not to worry! On submission of the pull request, [Travis CI](https://travis-ci.org/) will run all the tests across our modules_.
- Ensure your git commits are signed. _Read about signing commits [here](https://help.github.com/en/github/authenticating-to-github/signing-commits)_
- Code & commits follow our [styleguides](#Styleguides).
- Implement / Update tests that need to be updated and ensure that they pass. _Running all the tests within this project may be tough and time consuming. But not to worry! On submission of the pull request, [Travis CI](https://travis-ci.org/) will run all the tests across our modules_.

With the above points in mind feel free to comment on one of our [beginner-friendly issues](https://github.com/onaio/onadata/issues?q=is%3Aissue+is%3Aopen+label%3A%22Good+First+Issue%22) expressing your intent to work on it.

Expand Down
6 changes: 3 additions & 3 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [ ${INITDB} ]; then
if [ "${INITDB}" ]; then
RUN_DB_INIT_SCRIPT=$INITDB
else
RUN_DB_INIT_SCRIPT=true
Expand All @@ -13,8 +13,8 @@ if $RUN_DB_INIT_SCRIPT; then
psql -h db -U postgres onadata -c "CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology;"
fi

virtualenv -p `which $SELECTED_PYTHON` /srv/onadata/.virtualenv/${SELECTED_PYTHON}
. /srv/onadata/.virtualenv/${SELECTED_PYTHON}/bin/activate
virtualenv -p "$(which ${SELECTED_PYTHON})" /srv/onadata/.virtualenv/"${SELECTED_PYTHON}"
. /srv/onadata/.virtualenv/"${SELECTED_PYTHON}"/bin/activate

cd /srv/onadata
pip install --upgrade pip
Expand Down
9 changes: 4 additions & 5 deletions docker/postgis/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
FROM postgres:9.6

MAINTAINER Ukang'a Dickson <[email protected]>
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install -y postgresql-9.6-postgis-2.3 \
postgresql-9.6-postgis-script postgis \
apt-get install --no-install-recommends -y \
postgresql-9.6-postgis-2.3=2.3.1+dfsg-2+deb9u2 \
postgresql-9.6-postgis-2.3-scripts=2.3.1+dfsg-2+deb9u2 \
postgis=2.3.1+dfsg-2+deb9u2 \
&& rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["docker-entrypoint.sh"]
Expand Down
23 changes: 11 additions & 12 deletions onadata/apps/api/admin.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
# -*- coding: utf-8 -*-
"""API Django admin amendments."""
from django.contrib import admin

from onadata.apps.api.models import Team, OrganizationProfile, TempToken


class TeamAdmin(admin.ModelAdmin):

def get_queryset(self, request):
qs = super(TeamAdmin, self).get_queryset(request)
queryset = super(TeamAdmin, self).get_queryset(request)
if request.user.is_superuser:
return qs
return qs.filter(user=request.user)
return queryset
return queryset.filter(user=request.user)


admin.site.register(Team, TeamAdmin)


class OrganizationProfileAdmin(admin.ModelAdmin):

def get_queryset(self, request):
qs = super(OrganizationProfileAdmin, self).get_queryset(request)
queryset = super(OrganizationProfileAdmin, self).get_queryset(request)
if request.user.is_superuser:
return qs
return qs.filter(user=request.user)
return queryset
return queryset.filter(user=request.user)


admin.site.register(OrganizationProfile, OrganizationProfileAdmin)


class TempTokenProfileAdmin(admin.ModelAdmin):

def get_queryset(self, request):
qs = super(TempTokenProfileAdmin, self).get_queryset(request)
queryset = super(TempTokenProfileAdmin, self).get_queryset(request)
if request.user.is_superuser:
return qs
return qs.filter(user=request.user)
return queryset
return queryset.filter(user=request.user)


admin.site.register(TempToken, TempTokenProfileAdmin)
70 changes: 45 additions & 25 deletions onadata/apps/api/management/commands/fix_readonly_role_perms.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
from guardian.shortcuts import get_perms

from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from django.utils.translation import gettext as _
from django.conf import settings
from onadata.apps.api.models import Team


from onadata.libs.permissions import ReadOnlyRole, DataEntryRole,\
EditorRole, ManagerRole, OwnerRole, ReadOnlyRoleNoDownload,\
DataEntryOnlyRole, DataEntryMinorRole, EditorMinorRole
from onadata.libs.permissions import (
ReadOnlyRole,
DataEntryRole,
EditorRole,
ManagerRole,
OwnerRole,
ReadOnlyRoleNoDownload,
DataEntryOnlyRole,
DataEntryMinorRole,
EditorMinorRole,
)
from onadata.libs.utils.model_tools import queryset_iterator


User = get_user_model()


class Command(BaseCommand):
args = '<app model [created_perm] >'
help = _(u"Reassign permission to the model when permissions are changed")
args = "<app model [created_perm] >"
help = _("Reassign permission to the model when permissions are changed")

def handle(self, *args, **options):
self.stdout.write("Re-assigining started", ending='\n')
self.stdout.write("Re-assigining started", ending="\n")

if not args:
raise CommandError('Param not set. <app model [created_perm]>')
raise CommandError("Param not set. <app model [created_perm]>")

if len(args) < 3:
raise CommandError('Param not set. <app model [created_perm]>')
raise CommandError("Param not set. <app model [created_perm]>")

app = args[0]
model = args[1]
Expand All @@ -47,8 +58,9 @@ def handle(self, *args, **options):
for team in queryset_iterator(teams):
self.reassign_perms(team, app, model, new_perms)

self.stdout.write("Re-assigining finished", ending='\n')
self.stdout.write("Re-assigining finished", ending="\n")

# pylint: disable=unused-argument
def reassign_perms(self, user, app, model, new_perm):
"""
Gets all the permissions the user has on objects and assigns the new
Expand All @@ -65,41 +77,47 @@ def reassign_perms(self, user, app, model, new_perm):
if isinstance(user, Team):
if model == "project":
objects = user.projectgroupobjectpermission_set.filter(
group_id=user.pk).distinct('content_object_id')
group_id=user.pk
).distinct("content_object_id")
else:
objects = user.xformgroupobjectpermission_set.filter(
group_id=user.pk).distinct('content_object_id')
group_id=user.pk
).distinct("content_object_id")
else:
if model == 'project':
if model == "project":
objects = user.projectuserobjectpermission_set.all()
else:
objects = user.xformuserobjectpermission_set.all()

for perm_obj in objects:
obj = perm_obj.content_object
ROLES = [ReadOnlyRoleNoDownload,
ReadOnlyRole,
DataEntryOnlyRole,
DataEntryMinorRole,
DataEntryRole,
EditorMinorRole,
EditorRole,
ManagerRole,
OwnerRole]
ROLES = [
ReadOnlyRoleNoDownload,
ReadOnlyRole,
DataEntryOnlyRole,
DataEntryMinorRole,
DataEntryRole,
EditorMinorRole,
EditorRole,
ManagerRole,
OwnerRole,
]

# For each role reassign the perms
for role_class in reversed(ROLES):
# want to only process for readonly perms
if role_class.user_has_role(user, obj) or role_class \
not in [ReadOnlyRoleNoDownload, ReadOnlyRole]:
if role_class.user_has_role(user, obj) or role_class not in [
ReadOnlyRoleNoDownload,
ReadOnlyRole,
]:
continue

if self.check_role(role_class, user, obj, new_perm):
# If true
role_class.add(user, obj)
break

def check_role(self, role_class, user, obj, new_perm=[]):
def check_role(self, role_class, user, obj, new_perm=None):
"""
Test if the user has the role for the object provided
:param role_class:
Expand All @@ -108,6 +126,7 @@ def check_role(self, role_class, user, obj, new_perm=[]):
:param new_perm:
:return:
"""
new_perm = new_perm if new_perm is None else []
# remove the new permission because the old model doesnt have it
perm_list = role_class.class_to_permissions[type(obj)]
old_perm_set = set(perm_list)
Expand All @@ -120,3 +139,4 @@ def check_role(self, role_class, user, obj, new_perm=[]):
return set(get_perms(user, obj)) == diff_set

return user.has_perms(list(diff_set), obj)
return False
Loading

0 comments on commit 68926e7

Please sign in to comment.