mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-21 01:48:21 +02:00
Compare commits
2 Commits
permission
...
nix-shell
Author | SHA1 | Date | |
---|---|---|---|
dde1baa25c | |||
7a7ee47e0b |
1
.gitignore
vendored
1
.gitignore
vendored
@ -47,7 +47,6 @@ backups/
|
||||
env/
|
||||
venv/
|
||||
db.sqlite3
|
||||
shell.nix
|
||||
|
||||
# ansibles customs host
|
||||
ansible/host_vars/*.yaml
|
||||
|
@ -4,7 +4,7 @@
|
||||
from django.contrib import admin
|
||||
from note_kfet.admin import admin_site
|
||||
|
||||
from .models import Permission, PermissionVar, PermissionMask, Role
|
||||
from .models import Permission, PermissionMask, Role
|
||||
|
||||
|
||||
@admin.register(PermissionMask, site=admin_site)
|
||||
@ -15,14 +15,6 @@ class PermissionMaskAdmin(admin.ModelAdmin):
|
||||
list_display = ('description', 'rank', )
|
||||
|
||||
|
||||
@admin.register(PermissionVar, site=admin_site)
|
||||
class PermissionVarAdmin(admin.ModelAdmin):
|
||||
"""
|
||||
Admin customisation for PermissionVar
|
||||
"""
|
||||
list_display = ('name', 'description',)
|
||||
|
||||
|
||||
@admin.register(Permission, site=admin_site)
|
||||
class PermissionAdmin(admin.ModelAdmin):
|
||||
"""
|
||||
|
@ -2928,7 +2928,7 @@
|
||||
"application"
|
||||
],
|
||||
"query": "{\"user\": [\"user\"]}",
|
||||
"type": "add",
|
||||
"type": "create",
|
||||
"mask": 1,
|
||||
"field": "",
|
||||
"permanent": true,
|
||||
@ -3114,10 +3114,10 @@
|
||||
187,
|
||||
188,
|
||||
189,
|
||||
190,
|
||||
191,
|
||||
195,
|
||||
196
|
||||
190,
|
||||
191,
|
||||
195,
|
||||
196
|
||||
]
|
||||
}
|
||||
},
|
||||
@ -3159,8 +3159,8 @@
|
||||
159,
|
||||
160,
|
||||
179,
|
||||
189,
|
||||
190
|
||||
189,
|
||||
190
|
||||
]
|
||||
}
|
||||
},
|
||||
@ -3310,10 +3310,10 @@
|
||||
176,
|
||||
177,
|
||||
178,
|
||||
188,
|
||||
188,
|
||||
183,
|
||||
186,
|
||||
187
|
||||
186,
|
||||
187
|
||||
]
|
||||
}
|
||||
},
|
||||
@ -3508,13 +3508,13 @@
|
||||
187,
|
||||
188,
|
||||
189,
|
||||
190,
|
||||
191,
|
||||
192,
|
||||
193,
|
||||
194,
|
||||
195,
|
||||
196
|
||||
190,
|
||||
191,
|
||||
192,
|
||||
193,
|
||||
194,
|
||||
195,
|
||||
196
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -1,22 +0,0 @@
|
||||
# Generated by Django 2.2.28 on 2022-10-10 17:37
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('permission', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='PermissionVar',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.SlugField(unique=True, verbose_name='name')),
|
||||
('query', models.TextField(verbose_name='query')),
|
||||
('description', models.CharField(blank=True, max_length=255, verbose_name='description')),
|
||||
],
|
||||
),
|
||||
]
|
@ -118,25 +118,6 @@ class PermissionMask(models.Model):
|
||||
verbose_name_plural = _("permission masks")
|
||||
|
||||
|
||||
class PermissionVar(models.Model):
|
||||
|
||||
name = models.SlugField(
|
||||
unique=True,
|
||||
blank=False,
|
||||
verbose_name=_("name"),
|
||||
)
|
||||
|
||||
query = models.TextField(
|
||||
verbose_name=_("query"),
|
||||
)
|
||||
|
||||
description = models.CharField(
|
||||
max_length=255,
|
||||
blank=True,
|
||||
verbose_name=_("description"),
|
||||
)
|
||||
|
||||
|
||||
class Permission(models.Model):
|
||||
|
||||
PERMISSION_TYPES = [
|
||||
@ -158,7 +139,6 @@ class Permission(models.Model):
|
||||
# query -> ["AND", query, …] AND multiple queries
|
||||
# | ["OR", query, …] OR multiple queries
|
||||
# | ["NOT", query] Opposite of query
|
||||
# | ["VAR", query] A var name as defined in PermissionVar
|
||||
# query -> {key: value, …} A list of fields and values of a Q object
|
||||
# key -> string A field name
|
||||
# value -> int | string | bool | null Literal values
|
||||
@ -170,7 +150,6 @@ class Permission(models.Model):
|
||||
# | ["MUL", oper, …] Multiply F objects or literals
|
||||
# | int | string | bool | null Literal values
|
||||
# | ["F", string] A field
|
||||
# | ["VAR", string] A var name as defined in PermissionVar
|
||||
#
|
||||
# Examples:
|
||||
# Q(is_superuser=True) := {"is_superuser": true}
|
||||
@ -236,8 +215,6 @@ class Permission(models.Model):
|
||||
return functools.reduce(operator.mul, [Permission.compute_f(oper, **kwargs) for oper in oper[1:]])
|
||||
elif oper[0] == 'F':
|
||||
return F(oper[1])
|
||||
elif oper[0] == 'VAR':
|
||||
return compute_f(json.loads(PermissionVar.objects.get(name=oper[1]).query), **kwargs)
|
||||
else:
|
||||
field = kwargs[oper[0]]
|
||||
for i in range(1, len(oper)):
|
||||
@ -312,8 +289,6 @@ class Permission(models.Model):
|
||||
return functools.reduce(operator.or_, [Permission._about(query, **kwargs) for query in query[1:]])
|
||||
elif query[0] == 'NOT':
|
||||
return ~Permission._about(query[1], **kwargs)
|
||||
elif query[0] == 'VAR':
|
||||
return Permission._about(json.loads(PermissionVar.objects.get(name=query[1]).query), **kwargs)
|
||||
else:
|
||||
return Q(pk=F("pk")) if Permission.compute_param(query, **kwargs) else ~Q(pk=F("pk"))
|
||||
elif isinstance(query, dict):
|
||||
|
34
shell-static.nix
Executable file
34
shell-static.nix
Executable file
@ -0,0 +1,34 @@
|
||||
# This is a workaround meant for use with the nix package manager. If you don't know what it is or don't use it, please ignore this file.
|
||||
#
|
||||
# The nk20 javascript static location are hardcoded for imperative system.
|
||||
# This make ./manage.py collectstatic hard to use with nixos.
|
||||
#
|
||||
# A workaround is to enter a FHSUserEnv with the static placed under /share/javascript/<static>.
|
||||
# This emulate a debian like system and enable collecting static normally with ./manage.py collectstatics.
|
||||
# The regular shell.nix should be enough for other configurations.
|
||||
#
|
||||
# Warning, you are still supposed to use pip package with a venv !
|
||||
{ pkgs ? import <nixpkgs> {} }:
|
||||
(pkgs.buildFHSUserEnv {
|
||||
name = "pipzone";
|
||||
targetPkgs = pkgs: (with pkgs;
|
||||
let
|
||||
fhs-static = stdenv.mkDerivation {
|
||||
name = "fhs-static";
|
||||
buildCommand = ''
|
||||
mkdir -p $out/share/javascript/bootstrap4
|
||||
mkdir -p $out/share/javascript/jquery
|
||||
ln -s ${python39Packages.xstatic-bootstrap}/lib/python3.9/site-packages/xstatic/pkg/bootstrap/data/* $out/share/javascript/bootstrap4
|
||||
ln -s ${python39Packages.xstatic-jquery}/lib/python3.9/site-packages/xstatic/pkg/jquery/data/* $out/share/javascript/jquery
|
||||
'';
|
||||
};
|
||||
in [
|
||||
fhs-static
|
||||
python39
|
||||
gettext
|
||||
python39Packages.pip
|
||||
python39Packages.virtualenv
|
||||
python39Packages.setuptools
|
||||
]);
|
||||
runScript = "bash";
|
||||
}).env
|
23
shell.nix
Executable file
23
shell.nix
Executable file
@ -0,0 +1,23 @@
|
||||
# This is meant for use with the nix package manager. If you don't know what it is or don't use it, please ignore this file.
|
||||
#
|
||||
# This shell.nix contains all dependencies require to create a venv and pip install -r requirements.txt.
|
||||
#
|
||||
# Please check shell-static.nix for running ./manage.py collectstatics.
|
||||
{ pkgs ? import <nixpkgs> {} }:
|
||||
pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
python39
|
||||
python39Packages.pip
|
||||
python39Packages.setuptools
|
||||
gettext
|
||||
|
||||
];
|
||||
shellHook = ''
|
||||
# Tells pip to put packages into $PIP_PREFIX instead of the usual locations.
|
||||
# See https://pip.pypa.io/en/stable/user_guide/#environment-variables.
|
||||
export PIP_PREFIX=$(pwd)/_build/pip_packages
|
||||
export PYTHONPATH="$PIP_PREFIX/${pkgs.python39.sitePackages}:$PYTHONPATH"
|
||||
export PATH="$PIP_PREFIX/bin:$PATH"
|
||||
unset SOURCE_DATE_EPOCH
|
||||
'';
|
||||
}
|
Reference in New Issue
Block a user