Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ead354e
Remove avatar upload for user
keshav-space Dec 30, 2024
d677ec3
Use fontawesome for icons
keshav-space Dec 30, 2024
badc6fc
Improve custom css
keshav-space Dec 30, 2024
9dc1e94
Ensure the footer stays at the bottom
keshav-space Dec 30, 2024
e00c7ea
Add JavaScript to manage notifications
keshav-space Dec 30, 2024
4d21e78
Improve user login workflow
keshav-space Dec 31, 2024
452c952
Refactor app navbar
keshav-space Dec 31, 2024
ff10775
Improve user signup workflow
keshav-space Dec 31, 2024
59c8c0b
Refactor package followers column
keshav-space Dec 31, 2024
31f567f
Add instruction for profile picture in user profile
keshav-space Dec 31, 2024
de5a4b8
Move JavaScript to the end of the body
keshav-space Dec 31, 2024
f35d004
Ensure only logged-in user can see their profile
keshav-space Dec 31, 2024
2aedfeb
Add templates and views to handle 403 and 404 responses
keshav-space Dec 31, 2024
8607465
Refactor notes view
keshav-space Dec 31, 2024
8543dcb
Update text fixture
keshav-space Dec 31, 2024
b4da07b
Prevent login page for logged-in users
keshav-space Jan 1, 2025
b867180
Highlight active navbar items
keshav-space Jan 1, 2025
1e32797
Enable datetime localization for client
keshav-space Jan 1, 2025
18309aa
Remove unhelpful title from comment form
keshav-space Jan 3, 2025
83d5dae
Use pagination to show package events
keshav-space Jan 3, 2025
c7ed8c6
Refactor package search and discover page
keshav-space Jan 3, 2025
de902df
Refactor repository list view
keshav-space Jan 3, 2025
e14982e
Refactor create git repository view
keshav-space Jan 3, 2025
1018fe7
Add navbar item for repo management
keshav-space Jan 3, 2025
3325bcb
Use safe_url with trailing slash in urljoin
keshav-space Jan 6, 2025
35a4ab5
Use regular font for package activity content
keshav-space Jan 6, 2025
7a7e4c0
Add dockerignore file
keshav-space Jan 6, 2025
188bce2
Use compact table for followed packages
keshav-space Jan 6, 2025
6ec0335
Move profile image instructions to a modal popup
keshav-space Jan 6, 2025
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
120 changes: 120 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg


# Installer logs
pip-log.txt
pip-delete-this-directory.txt
pip-selfcheck.json

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
coverage.xml
*.cover

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Sphinx
docs/_build
docs/bin
docs/build
docs/include
docs/Lib
doc/pyvenv.cfg
pyvenv.cfg

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv and pip
.python-version
pyvenv.cfg
bin/

# Environments
.venv
env/
venv/
ENV/


# mypy
.mypy_cache/


# Database
*.sqlite3*

# Staticfiles
staticfiles/

# virtualenv
bin
include
lib64
share
Pipfile

# editors
.vscode
# PyCharm
.idea/

# pytest
.pytest_cache


# Various junk and temp files
.DS_Store
*~
.*.sw[po]
.build
.ve
*.bak
/.cache/
/tmp/

# pyenv
/.python-version
/man/
/.pytest_cache/
lib64
tcl

# Ignore Jupyter Notebook related temp files
.ipynb_checkpoints/
20 changes: 9 additions & 11 deletions fedcode/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ class CreateGitRepoForm(forms.ModelForm):
class Meta:
model = Repository
fields = ["url"]
help_texts = {
"url": None,
}

def __init__(self, *args, **kwargs):
super(CreateGitRepoForm, self).__init__(*args, **kwargs)
self.fields["url"].widget.attrs.update(
{"class": "input mb-5", "placeholder": "https://github.com/nexB/vulnerablecode-data"}
{"class": "input", "placeholder": "https://github.com/nexB/vulnerablecode-data"}
)
self.fields["url"].help_text = ""
self.fields["url"].label = ""


class CreateNoteForm(forms.ModelForm):
Expand All @@ -39,9 +38,10 @@ class Meta:
def __init__(self, *args, **kwargs):
super(CreateNoteForm, self).__init__(*args, **kwargs)
self.fields["content"].widget.attrs.update(
{"class": "textarea", "placeholder": "Add a note...", "rows": 5}
{"class": "textarea", "placeholder": "Comment...", "rows": 5}
)
self.fields["content"].label = ""
self.fields["content"].help_text = ""


class ReviewStatusForm(forms.ModelForm):
Expand Down Expand Up @@ -109,9 +109,8 @@ class SearchPackageForm(forms.Form):
label=False,
widget=forms.TextInput(
attrs={
"placeholder": "Please enter a valid purl ex: pkg:maven/org.apache.commons/io",
"class": "input is-rounded",
"style": "width: 90%;",
"placeholder": "Search a package...",
"class": "input ",
},
),
)
Expand All @@ -137,9 +136,8 @@ class SearchRepositoryForm(forms.Form):
label=False,
widget=forms.TextInput(
attrs={
"placeholder": "Please Enter a Repository URL ex: https://github.com/nexB/vulnerablecode-data",
"class": "input is-rounded",
"style": "width: 90%;",
"placeholder": "Search a repository...",
"class": "input",
},
),
)
30 changes: 30 additions & 0 deletions fedcode/middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# FederatedCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/nexB/federatedcode for support or download.
# See https://aboutcode.org for more information about AboutCode.org OSS projects.
#

import zoneinfo

from django.utils import timezone


class TimezoneMiddleware:
def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
try:
# Activate local timezone for user using cookies
tzname = request.COOKIES.get("user_timezone")
if tzname:
timezone.activate(zoneinfo.ZoneInfo(tzname))
else:
timezone.deactivate()
except Exception as e:
timezone.deactivate()

return self.get_response(request)
17 changes: 17 additions & 0 deletions fedcode/migrations/0005_remove_person_avatar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.1.2 on 2024-12-27 17:48

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("fedcode", "0004_alter_vulnerability_unique_together"),
]

operations = [
migrations.RemoveField(
model_name="person",
name="avatar",
),
]
43 changes: 30 additions & 13 deletions fedcode/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class RemoteActor(models.Model):
help_text="A field to track when remote actor are updated",
)

@property
def safe_url(self):
return f"{self.url.rstrip('/')}/"


class Actor(models.Model):
"""
Expand Down Expand Up @@ -227,6 +231,11 @@ def reputation_value(self):
def absolute_url(self):
return full_reverse("note-page", self.id)

@property
def acct_avatar(self):
person = Person.objects.get(user__username=self.username)
return person.avatar

@property
def to_ap(self):
return {
Expand Down Expand Up @@ -290,6 +299,10 @@ def __str__(self):
def followers_count(self):
return Follow.objects.filter(package=self).count()

@property
def notes_count(self):
return Note.objects.filter(acct=self.acct).count()

@property
def followers(self):
return Follow.objects.filter(package=self).values("person_id")
Expand Down Expand Up @@ -350,16 +363,9 @@ def to_ap(self):

class Person(Actor):
"""
A person is a user can follow pacakge or just vote or create a notes
A person is a user can follow package or just vote or create a notes
"""

avatar = models.ImageField(
upload_to="uploads/",
help_text="",
default="favicon-16x16.png",
null=True,
)

user = models.OneToOneField(
User,
null=True,
Expand Down Expand Up @@ -391,13 +397,24 @@ class Meta:
),
]

@property
def avatar(self):
from hashlib import sha256

email = ""
if self.user and (email := self.user.email):
email = email.strip().lower()

gravatar = sha256(email.encode("utf-8")).hexdigest()
return f"https://gravatar.com/avatar/{gravatar}"

@property
def local(self):
return bool(self.user)

@property
def avatar_absolute_url(self):
return f'{"https://"}{FEDERATEDCODE_DOMAIN}{self.avatar.url}'
return self.avatar

# TODO raise error if the user doesn't have a user or remote actor
@property
Expand Down Expand Up @@ -425,13 +442,13 @@ def absolute_url_ap(self):
@property
def inbox_url(self):
if not self.local:
return urljoin(self.remote_actor.url, "inbox")
return urljoin(self.remote_actor.safe_url, "inbox")
return full_reverse("user-inbox", self.user.username)

@property
def outbox_url(self):
if not self.local:
return urljoin(self.remote_actor.url, "outbox")
return urljoin(self.remote_actor.safe_url, "outbox")
return full_reverse("user-outbox", self.user.username)

@property
Expand All @@ -443,7 +460,7 @@ def key_id(self):
if self.user:
return full_reverse("user-ap-profile", self.user.username) + "#main-key"
else:
return self.remote_actor.url + "#main-key"
return self.remote_actor.safe_url + "#main-key"

@property
def to_ap(self):
Expand Down Expand Up @@ -604,7 +621,7 @@ class Vulnerability(models.Model):
)

class Meta:
unique_together = ('id', 'repo')
unique_together = ("id", "repo")

@property
def absolute_url(self):
Expand Down
2 changes: 2 additions & 0 deletions fedcode/pipes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@


def create_note(pkg, note_dict):
# TODO: also take argument for source of the note ideally github blob for
# for file.
note, _ = Note.objects.get_or_create(acct=pkg.acct, content=saneyaml.dump(note_dict))
pkg.notes.add(note)
create_activity = CreateActivity(actor=pkg.to_ap, object=note.to_ap)
Expand Down
21 changes: 21 additions & 0 deletions fedcode/templates/403.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "base.html" %}

{% block title %}
Permission Denied
{% endblock %}

{% block content %}
<section class="hero is-large is-link">
<div class="hero-body">
<div class="container has-text-centered">
<h1 class="title is-1 pb-2">
Permission Denied
</h1>
<p class="subtitle is-4">
You do not have permission to access this page.
</p>
<a href="{% url 'purl-list' %}" class="button is-dark">Explore available packages</a>
</div>
</div>
</section>
{% endblock %}
21 changes: 21 additions & 0 deletions fedcode/templates/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "base.html" %}

{% block title %}
Page Not Found
{% endblock %}

{% block content %}
<section class="hero is-large is-link">
<div class="hero-body">
<div class="container has-text-centered">
<h1 class="title is-1 pb-2">
404 - Page Not Found
</h1>
<p class="subtitle is-4">
Sorry, the page you're looking for does not exist.
</p>
<a href="{% url 'purl-list' %}" class="button is-dark">Explore available packages</a>
</div>
</div>
</section>
{% endblock %}
Loading