Revert "Merge pull request #239 from netbox-community/develop"
This reverts commit80f514fa90
, reversing changes made tob0b20aa6ba
.
This commit is contained in:
parent
197ad86009
commit
c429011697
8 changed files with 32 additions and 80 deletions
|
@ -20,23 +20,15 @@ with file.open('r') as stream:
|
|||
username = username,
|
||||
password = user_details.get('password', 0) or User.objects.make_random_password)
|
||||
|
||||
print("👤 Created user",username)
|
||||
print("👤 Created user ",username)
|
||||
|
||||
if user_details.get('api_token', 0):
|
||||
Token.objects.create(user=user, key=user_details['api_token'])
|
||||
|
||||
yaml_permissions = user_details.get('permissions', [])
|
||||
if yaml_permissions:
|
||||
subject = user.user_permissions
|
||||
subject.clear()
|
||||
for yaml_permission in yaml_permissions:
|
||||
if '*' in yaml_permission:
|
||||
permission_filter = '^' + yaml_permission.replace('*','.*') + '$'
|
||||
permissions = Permission.objects.filter(codename__iregex=permission_filter)
|
||||
print(" ⚿ Granting", permissions.count(), "permissions matching '" + yaml_permission + "'")
|
||||
else:
|
||||
permissions = Permission.objects.filter(codename=yaml_permission)
|
||||
print(" ⚿ Granting permission", yaml_permission)
|
||||
|
||||
for permission in permissions:
|
||||
subject.add(permission)
|
||||
user_permissions = user_details.get('permissions', [])
|
||||
if user_permissions:
|
||||
user.user_permissions.clear()
|
||||
for permission_codename in user_details.get('permissions', []):
|
||||
for permission in Permission.objects.filter(codename=permission_codename):
|
||||
user.user_permissions.add(permission)
|
||||
user.save()
|
||||
|
|
|
@ -24,18 +24,9 @@ with file.open('r') as stream:
|
|||
if user:
|
||||
user.groups.add(group)
|
||||
|
||||
yaml_permissions = group_details.get('permissions', [])
|
||||
if yaml_permissions:
|
||||
subject = group.permissions
|
||||
subject.clear()
|
||||
for yaml_permission in yaml_permissions:
|
||||
if '*' in yaml_permission:
|
||||
permission_filter = '^' + yaml_permission.replace('*','.*') + '$'
|
||||
permissions = Permission.objects.filter(codename__iregex=permission_filter)
|
||||
print(" ⚿ Granting", permissions.count(), "permissions matching '" + yaml_permission + "'")
|
||||
else:
|
||||
permissions = Permission.objects.filter(codename=yaml_permission)
|
||||
print(" ⚿ Granting permission", yaml_permission)
|
||||
|
||||
for permission in permissions:
|
||||
subject.add(permission)
|
||||
group_permissions = group_details.get('permissions', [])
|
||||
if group_permissions:
|
||||
group.permissions.clear()
|
||||
for permission_codename in group_details.get('permissions', []):
|
||||
for permission in Permission.objects.filter(codename=permission_codename):
|
||||
group.permissions.add(permission)
|
||||
|
|
|
@ -7,12 +7,12 @@ from os.path import dirname, abspath
|
|||
this_dir = dirname(abspath(__file__))
|
||||
|
||||
def filename(f):
|
||||
return f.name
|
||||
return f.name
|
||||
|
||||
with scandir(dirname(abspath(__file__))) as it:
|
||||
for f in sorted(it, key = filename):
|
||||
if f.name.startswith('__') or not f.is_file():
|
||||
continue
|
||||
|
||||
print(f"Running {f.path}")
|
||||
runpy.run_path(f.path)
|
||||
for f in sorted(it, key = filename):
|
||||
if f.name.startswith('__') or not f.is_file():
|
||||
continue
|
||||
|
||||
print(f"Running {f.path}")
|
||||
runpy.run_path(f.path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue