Skip to content

Commit

Permalink
Merge branch 'develop' into hotfix/update_get_role
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-salles committed Aug 29, 2022
2 parents 66dd40b + 60f2d35 commit 0619bd4
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 218 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sudo: true

language: python
python:
- "3.6.8"
- "3.8.13"

services:
- docker
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
FROM python:3.6-slim
FROM python:3.8.13-slim

ENV WORKDIR /home/app
WORKDIR $WORKDIR

RUN apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests -y apt-utils \
&& apt-get install --no-install-recommends --no-install-suggests -y gcc bzip2 git curl nginx libpq-dev gettext \
libgdal-dev python3-cffi python3-gdal vim
&& apt-get install --no-install-recommends --no-install-suggests -y apt-utils \
&& apt-get install --no-install-recommends --no-install-suggests -y gcc bzip2 git curl nginx libpq-dev gettext \
libgdal-dev python3-cffi python3-gdal vim

RUN apt-get install make

RUN pip install -U pip==21.2.2 setuptools==57.4.0
RUN pip install poetry==1.1.12
RUN pip install gunicorn==19.9.0
RUN pip install gevent==1.4.0
RUN pip install gevent==21.12.0
RUN pip install psycopg2-binary
RUN apt-get install -y libjpeg-dev libgpgme-dev linux-libc-dev musl-dev libffi-dev libssl-dev
ENV LIBRARY_PATH=/lib:/usr/lib
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

# Requirements

* Python (3.6)
* Python (3.8.13)
* Poetry
* Docker
* Docker-compose
Expand Down
5 changes: 1 addition & 4 deletions bothub/api/v2/internal/organization/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@

from bothub.api.v2.metadata import Metadata
from bothub.authentication.models import User
from bothub.common.models import (
Organization,
OrganizationAuthorization
)
from bothub.common.models import Organization, OrganizationAuthorization
from bothub.api.v2.internal.organization.serializers import (
OrganizationSerializer,
OrgCreateSerializer,
Expand Down
2 changes: 2 additions & 0 deletions bothub/api/v2/repository/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,8 @@ def destroy(self, request, *args, **kwargs):


class RepositoryTokenByUserViewSet(mixins.ListModelMixin, GenericViewSet):
serializer_class = RepositoryAuthorizationSerializer

def get_queryset(self):
user = self.request.user
if user.is_anonymous:
Expand Down
2 changes: 1 addition & 1 deletion bothub/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ def get_user_authorization(self, user):

if repo_auth.role < org_auth.role:
repo_auth.role = org_auth.role
repo_auth.save(update_fields=['role'])
repo_auth.save(update_fields=["role"])
return repo_auth

def get_absolute_url(self):
Expand Down
31 changes: 22 additions & 9 deletions bothub/common/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
QAKnowledgeBase,
QAtext,
Organization,
OrganizationAuthorization
OrganizationAuthorization,
)
from .models import RepositoryAuthorization
from .models import RepositoryEntity
Expand Down Expand Up @@ -546,7 +546,9 @@ class RepositoryAuthorizationTestCase(TestCase):
def setUp(self):
self.owner = User.objects.create_user("owner@user.com", "owner")
self.user = User.objects.create_user("fake@user.com", "user")
self.collaborator = User.objects.create_user("colaborator@user.com", "collaborator")
self.collaborator = User.objects.create_user(
"colaborator@user.com", "collaborator"
)

self.repository = Repository.objects.create(
owner=self.owner.repository_owner, name="Test", slug="test"
Expand All @@ -561,7 +563,7 @@ def setUp(self):
self.organization_repository = Repository.objects.create(
owner=self.organization,
name="Organization Repository",
slug="organization_repository"
slug="organization_repository",
)

def test_admin_level(self):
Expand Down Expand Up @@ -702,16 +704,25 @@ def test_organization_auth_over_repository_auth(self):
initial_organization_role = OrganizationAuthorization.ROLE_ADMIN

# Set user's role to a low level at the Repository
collaborator_repository_auth, created = RepositoryAuthorization.objects.get_or_create(
user=self.collaborator, repository=self.organization_repository, role=RepositoryAuthorization.ROLE_USER
(
collaborator_repository_auth,
created,
) = RepositoryAuthorization.objects.get_or_create(
user=self.collaborator,
repository=self.organization_repository,
role=RepositoryAuthorization.ROLE_USER,
)
# Set user's role to a high level at the Organization
collaborator_organization_auth = self.organization.organization_authorizations.create(
user=self.collaborator, role=initial_organization_role
collaborator_organization_auth = (
self.organization.organization_authorizations.create(
user=self.collaborator, role=initial_organization_role
)
)

# Validate that their access level corresponds to their role in the Organization and not the Repository, as it is higher at this point.
user_authorization = self.organization_repository.get_user_authorization(self.collaborator)
user_authorization = self.organization_repository.get_user_authorization(
self.collaborator
)
self.assertEqual(user_authorization.role, collaborator_organization_auth.role)

# Lower their level inside the Organization
Expand All @@ -723,7 +734,9 @@ def test_organization_auth_over_repository_auth(self):
self.assertEqual(collaborator_repository_auth.role, initial_organization_role)

# Validate that the user's level is now the Repository's and not the Organization's, as it is higher.
user_authorization = self.organization_repository.get_user_authorization(self.collaborator)
user_authorization = self.organization_repository.get_user_authorization(
self.collaborator
)
self.assertEqual(user_authorization.role, collaborator_repository_auth.role)


Expand Down
2 changes: 1 addition & 1 deletion bothub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@

envvar_EMAIL_HOST = env.str("EMAIL_HOST")

ADMINS = [("Helder", "helder.souza@weni.ai")] # env.list("ADMINS")
ADMINS = env.list("ADMINS")
EMAIL_SUBJECT_PREFIX = "[bothub] "
DEFAULT_FROM_EMAIL = env.str("DEFAULT_FROM_EMAIL")
SERVER_EMAIL = env.str("SERVER_EMAIL")
Expand Down

0 comments on commit 0619bd4

Please sign in to comment.