Skip to content

Commit

Permalink
Use BigInt for permissions field and remove max value validator
Browse files Browse the repository at this point in the history
BigInt is needed as Discord's permissions number now exceeds that which can be stored
in a normal int. I have removed the max value validator, as this just adds
maintanence burden for us each time Discord adds new permissions.
  • Loading branch information
ChrisLovering committed Jun 18, 2021
1 parent 297337f commit c40ed8c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
19 changes: 19 additions & 0 deletions pydis_site/apps/api/migrations/0070_auto_20210618_2114.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.0.14 on 2021-06-18 21:14

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0069_documentationlink_validators'),
]

operations = [
migrations.AlterField(
model_name='role',
name='permissions',
field=models.BigIntegerField(help_text='The integer value of the permission bitset of this role from Discord.', validators=[django.core.validators.MinValueValidator(limit_value=0, message='Role permissions cannot be negative.')]),
),
]
8 changes: 2 additions & 6 deletions pydis_site/apps/api/models/bot/role.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from django.core.validators import MaxValueValidator, MinValueValidator
from django.core.validators import MinValueValidator
from django.db import models

from pydis_site.apps.api.models.mixins import ModelReprMixin
Expand Down Expand Up @@ -38,16 +38,12 @@ class Role(ModelReprMixin, models.Model):
),
help_text="The integer value of the colour of this role from Discord."
)
permissions = models.IntegerField(
permissions = models.BigIntegerField(
validators=(
MinValueValidator(
limit_value=0,
message="Role permissions cannot be negative."
),
MaxValueValidator(
limit_value=2 << 32,
message="Role permission bitset exceeds value of having all permissions"
)
),
help_text="The integer value of the permission bitset of this role from Discord."
)
Expand Down

0 comments on commit c40ed8c

Please sign in to comment.