Skip to content

Commit

Permalink
Add support for webfinger
Browse files Browse the repository at this point in the history
Add pytest run doctests
Edit Actor model , Edit create_git_repo and view function
  • Loading branch information
ziadhany committed Jun 29, 2023
1 parent 9dc965b commit 49d8c5f
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 149 deletions.
1 change: 1 addition & 0 deletions purl_sync/purl_sync/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,4 @@

MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
GIT_PATH = os.path.join(MEDIA_ROOT, "git")
11 changes: 7 additions & 4 deletions purl_sync/purl_sync/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,27 @@
from django.contrib import admin
from django.urls import path

from review.views import database_admin_profile_view, login_view, security_team_signup_view, create_git_repo_view
from review.views import CreatGitView
from review.views import WebfingerView
from review.views import database_admin_profile_view
from review.views import login_view
from review.views import security_team_profile_view
from review.views import review_page_view
from review.views import security_team_signup_view

urlpatterns = [
path("admin/", admin.site.urls),
path(".well-known/webfinger", WebfingerView.as_view()),
path("security-team/@<str:username>", security_team_profile_view),
path("database-admin/@<str:username>", database_admin_profile_view),
path("login/", login_view),
path("signup/", security_team_signup_view),
path("create-repo/", create_git_repo_view),
# path("create-repo/", CreatGitView.as_view()),
# path("review/<id>/", review_page_view),
# path("security-team/@<str:username>/edit-followers/", database_admin_profile_view),
# path("<str:username>/inbox/", ),
# path("<str:username>/outbox/", ),
# path("<str:username>/followers/", ),
# path("<str:username>/following/", ),
# path(f".well-known/webfinger?resource=acct:<username>@{DOMAIN}", ),
]

if settings.DEBUG:
Expand Down
2 changes: 1 addition & 1 deletion purl_sync/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DJANGO_SETTINGS_MODULE = "purl_sync.settings"
python_files = "*.py"
python_classes = "Test"
python_functions = "test"

addopts = "--doctest-modules"

[tool.black]
line-length = 100
Expand Down
Empty file added purl_sync/review/activitypub.py
Empty file.
6 changes: 6 additions & 0 deletions purl_sync/review/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django import forms


class CreateRepoForm(forms.Form):
repo_name = forms.CharField()
repo_url = forms.URLField(required=True)
113 changes: 60 additions & 53 deletions purl_sync/review/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
# Generated by Django 4.2.2 on 2023-06-26 13:44
# Generated by Django 4.2.2 on 2023-06-29 08:43

from django.conf import settings
import django.contrib.auth.models
from django.db import migrations, models
import django.db.models.deletion
import uuid

import django.db.models.deletion
from django.conf import settings
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

initial = True

dependencies = [
("auth", "0012_alter_user_first_name_max_length"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name="DatabaseAdmin",
fields=[
(
"user_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to=settings.AUTH_USER_MODEL,
"id",
models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
(
Expand All @@ -40,16 +36,24 @@ class Migration(migrations.Migration):
),
("note", models.CharField(help_text="the profile description", max_length=100)),
("public_key", models.TextField()),
("followers", models.JSONField(default=dict)),
(
"followers",
models.JSONField(
default=dict,
help_text="e.g. {'secrityteam@vcio': ['pkg:npm/[email protected]']}",
),
),
("followers_count", models.PositiveIntegerField(default=0)),
(
"user",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
),
),
],
options={
"abstract": False,
},
bases=("auth.user",),
managers=[
("objects", django.contrib.auth.models.UserManager()),
],
),
migrations.CreateModel(
name="GitRepo",
Expand Down Expand Up @@ -108,23 +112,38 @@ class Migration(migrations.Migration):
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
("voter_acct", models.CharField(help_text="security@vcio", max_length=100)),
("gainer_acct", models.CharField(help_text="security@nexb", max_length=100)),
("voter_acct", models.CharField(help_text="security@vcio.com", max_length=100)),
("gainer_acct", models.CharField(help_text="security@nexb.com", max_length=100)),
("positive", models.BooleanField(default=True)),
],
),
migrations.CreateModel(
name="Vulnerability",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4, editable=False, primary_key=True, serialize=False
),
),
("branch_name", models.CharField(max_length=28)),
("filename", models.CharField(max_length=255)),
("commit_id", models.CharField(max_length=50)),
(
"git_repo",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="review.gitrepo"
),
),
],
),
migrations.CreateModel(
name="SecurityTeam",
fields=[
(
"user_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to=settings.AUTH_USER_MODEL,
"id",
models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
(
Expand All @@ -137,36 +156,23 @@ class Migration(migrations.Migration):
),
("note", models.CharField(help_text="the profile description", max_length=100)),
("public_key", models.TextField()),
("following", models.JSONField(default=dict)),
("following_count", models.PositiveIntegerField(default=0)),
],
options={
"abstract": False,
},
bases=("auth.user",),
managers=[
("objects", django.contrib.auth.models.UserManager()),
],
),
migrations.CreateModel(
name="Vulnerability",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4, editable=False, primary_key=True, serialize=False
"following",
models.JSONField(
default=dict, help_text="e.g. {'datebase1@vcio': ['pkg:npm/[email protected]']}"
),
),
("branch_name", models.CharField(max_length=28)),
("filename", models.CharField(max_length=255)),
("commit_id", models.CharField(max_length=50)),
("following_count", models.PositiveIntegerField(default=0)),
(
"git_repo",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="review.gitrepo"
"user",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
),
),
],
options={
"abstract": False,
},
),
migrations.CreateModel(
name="Review",
Expand All @@ -177,6 +183,7 @@ class Migration(migrations.Migration):
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
("headline", models.CharField(max_length=300)),
("data", models.TextField()),
(
"status",
Expand All @@ -185,7 +192,7 @@ class Migration(migrations.Migration):
),
),
(
"author",
"creator",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="review.securityteam"
),
Expand Down
28 changes: 19 additions & 9 deletions purl_sync/review/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
from purl_sync.settings import DOMAIN


class Actor(User):
avatar = models.ImageField(upload_to="uploads/", help_text="the profile image", default="favicon-16x16.png")
class Actor(models.Model):
avatar = models.ImageField(
upload_to="uploads/", help_text="the profile image", default="favicon-16x16.png"
)
note = models.CharField(help_text="the profile description", max_length=100)
public_key = models.TextField(blank=False)
REQUIRED_FIELDS = ["username", "email", "password"]

@property
def acct(self):
"""The Webfinger account URI"""
return f"{self.username}@{DOMAIN}"
return f"{self.user.username}@{DOMAIN}"

@property
def reputation_value(self):
Expand All @@ -34,7 +35,10 @@ class Reputation(models.Model):


class DatabaseAdmin(Actor):
followers = models.JSONField(default=dict, help_text="e.g. {'secrityteam@vcio': ['pkg:npm/[email protected]']}")
user = models.OneToOneField(User, on_delete=models.CASCADE)
followers = models.JSONField(
default=dict, help_text="e.g. {'secrityteam@vcio': ['pkg:npm/[email protected]']}"
)
followers_count = models.PositiveIntegerField(default=0)

def save(self, *args, **kwargs):
Expand Down Expand Up @@ -64,7 +68,10 @@ class PackageUrl(models.Model):


class SecurityTeam(Actor):
following = models.JSONField(default=dict, help_text="e.g. {'datebase1@vcio': ['pkg:npm/[email protected]']}")
user = models.OneToOneField(User, on_delete=models.CASCADE)
following = models.JSONField(
default=dict, help_text="e.g. {'datebase1@vcio': ['pkg:npm/[email protected]']}"
)
following_count = models.PositiveIntegerField(default=0)

def save(self, *args, **kwargs):
Expand All @@ -81,8 +88,11 @@ class Notes(models.Model):


class Review(models.Model):
author = models.ForeignKey(SecurityTeam, on_delete=models.CASCADE, help_text="")
headline = models.CharField(max_length=300)
creator = models.ForeignKey(SecurityTeam, on_delete=models.CASCADE, help_text="")

git_repo = models.ForeignKey(GitRepo, on_delete=models.CASCADE, help_text="")

data = models.TextField()
notes = models.ManyToManyField(Notes)

Expand All @@ -107,7 +117,7 @@ class Meta:

class RemoteSecurityTeam(RemoteActor):
@property
def get_data(self):
def get_profile_data(self):
raise NotImplementedError

@property
Expand All @@ -117,7 +127,7 @@ def create_activity(self):

class RemoteDatabaseAdmin(RemoteActor):
@property
def get_data(self):
def get_profile_data(self):
raise NotImplementedError

@property
Expand Down
15 changes: 15 additions & 0 deletions purl_sync/review/templates/webfinger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"subject": "{{ resource }}",
"links": [
{
"rel": "https://webfinger.net/rel/profile-page",
"type": "text/html",
"href": "https://{{ domain }}/{{ user_type }}/@{{ username }}"
},
{
"rel": "self",
"type": "application/activity+json",
"href": "https://{{ domain }}/users/{{ user_type }}/{{ username }}"
}
]
}
Loading

0 comments on commit 49d8c5f

Please sign in to comment.