Skip to content

Commit

Permalink
Merge permissions-v3 (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffo99 authored Aug 10, 2021
1 parent 09d2452 commit c74761e
Show file tree
Hide file tree
Showing 33 changed files with 764 additions and 1,424 deletions.
1 change: 1 addition & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 43 additions & 1 deletion backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pandaSDMX = "^1.4.2"
pydantic = "~1.7.3"
django-pam = "^2.0.0"
django-colorfield = "^0.4.2"
deprecation = "^2.1.0"

[tool.poetry.dev-dependencies]

Expand Down
142 changes: 4 additions & 138 deletions backend/sophon/core/admin.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from django.contrib import admin, messages
from django.contrib import admin

from . import models


class CoreAdmin(admin.ModelAdmin):
class SophonAdmin(admin.ModelAdmin):
"""
:class:`django.contrib.admin.ModelAdmin` class from which all other admin classes inherit.
Base :class:`django.contrib.admin.ModelAdmin` class from which all other admin classes inherit.
"""


@admin.register(models.ResearchGroup)
class ResearchGroupAdmin(CoreAdmin):
class ResearchGroupAdmin(SophonAdmin):
list_display = (
"slug",
"name",
Expand All @@ -20,137 +20,3 @@ class ResearchGroupAdmin(CoreAdmin):
ordering = (
"slug",
)


@admin.register(models.ResearchTag)
class ResearchTagAdmin(CoreAdmin):
list_display = (
"slug",
"name",
"color",
"owner",
)

ordering = (
"slug",
)


@admin.register(models.ResearchProject)
class ResearchProjectAdmin(CoreAdmin):
list_display = (
"group",
"slug",
"name",
"visibility",
)

ordering = (
"slug",
)


@admin.action(description="Sync DataFlows")
def sync_flows_admin(modeladmin, request, queryset):
for datasource in queryset:
datasource: models.DataSource
try:
datasource.sync_flows()
except NotImplementedError:
modeladmin.message_user(
request,
f"Skipped {datasource}: Syncing DataFlows is not supported on this DataSource.",
level=messages.ERROR
)
except Exception as exc:
modeladmin.message_user(
request,
f"Skipped {datasource}: {exc}",
level=messages.ERROR
)
else:
modeladmin.log_change(request, datasource, "Sync DataFlows")


@admin.register(models.DataSource)
class DataSourceAdmin(CoreAdmin):
list_display = (
"id",
"name",
"data_content_type",
"last_sync",
)

ordering = (
"last_sync",
)

actions = (
sync_flows_admin,
)

fieldsets = (
(
None, {
"fields": (
"id",
"name",
"description",
)
}
),
(
"URLs", {
"fields": (
"url",
"documentation",
)
}
),
(
"API configuration", {
"fields": (
"data_content_type",
"headers",
"resources",
)
}
),
(
"Features supported", {
"fields": (
"supports_agencyscheme",
"supports_categoryscheme",
"supports_codelist",
"supports_conceptscheme",
"supports_data",
"supports_dataflow",
"supports_datastructure",
"supports_provisionagreement",
"supports_preview",
"supports_structurespecific_data",
)
}
),
(
"Syncronization", {
"fields": (
"last_sync",
)
}
)
)


@admin.register(models.DataFlow)
class DataFlowAdmin(CoreAdmin):
list_display = (
"datasource",
"sdmx_id",
"description",
)

ordering = (
"datasource",
"sdmx_id",
)
22 changes: 22 additions & 0 deletions backend/sophon/core/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import enum


class SophonGroupAccess(enum.IntEnum):
"""
The level of access an user has in a group.
From the highest to the lowest:
- Instance superuser
- Group owner
- Group member
- Instance user
- Anonymous user
Since access levels are instance of an :class:`~enum.IntEnum`, they can be compared with ``==``, ``!=``, ``>``, ``<``, ``>=`` and ``<=``.
"""

SUPERUSER = 200
OWNER = 100
MEMBER = 50
REGISTERED = 10
NONE = 0
Loading

0 comments on commit c74761e

Please sign in to comment.