Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change permission logic #159

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

### Added

- nothing added
- Add model InstancePermission to determine read and write permissions for a user
- InstancePermission are bulk created or bulk updated

### Changed

- nothing changed
- Changed the logic of read/write permissions by user: A user that has read/write access to an instance of the model Model, will have an instance of InstancePermission (with the model_name="Model") and the uid of the instance will be in the read/write_instance_uids
- Update black version

### Removed

Expand Down
69 changes: 69 additions & 0 deletions concrete_datastore/admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
AuthToken,
ConcretePermission,
EmailDevice,
InstancePermission,
SystemVersion,
)
from concrete_datastore.concrete.models import (
divider,
Expand Down Expand Up @@ -231,3 +233,70 @@ class EmailDeviceAdmin(SaveModelMixin, admin.ModelAdmin):
'modification_date',
]
list_filter = ['mfa_mode', 'confirmed']


@admin.register(InstancePermission, site=admin_site)
class InstancePermissionAdmin(SaveModelMixin, admin.ModelAdmin):
list_display = [
'uid',
'user',
'model_name',
'creation_date',
'modification_date',
]
search_fields = ['user__email']
readonly_fields = [
'uid',
'user',
'model_name',
'creation_date',
'modification_date',
]
date_hierarchy = 'creation_date'

fields = [
'uid',
'user',
'model_name',
'read_instance_uids',
'write_instance_uids',
'creation_date',
'modification_date',
]
list_filter = ['model_name']


@admin.register(SystemVersion, site=admin_site)
class SystemVersionAdmin(SaveModelMixin, admin.ModelAdmin):
@admin.action(description='Tag as latest')
def tag_as_latest(self, request, queryset):
queryset.update(is_latest=True)

@admin.action(description='Untag as latest')
def untag_as_latest(self, request, queryset):
queryset.update(is_latest=False)

list_display = [
'uid',
'app_name',
'version',
'is_latest',
'creation_date',
'modification_date',
]
search_fields = ['app_name']
readonly_fields = ['uid', 'creation_date', 'modification_date']
date_hierarchy = 'creation_date'

fields = [
'uid',
'user',
'model_name',
'read_instance_uids',
'write_instance_uids',
'creation_date',
'modification_date',
]
list_filter = ['app_name', 'is_latest']

actions = ['tag_as_latest', 'untag_as_latest']
1 change: 0 additions & 1 deletion concrete_datastore/admin/admin_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class MyAuthForm(forms.AuthenticationForm):


class OTPAuthenticationForm(MyAuthForm, OTPAuthenticationFormMixin):

otp_error_messages = {
'token_required': _('Please enter your OTP token.'),
'challenge_exception': _('Error generating challenge: {0}'),
Expand Down
1 change: 0 additions & 1 deletion concrete_datastore/api/v1/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ class FilterSupportingOrBackend(
BaseFilterBackend, CustomShemaOperationParameters
):
def get_schema_operation_parameters(self, view):

params = [
{
'name': f'{field_name}__in{neg}',
Expand Down
Loading