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

Added admin support #51

Merged
merged 2 commits into from
Aug 9, 2023
Merged
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
16 changes: 11 additions & 5 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ exclude =
build
venv*
certego_django_apps/migrations
example_project
ignore =
F821 # undefined name 'Rule'
W503 # line break before binary operator
E402 # module level import not at top of file
W291 # trailing whitespace nightmare
E203 # whitespace before ':'
# undefined name 'Rule'
F821,
# line break before binary operator
W503,
# module level import not at top of file
E402,
# trailing whitespace nightmare
W291,
# whitespace before ':'
E203,
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/myint/autoflake
rev: v1.4
rev: v2.2.0
hooks:
- id: autoflake
args:
Expand All @@ -11,15 +11,15 @@ repos:
"-i",
]
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.7.0
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 4.0.1
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", "--filter-files", "--skip", "venv"]
Expand All @@ -30,4 +30,4 @@ repos:
# additional_dependencies:
# - django-stubs
# - djangorestframework-stubs
# args: [--no-strict-optional, --ignore-missing-imports]
# args: [--no-strict-optional, --ignore-missing-imports]
1 change: 0 additions & 1 deletion certego_saas/apps/feedback/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand Down
1 change: 0 additions & 1 deletion certego_saas/apps/notifications/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("certego_saas_notifications", "0001_initial"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class Migration(migrations.Migration):

dependencies = [
("certego_saas_notifications", "0002_alter_notification_appname"),
]
Expand Down
2 changes: 2 additions & 0 deletions certego_saas/apps/organization/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ class MembershipAdmin(admin.ModelAdmin):
"user",
"organization",
"is_owner",
"is_admin",
"created_at",
)

list_filter = (
"organization",
"is_owner",
"is_admin",
)


Expand Down
14 changes: 13 additions & 1 deletion certego_saas/apps/organization/membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,17 @@ class Meta:
on_delete=models.CASCADE,
)
is_owner = models.BooleanField(default=False)
is_admin = models.BooleanField(default=False)

# funcs
def clean_admin(self):
if self.is_owner and not self.is_admin:
# an owner must be an admin, permissions will be checked on this field
self.is_admin = True

def clean(self):
super().clean()
self.clean_admin()

def __str__(self):
member_str = "owner" if self.is_owner else "member"
Expand All @@ -48,4 +57,7 @@ class ExistingMembershipException(ValidationError):
)

class OwnerCantLeaveException(ValidationError):
default_detail = "Owner cannot leave the organization but can choose to delete the organization."
default_detail = (
"Owner cannot leave the organization"
"but can choose to delete the organization."
)
1 change: 0 additions & 1 deletion certego_saas/apps/organization/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("certego_saas_organization", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="membership",
name="is_admin",
field=models.BooleanField(default=False),
),
]
1 change: 0 additions & 1 deletion certego_saas/apps/payments/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand Down
1 change: 0 additions & 1 deletion certego_saas/apps/user/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

initial = True
replaces = [
("certego_saas", "0001_initial"),
Expand Down
1 change: 0 additions & 1 deletion certego_saas/ext/test_utilities/no_logs_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def assertNoLogs(
with self.assertLogs(logger=logger, level=level) as new_log:
yield
except AssertionError as e:

if isinstance(e.args[0], str) and not e.args[0].startswith(
"no logs of level"
):
Expand Down
1 change: 0 additions & 1 deletion certego_saas/ext/upload/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def __repr__(self):
from django.db.models import fields as django_fields

class BIDocument(__BIDocumentInterface, Model):

index = django_fields.CharField(max_length=100)
creation_date = django_fields.DateTimeField(auto_now_add=True)
category = django_fields.CharField(max_length=100)
Expand Down
2 changes: 0 additions & 2 deletions certego_saas/ext/upload/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ def send_message(


if settings.DEBUG or certego_apps_settings.TESTING:

Slack = _Slack

else:

class Slack(_Slack):

token = settings.SLACK_TOKEN

client = WebClient(token=token)
Expand Down
2 changes: 0 additions & 2 deletions certego_saas/ext/upload/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ def post_tweet(


if settings.DEBUG or certego_apps_settings.TESTING:

Twitter = _Twitter

else:

class Twitter(_Twitter):

CHARACTER_LIMIT = twitter_lib.api.CHARACTER_LIMIT
client = twitter_lib.Api(
consumer_key=certego_apps_settings.TWITTER_CONSUMER_KEY,
Expand Down