Skip to content

Commit

Permalink
feat: TP2000-1018 - expose report endpoints to tariff managers (#1029)
Browse files Browse the repository at this point in the history
  • Loading branch information
nboyse authored Sep 18, 2023
1 parent 791e7b6 commit d377aee
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
29 changes: 29 additions & 0 deletions reports/migrations/0001_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 3.2.20 on 2023-09-11 14:27

from django.db import migrations, models


class Migration(migrations.Migration):
initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="Report",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
],
options={
"db_table": "report",
},
),
]
30 changes: 30 additions & 0 deletions reports/migrations/0002_create_custom_permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.contrib.auth.models import Permission, Group
from django.contrib.contenttypes.models import ContentType
from reports.models import Report
from django.db import migrations


def create_custom_permissions(apps, schema_editor):
content_type = ContentType.objects.get_for_model(Report)

view_permission, _ = Permission.objects.get_or_create(
codename="view_report_index",
name="Can view report index",
content_type=content_type,
)

edit_permission, _ = Permission.objects.get_or_create(
codename="view_report",
name="Can view reports",
content_type=content_type,
)


class Migration(migrations.Migration):
dependencies = [
("reports", "0001_report"),
]

operations = [
migrations.RunPython(create_custom_permissions),
]
8 changes: 7 additions & 1 deletion reports/models.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# Create your models here.
from django.db import models


class Report(models.Model):
class Meta:
# Define the name for the database table (optional)
db_table = "report"
4 changes: 2 additions & 2 deletions reports/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import reports.utils as utils


@permission_required("app.view_report_index")
@permission_required("reports.view_report_index")
def index(request):
context = {
"report": index_model.IndexTable(),
Expand All @@ -16,7 +16,7 @@ def index(request):
return render(request, "reports/index.jinja", context)


@permission_required("app.view_report")
@permission_required("reports.view_report")
def report(request):
# find the report based on the request
report_class = utils.get_report_by_slug(request.resolver_match.url_name)
Expand Down

0 comments on commit d377aee

Please sign in to comment.