mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-19 05:25:42 +00:00
reformat comments 1
This commit is contained in:
@ -14,9 +14,7 @@ User = get_user_model()
|
||||
|
||||
|
||||
class RuleSetInline(admin.TabularInline):
|
||||
"""
|
||||
Class for displaying inline RuleSet data in the Group admin page.
|
||||
"""
|
||||
"""Class for displaying inline RuleSet data in the Group admin page."""
|
||||
|
||||
model = RuleSet
|
||||
can_delete = False
|
||||
@ -76,9 +74,7 @@ class InvenTreeGroupAdminForm(forms.ModelForm):
|
||||
|
||||
|
||||
class RoleGroupAdmin(admin.ModelAdmin): # pragma: no cover
|
||||
"""
|
||||
Custom admin interface for the Group model
|
||||
"""
|
||||
"""Custom admin interface for the Group model"""
|
||||
|
||||
form = InvenTreeGroupAdminForm
|
||||
|
||||
@ -213,9 +209,7 @@ class InvenTreeUserAdmin(UserAdmin):
|
||||
|
||||
|
||||
class OwnerAdmin(admin.ModelAdmin):
|
||||
"""
|
||||
Custom admin interface for the Owner model
|
||||
"""
|
||||
"""Custom admin interface for the Owner model"""
|
||||
pass
|
||||
|
||||
|
||||
|
@ -14,9 +14,7 @@ from users.serializers import OwnerSerializer, UserSerializer
|
||||
|
||||
|
||||
class OwnerList(generics.ListAPIView):
|
||||
"""
|
||||
List API endpoint for Owner model. Cannot create.
|
||||
"""
|
||||
"""List API endpoint for Owner model. Cannot create."""
|
||||
|
||||
queryset = Owner.objects.all()
|
||||
serializer_class = OwnerSerializer
|
||||
@ -54,9 +52,7 @@ class OwnerList(generics.ListAPIView):
|
||||
|
||||
|
||||
class OwnerDetail(generics.RetrieveAPIView):
|
||||
"""
|
||||
Detail API endpoint for Owner model. Cannot edit or delete
|
||||
"""
|
||||
"""Detail API endpoint for Owner model. Cannot edit or delete"""
|
||||
|
||||
queryset = Owner.objects.all()
|
||||
serializer_class = OwnerSerializer
|
||||
@ -108,7 +104,7 @@ class RoleDetails(APIView):
|
||||
|
||||
|
||||
class UserDetail(generics.RetrieveAPIView):
|
||||
""" Detail endpoint for a single user """
|
||||
"""Detail endpoint for a single user"""
|
||||
|
||||
queryset = User.objects.all()
|
||||
serializer_class = UserSerializer
|
||||
@ -116,7 +112,7 @@ class UserDetail(generics.RetrieveAPIView):
|
||||
|
||||
|
||||
class UserList(generics.ListAPIView):
|
||||
""" List endpoint for detail on all users """
|
||||
"""List endpoint for detail on all users"""
|
||||
|
||||
queryset = User.objects.all()
|
||||
serializer_class = UserSerializer
|
||||
@ -135,7 +131,7 @@ class UserList(generics.ListAPIView):
|
||||
|
||||
|
||||
class GetAuthToken(APIView):
|
||||
""" Return authentication token for an authenticated user. """
|
||||
"""Return authentication token for an authenticated user."""
|
||||
|
||||
permission_classes = [
|
||||
permissions.IsAuthenticated,
|
||||
|
@ -221,9 +221,7 @@ class RuleSet(models.Model):
|
||||
|
||||
@classmethod
|
||||
def check_table_permission(cls, user, table, permission):
|
||||
"""
|
||||
Check if the provided user has the specified permission against the table
|
||||
"""
|
||||
"""Check if the provided user has the specified permission against the table"""
|
||||
|
||||
# If the table does *not* require permissions
|
||||
if table in cls.RULESET_IGNORE:
|
||||
@ -269,7 +267,7 @@ class RuleSet(models.Model):
|
||||
)
|
||||
|
||||
def __str__(self, debug=False): # pragma: no cover
|
||||
""" Ruleset string representation """
|
||||
"""Ruleset string representation"""
|
||||
if debug:
|
||||
# Makes debugging easier
|
||||
return f'{str(self.group).ljust(15)}: {self.name.title().ljust(15)} | ' \
|
||||
@ -296,15 +294,13 @@ class RuleSet(models.Model):
|
||||
self.group.save()
|
||||
|
||||
def get_models(self):
|
||||
"""
|
||||
Return the database tables / models that this ruleset covers.
|
||||
"""
|
||||
"""Return the database tables / models that this ruleset covers."""
|
||||
|
||||
return self.RULESET_MODELS.get(self.name, [])
|
||||
|
||||
|
||||
def split_model(model):
|
||||
"""get modelname and app from modelstring"""
|
||||
"""Get modelname and app from modelstring"""
|
||||
*app, model = model.split('_')
|
||||
|
||||
# handle models that have
|
||||
@ -317,7 +313,7 @@ def split_model(model):
|
||||
|
||||
|
||||
def split_permission(app, perm):
|
||||
"""split permission string into permission and model"""
|
||||
"""Split permission string into permission and model"""
|
||||
permission_name, *model = perm.split('_')
|
||||
# handle models that have underscores
|
||||
if len(model) > 1: # pragma: no cover
|
||||
@ -329,7 +325,6 @@ def split_permission(app, perm):
|
||||
|
||||
def update_group_roles(group, debug=False):
|
||||
"""
|
||||
|
||||
Iterates through all of the RuleSets associated with the group,
|
||||
and ensures that the correct permissions are either applied or removed from the group.
|
||||
|
||||
@ -339,7 +334,6 @@ def update_group_roles(group, debug=False):
|
||||
b) Whenver the group object is updated
|
||||
|
||||
The RuleSet model has complete control over the permissions applied to any group.
|
||||
|
||||
"""
|
||||
|
||||
if not canAppAccessDatabase(allow_test=True):
|
||||
@ -594,24 +588,20 @@ class Owner(models.Model):
|
||||
owner = GenericForeignKey('owner_type', 'owner_id')
|
||||
|
||||
def __str__(self):
|
||||
""" Defines the owner string representation """
|
||||
"""Defines the owner string representation"""
|
||||
return f'{self.owner} ({self.owner_type.name})'
|
||||
|
||||
def name(self):
|
||||
"""
|
||||
Return the 'name' of this owner
|
||||
"""
|
||||
"""Return the 'name' of this owner"""
|
||||
return str(self.owner)
|
||||
|
||||
def label(self):
|
||||
"""
|
||||
Return the 'type' label of this owner i.e. 'user' or 'group'
|
||||
"""
|
||||
"""Return the 'type' label of this owner i.e. 'user' or 'group'"""
|
||||
return str(self.owner_type.name)
|
||||
|
||||
@classmethod
|
||||
def create(cls, obj):
|
||||
""" Check if owner exist then create new owner entry """
|
||||
"""Check if owner exist then create new owner entry"""
|
||||
|
||||
# Check for existing owner
|
||||
existing_owner = cls.get_owner(obj)
|
||||
@ -627,7 +617,7 @@ class Owner(models.Model):
|
||||
|
||||
@classmethod
|
||||
def get_owner(cls, user_or_group):
|
||||
""" Get owner instance for a group or user """
|
||||
"""Get owner instance for a group or user"""
|
||||
|
||||
user_model = get_user_model()
|
||||
owner = None
|
||||
|
@ -10,8 +10,7 @@ from .models import Owner
|
||||
|
||||
|
||||
class UserSerializer(InvenTreeModelSerializer):
|
||||
""" Serializer for a User
|
||||
"""
|
||||
"""Serializer for a User"""
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
@ -23,9 +22,7 @@ class UserSerializer(InvenTreeModelSerializer):
|
||||
|
||||
|
||||
class OwnerSerializer(InvenTreeModelSerializer):
|
||||
"""
|
||||
Serializer for an "Owner" (either a "user" or a "group")
|
||||
"""
|
||||
"""Serializer for an "Owner" (either a "user" or a "group")"""
|
||||
|
||||
name = serializers.CharField(read_only=True)
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
"""
|
||||
Unit tests for the user model database migrations
|
||||
"""
|
||||
"""Unit tests for the user model database migrations"""
|
||||
|
||||
from django_test_migrations.contrib.unittest_case import MigratorTestCase
|
||||
|
||||
@ -8,9 +6,7 @@ from InvenTree import helpers
|
||||
|
||||
|
||||
class TestForwardMigrations(MigratorTestCase):
|
||||
"""
|
||||
Test entire schema migration sequence for the users app
|
||||
"""
|
||||
"""Test entire schema migration sequence for the users app"""
|
||||
|
||||
migrate_from = ('users', helpers.getOldestMigrationFile('users'))
|
||||
migrate_to = ('users', helpers.getNewestMigrationFile('users'))
|
||||
|
@ -10,9 +10,7 @@ from users.models import Owner, RuleSet
|
||||
|
||||
|
||||
class RuleSetModelTest(TestCase):
|
||||
"""
|
||||
Some simplistic tests to ensure the RuleSet model is setup correctly.
|
||||
"""
|
||||
"""Some simplistic tests to ensure the RuleSet model is setup correctly."""
|
||||
|
||||
def test_ruleset_models(self):
|
||||
|
||||
@ -48,10 +46,7 @@ class RuleSetModelTest(TestCase):
|
||||
self.assertEqual(len(empty), 0)
|
||||
|
||||
def test_model_names(self):
|
||||
"""
|
||||
Test that each model defined in the rulesets is valid,
|
||||
based on the database schema!
|
||||
"""
|
||||
"""Test that each model defined in the rulesets is valid, based on the database schema!"""
|
||||
|
||||
available_models = apps.get_models()
|
||||
|
||||
@ -108,9 +103,7 @@ class RuleSetModelTest(TestCase):
|
||||
self.assertEqual(len(extra_models), 0)
|
||||
|
||||
def test_permission_assign(self):
|
||||
"""
|
||||
Test that the permission assigning works!
|
||||
"""
|
||||
"""Test that the permission assigning works!"""
|
||||
|
||||
# Create a new group
|
||||
group = Group.objects.create(name="Test group")
|
||||
@ -161,9 +154,7 @@ class RuleSetModelTest(TestCase):
|
||||
|
||||
|
||||
class OwnerModelTest(InvenTreeTestCase):
|
||||
"""
|
||||
Some simplistic tests to ensure the Owner model is setup correctly.
|
||||
"""
|
||||
"""Some simplistic tests to ensure the Owner model is setup correctly."""
|
||||
|
||||
def do_request(self, endpoint, filters, status_code=200):
|
||||
response = self.client.get(endpoint, filters, format='json')
|
||||
@ -212,9 +203,7 @@ class OwnerModelTest(InvenTreeTestCase):
|
||||
self.assertEqual(group_as_owner, None)
|
||||
|
||||
def test_api(self):
|
||||
"""
|
||||
Test user APIs
|
||||
"""
|
||||
"""Test user APIs"""
|
||||
self.client.logout()
|
||||
|
||||
# not authed
|
||||
@ -231,9 +220,7 @@ class OwnerModelTest(InvenTreeTestCase):
|
||||
# self.do_request(reverse('api-owner-detail', kwargs={'pk': self.user.id}), {})
|
||||
|
||||
def test_token(self):
|
||||
"""
|
||||
Test token mechanisms
|
||||
"""
|
||||
"""Test token mechanisms"""
|
||||
self.client.logout()
|
||||
|
||||
token = Token.objects.filter(user=self.user)
|
||||
|
Reference in New Issue
Block a user