diff --git a/members/admin/activity_admin.py b/members/admin/activity_admin.py index c92ef91c..9eec2aea 100644 --- a/members/admin/activity_admin.py +++ b/members/admin/activity_admin.py @@ -193,7 +193,11 @@ def get_queryset(self, request): # Only show own departments when creating new activity def formfield_for_foreignkey(self, db_field, request, **kwargs): - if db_field.name == "department" and not request.user.is_superuser: + if ( + db_field.name == "department" + and not request.user.is_superuser + and not request.user.has_perm("members.view_all_departments") + ): kwargs["queryset"] = Department.objects.filter( adminuserinformation__user=request.user ) diff --git a/members/admin/activityinvite_admin.py b/members/admin/activityinvite_admin.py index 343eb90b..250fdec2 100644 --- a/members/admin/activityinvite_admin.py +++ b/members/admin/activityinvite_admin.py @@ -187,7 +187,11 @@ def get_queryset(self, request): # Limit the activity possible to invite to: Not finished and belonging to user def formfield_for_foreignkey(self, db_field, request, **kwargs): - if db_field.name == "activity" and not request.user.is_superuser: + if ( + db_field.name == "activity" + and not request.user.is_superuser + and not request.user.has_perm("members.view_all_departments") + ): departments = Department.objects.filter( adminuserinformation__user=request.user ) diff --git a/members/admin/admin_actions.py b/members/admin/admin_actions.py index 961a3219..8dbd2440 100644 --- a/members/admin/admin_actions.py +++ b/members/admin/admin_actions.py @@ -34,7 +34,7 @@ def invite_many_to_activity_action(modelAdmin, request, queryset): # Get list of available departments if request.user.is_superuser or request.user.has_perm( - "members.view_all_persons" + "members.view_all_departments" ): department_list_query = Department.objects.all().order_by("name") else: @@ -50,7 +50,9 @@ def invite_many_to_activity_action(modelAdmin, request, queryset): activity_list_query = Activity.objects.filter( end_date__gt=timezone.now() ).order_by("department__name", "name") - if not request.user.is_superuser: + if not request.user.is_superuser and not request.user.has_perm( + "members.view_all_departments" + ): activity_list_query = activity_list_query.filter( department__in=department_ids ).order_by("department__name", "name") diff --git a/members/admin/family_admin.py b/members/admin/family_admin.py index 0b93f86a..58232b3f 100644 --- a/members/admin/family_admin.py +++ b/members/admin/family_admin.py @@ -57,7 +57,9 @@ def resend_link_email(self, request, queryset): # Only view familys related to users department (via participant, waitinglist & invites) def get_queryset(self, request): qs = super(FamilyAdmin, self).get_queryset(request) - if request.user.is_superuser: + if request.user.is_superuser or request.user.has_perm( + "members.view_all_departments" + ): return qs departments = Department.objects.filter( adminuserinformation__user=request.user diff --git a/members/admin/inlines.py b/members/admin/inlines.py index cedc9281..84fd9f61 100644 --- a/members/admin/inlines.py +++ b/members/admin/inlines.py @@ -44,7 +44,11 @@ class ActivityInviteInline(admin.TabularInline): # Limit the activity possible to invite to: Not finished and belonging to user def formfield_for_foreignkey(self, db_field, request, **kwargs): - if db_field.name == "activity" and not request.user.is_superuser: + if ( + db_field.name == "activity" + and not request.user.is_superuser + and not request.user.has_perm("members.view_all_departments") + ): departments = Department.objects.filter( adminuserinformation__user=request.user ) @@ -56,8 +60,6 @@ def formfield_for_foreignkey(self, db_field, request, **kwargs): # Only view invites it would be possible for user to give out def get_queryset(self, request): qs = super(ActivityInviteInline, self).get_queryset(request) - if request.user.is_superuser: - return qs return qs.filter( activity__department__in=AdminUserInformation.get_departments_admin( request.user diff --git a/members/admin/person_admin.py b/members/admin/person_admin.py index 0b22487a..7054e3f5 100644 --- a/members/admin/person_admin.py +++ b/members/admin/person_admin.py @@ -217,8 +217,10 @@ def export_csv(self, request, queryset): # Only view persons related to users department (all family, via participant, waitinglist & invites) def get_queryset(self, request): qs = super(PersonAdmin, self).get_queryset(request) - if request.user.is_superuser or request.user.has_perm( - "members.view_all_persons" + if ( + request.user.is_superuser + or request.user.has_perm("members.view_all_persons") + or request.user.has_perm("members.view_all_departments") ): return qs else: diff --git a/members/models/address.py b/members/models/address.py index ba9092a8..f01bcd38 100644 --- a/members/models/address.py +++ b/members/models/address.py @@ -113,12 +113,8 @@ def get_by_dawa_id(dawa_id): @staticmethod def get_user_addresses(user): - if user.is_superuser: + if user.is_superuser or user.has_perm("members.view_all_departments"): return Address.objects.all() - if user.has_perm("members.view_all_departments"): - department_address_id = [ - department.address.id for department in Department.objects.all() - ] else: department_address_id = [ department.address.id diff --git a/members/models/admin_user_information.py b/members/models/admin_user_information.py index d187f0db..e7df4a41 100644 --- a/members/models/admin_user_information.py +++ b/members/models/admin_user_information.py @@ -17,14 +17,14 @@ def __str__(self): @staticmethod def get_departments_admin(user): - if user.is_superuser: + if user.is_superuser or user.has_perm("members.view_all_departments"): return Department.objects.all() else: return Department.objects.filter(adminuserinformation__user=user) @staticmethod def get_unions_admin(user): - if user.is_superuser: + if user.is_superuser or user.has_perm("members.view_all_unions"): return Union.objects.all() else: return Union.objects.filter(adminuserinformation__user=user) diff --git a/poetry.lock b/poetry.lock index db52aa81..98e6839f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. [[package]] name = "aniso8601" @@ -615,22 +615,23 @@ graphql-core = ">=3.2,<3.3" [[package]] name = "gunicorn" -version = "20.1.0" +version = "22.0.0" description = "WSGI HTTP Server for UNIX" optional = false -python-versions = ">=3.5" +python-versions = ">=3.7" files = [ - {file = "gunicorn-20.1.0-py3-none-any.whl", hash = "sha256:9dcc4547dbb1cb284accfb15ab5667a0e5d1881cc443e0677b4882a4067a807e"}, - {file = "gunicorn-20.1.0.tar.gz", hash = "sha256:e0a968b5ba15f8a328fdfd7ab1fcb5af4470c28aaf7e55df02a99bc13138e6e8"}, + {file = "gunicorn-22.0.0-py3-none-any.whl", hash = "sha256:350679f91b24062c86e386e198a15438d53a7a8207235a78ba1b53df4c4378d9"}, + {file = "gunicorn-22.0.0.tar.gz", hash = "sha256:4a0b436239ff76fb33f11c07a16482c521a7e09c1ce3cc293c2330afe01bec63"}, ] [package.dependencies] -setuptools = ">=3.0" +packaging = "*" [package.extras] -eventlet = ["eventlet (>=0.24.1)"] +eventlet = ["eventlet (>=0.24.1,!=0.36.0)"] gevent = ["gevent (>=1.4.0)"] setproctitle = ["setproctitle"] +testing = ["coverage", "eventlet", "gevent", "pytest", "pytest-cov"] tornado = ["tornado (>=0.2)"] [[package]] @@ -646,13 +647,13 @@ files = [ [[package]] name = "idna" -version = "3.6" +version = "3.7" description = "Internationalized Domain Names in Applications (IDNA)" optional = false python-versions = ">=3.5" files = [ - {file = "idna-3.6-py3-none-any.whl", hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f"}, - {file = "idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"}, + {file = "idna-3.7-py3-none-any.whl", hash = "sha256:82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0"}, + {file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"}, ] [[package]] @@ -985,22 +986,6 @@ starlette = ["starlette (>=0.19.1)"] starlite = ["starlite (>=1.48)"] tornado = ["tornado (>=5)"] -[[package]] -name = "setuptools" -version = "69.2.0" -description = "Easily download, build, install, upgrade, and uninstall Python packages" -optional = false -python-versions = ">=3.8" -files = [ - {file = "setuptools-69.2.0-py3-none-any.whl", hash = "sha256:c21c49fb1042386df081cb5d86759792ab89efca84cf114889191cd09aacc80c"}, - {file = "setuptools-69.2.0.tar.gz", hash = "sha256:0ff4183f8f42cd8fa3acea16c45205521a4ef28f73c6391d8a25e92893134f2e"}, -] - -[package.extras] -docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (<7.2.5)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier"] -testing = ["build[virtualenv]", "filelock (>=3.4.0)", "importlib-metadata", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "mypy (==1.9)", "packaging (>=23.2)", "pip (>=19.1)", "pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-home (>=0.5)", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-ruff (>=0.2.1)", "pytest-timeout", "pytest-xdist (>=3)", "tomli", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] -testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.2)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] - [[package]] name = "six" version = "1.16.0" @@ -1047,19 +1032,18 @@ files = [ [[package]] name = "sqlparse" -version = "0.4.4" +version = "0.5.0" description = "A non-validating SQL parser." optional = false -python-versions = ">=3.5" +python-versions = ">=3.8" files = [ - {file = "sqlparse-0.4.4-py3-none-any.whl", hash = "sha256:5430a4fe2ac7d0f93e66f1efc6e1338a41884b7ddf2a350cedd20ccc4d9d28f3"}, - {file = "sqlparse-0.4.4.tar.gz", hash = "sha256:d446183e84b8349fa3061f0fe7f06ca94ba65b426946ffebe6e3e8295332420c"}, + {file = "sqlparse-0.5.0-py3-none-any.whl", hash = "sha256:c204494cd97479d0e39f28c93d46c0b2d5959c7b9ab904762ea6c7af211c8663"}, + {file = "sqlparse-0.5.0.tar.gz", hash = "sha256:714d0a4932c059d16189f58ef5411ec2287a4360f17cdd0edd2d09d4c5087c93"}, ] [package.extras] -dev = ["build", "flake8"] +dev = ["build", "hatch"] doc = ["sphinx"] -test = ["pytest", "pytest-cov"] [[package]] name = "text-unidecode" @@ -1085,17 +1069,23 @@ files = [ [[package]] name = "tqdm" -version = "4.53.0" +version = "4.66.3" description = "Fast, Extensible Progress Meter" optional = false -python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7" +python-versions = ">=3.7" files = [ - {file = "tqdm-4.53.0-py2.py3-none-any.whl", hash = "sha256:5ff3f5232b19fa4c5531641e480b7fad4598819f708a32eb815e6ea41c5fa313"}, - {file = "tqdm-4.53.0.tar.gz", hash = "sha256:3d3f1470d26642e88bd3f73353cb6ff4c51ef7d5d7efef763238f4bc1f7e4e81"}, + {file = "tqdm-4.66.3-py3-none-any.whl", hash = "sha256:4f41d54107ff9a223dca80b53efe4fb654c67efaba7f47bada3ee9d50e05bd53"}, + {file = "tqdm-4.66.3.tar.gz", hash = "sha256:23097a41eba115ba99ecae40d06444c15d1c0c698d527a01c6c8bd1c5d0647e5"}, ] +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + [package.extras] -dev = ["argopt", "py-make (>=0.1.0)", "pydoc-markdown", "twine", "wheel"] +dev = ["pytest (>=6)", "pytest-cov", "pytest-timeout", "pytest-xdist"] +notebook = ["ipywidgets (>=6)"] +slack = ["slack-sdk"] +telegram = ["requests"] [[package]] name = "trio" @@ -1205,4 +1195,4 @@ h11 = ">=0.9.0,<1" [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "8e4c18289e5945a5562397b21bae7481d39f3f034f150f9154fc8382d00855a5" +content-hash = "6341c970730be47b8d4c325e1a6f3dcdc619e185f233015af9602d24112afc76" diff --git a/pyproject.toml b/pyproject.toml index e722fdc7..9fcb85b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,11 +27,11 @@ factory-boy = "3.0.1" flake8 = "3.8.4" freezegun = "1.2.2" graphene_django = "3.0.0" -gunicorn = "20.1.0" +gunicorn = "22.0.0" psycopg2 = "2.9.5" quickpay-api-client = "2.0.1" sentry-sdk = "1.14" -tqdm = "4.53.0" +tqdm = "4.66.3" whitenoise = "5.2.0" pydotplus = "2.0.2" selenium = "4.9.0"