Skip to content

Commit

Permalink
Merge branch 'main' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
mouse-reeve committed Dec 11, 2022
2 parents ad75fd1 + c75bb1b commit 5833553
Show file tree
Hide file tree
Showing 89 changed files with 3,184 additions and 1,574 deletions.
9 changes: 8 additions & 1 deletion bookwyrm/activitypub/base_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ def serialize(self, **kwargs):
try:
if issubclass(type(v), ActivityObject):
data[k] = v.serialize()
elif isinstance(v, list):
data[k] = [
e.serialize() if issubclass(type(e), ActivityObject) else e
for e in v
]
except TypeError:
pass
data = {k: v for (k, v) in data.items() if v is not None and k not in omit}
Expand Down Expand Up @@ -306,7 +311,9 @@ class Link(ActivityObject):

def serialize(self, **kwargs):
"""remove fields"""
omit = ("id", "type", "@context")
omit = ("id", "@context")
if self.type == "Link":
omit += ("type",)
return super().serialize(omit=omit)


Expand Down
2 changes: 2 additions & 0 deletions bookwyrm/activitypub/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class BookData(ActivityObject):
viaf: str = None
wikidata: str = None
asin: str = None
aasin: str = None
isfdb: str = None
lastEditedBy: str = None
links: List[str] = field(default_factory=lambda: [])
fileLinks: List[str] = field(default_factory=lambda: [])
Expand Down
6 changes: 6 additions & 0 deletions bookwyrm/emailing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def email_data():
}


def test_email(user):
"""Just an admin checking if emails are sending"""
data = email_data()
send_email(user.email, *format_email("test", data))


def email_confirmation_email(user):
"""newly registered users confirm email address"""
data = email_data()
Expand Down
53 changes: 52 additions & 1 deletion bookwyrm/forms/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,45 @@ class Meta:
class SiteForm(CustomForm):
class Meta:
model = models.SiteSettings
exclude = ["admin_code", "install_mode", "imports_enabled"]
fields = [
"name",
"instance_tagline",
"instance_description",
"instance_short_description",
"default_theme",
"code_of_conduct",
"privacy_policy",
"impressum",
"show_impressum",
"logo",
"logo_small",
"favicon",
"support_link",
"support_title",
"admin_email",
"footer_item",
]
widgets = {
"instance_short_description": forms.TextInput(
attrs={"aria-describedby": "desc_instance_short_description"}
),
}


class RegistrationForm(CustomForm):
class Meta:
model = models.SiteSettings
fields = [
"allow_registration",
"allow_invite_requests",
"registration_closed_text",
"invite_request_text",
"invite_request_question",
"invite_question_text",
"require_confirm_email",
]

widgets = {
"require_confirm_email": forms.CheckboxInput(
attrs={"aria-describedby": "desc_require_confirm_email"}
),
Expand All @@ -69,6 +103,23 @@ class Meta:
}


class RegistrationLimitedForm(CustomForm):
class Meta:
model = models.SiteSettings
fields = [
"registration_closed_text",
"invite_request_text",
"invite_request_question",
"invite_question_text",
]

widgets = {
"invite_request_text": forms.Textarea(
attrs={"aria-describedby": "desc_invite_request_text"}
),
}


class ThemeForm(CustomForm):
class Meta:
model = models.Theme
Expand Down
1 change: 1 addition & 0 deletions bookwyrm/forms/author.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Meta:
"inventaire_id",
"librarything_key",
"goodreads_key",
"isfdb",
"isni",
]
widgets = {
Expand Down
42 changes: 29 additions & 13 deletions bookwyrm/forms/books.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,30 @@ class Meta:
class EditionForm(CustomForm):
class Meta:
model = models.Edition
exclude = [
"remote_id",
"origin_id",
"created_date",
"updated_date",
"edition_rank",
"authors",
"parent_work",
"shelves",
"connector",
"search_vector",
"links",
"file_links",
fields = [
"title",
"subtitle",
"description",
"series",
"series_number",
"languages",
"subjects",
"publishers",
"first_published_date",
"published_date",
"cover",
"physical_format",
"physical_format_detail",
"pages",
"isbn_13",
"isbn_10",
"openlibrary_key",
"inventaire_id",
"goodreads_key",
"oclc_number",
"asin",
"aasin",
"isfdb",
]
widgets = {
"title": forms.TextInput(attrs={"aria-describedby": "desc_title"}),
Expand Down Expand Up @@ -73,10 +84,15 @@ class Meta:
"inventaire_id": forms.TextInput(
attrs={"aria-describedby": "desc_inventaire_id"}
),
"goodreads_key": forms.TextInput(
attrs={"aria-describedby": "desc_goodreads_key"}
),
"oclc_number": forms.TextInput(
attrs={"aria-describedby": "desc_oclc_number"}
),
"ASIN": forms.TextInput(attrs={"aria-describedby": "desc_ASIN"}),
"AASIN": forms.TextInput(attrs={"aria-describedby": "desc_AASIN"}),
"isfdb": forms.TextInput(attrs={"aria-describedby": "desc_isfdb"}),
}


Expand Down
19 changes: 19 additions & 0 deletions bookwyrm/management/commands/confirm_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
""" manually confirm e-mail of user """
from django.core.management.base import BaseCommand

from bookwyrm import models


class Command(BaseCommand):
"""command-line options"""

help = "Manually confirm email for user"

def add_arguments(self, parser):
parser.add_argument("username")

def handle(self, *args, **options):
name = options["username"]
user = models.User.objects.get(localname=name)
user.reactivate()
self.stdout.write(self.style.SUCCESS("User's email is now confirmed."))
30 changes: 20 additions & 10 deletions bookwyrm/management/commands/initdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,64 @@

def init_groups():
"""permission levels"""
groups = ["admin", "moderator", "editor"]
groups = ["admin", "owner", "moderator", "editor"]
for group in groups:
Group.objects.create(name=group)
Group.objects.get_or_create(name=group)


def init_permissions():
"""permission types"""
permissions = [
{
"codename": "manage_registration",
"name": "allow or prevent user registration",
"groups": ["admin"],
},
{
"codename": "system_administration",
"name": "technical controls",
"groups": ["admin"],
},
{
"codename": "edit_instance_settings",
"name": "change the instance info",
"groups": ["admin"],
"groups": ["admin", "owner"],
},
{
"codename": "set_user_group",
"name": "change what group a user is in",
"groups": ["admin", "moderator"],
"groups": ["admin", "owner", "moderator"],
},
{
"codename": "control_federation",
"name": "control who to federate with",
"groups": ["admin", "moderator"],
"groups": ["admin", "owner", "moderator"],
},
{
"codename": "create_invites",
"name": "issue invitations to join",
"groups": ["admin", "moderator"],
"groups": ["admin", "owner", "moderator"],
},
{
"codename": "moderate_user",
"name": "deactivate or silence a user",
"groups": ["admin", "moderator"],
"groups": ["admin", "owner", "moderator"],
},
{
"codename": "moderate_post",
"name": "delete other users' posts",
"groups": ["admin", "moderator"],
"groups": ["admin", "owner", "moderator"],
},
{
"codename": "edit_book",
"name": "edit book info",
"groups": ["admin", "moderator", "editor"],
"groups": ["admin", "owner", "moderator", "editor"],
},
]

content_type = ContentType.objects.get_for_model(models.User)
for permission in permissions:
permission_obj = Permission.objects.create(
permission_obj, _ = Permission.objects.get_or_create(
codename=permission["codename"],
name=permission["name"],
content_type=content_type,
Expand Down
28 changes: 28 additions & 0 deletions bookwyrm/migrations/0168_auto_20221205_1701.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.16 on 2022-12-05 17:01

import bookwyrm.models.fields
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("bookwyrm", "0167_auto_20221125_1900"),
]

operations = [
migrations.AddField(
model_name="author",
name="aasin",
field=bookwyrm.models.fields.CharField(
blank=True, max_length=255, null=True
),
),
migrations.AddField(
model_name="book",
name="aasin",
field=bookwyrm.models.fields.CharField(
blank=True, max_length=255, null=True
),
),
]
63 changes: 63 additions & 0 deletions bookwyrm/migrations/0168_auto_20221205_2331.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
""" I added two new permission types and a new group to the management command that
creates the database on install, this creates them for existing instances """
# Generated by Django 3.2.16 on 2022-12-05 23:31

from django.db import migrations


def create_groups_and_perms(apps, schema_editor):
"""create the new "owner" group and "system admin" permission"""
db_alias = schema_editor.connection.alias
group_model = apps.get_model("auth", "Group")
# Add the "owner" group, if needed
owner_group, group_created = group_model.objects.using(db_alias).get_or_create(
name="owner"
)

# Create perms, if needed
user_model = apps.get_model("bookwyrm", "User")
content_type_model = apps.get_model("contenttypes", "ContentType")
content_type = content_type_model.objects.get_for_model(user_model)
perms_model = apps.get_model("auth", "Permission")
reg_perm, perm_created = perms_model.objects.using(db_alias).get_or_create(
codename="manage_registration",
name="allow or prevent user registration",
content_type=content_type,
)
admin_perm, admin_perm_created = perms_model.objects.using(db_alias).get_or_create(
codename="system_administration",
name="technical controls",
content_type=content_type,
)

# Add perms to the group if anything was created
if group_created or perm_created or admin_perm_created:
perms = [
"edit_instance_settings",
"set_user_group",
"control_federation",
"create_invites",
"moderate_user",
"moderate_post",
"edit_book",
]
owner_group.permissions.set(
perms_model.objects.using(db_alias).filter(codename__in=perms).all()
)

# also extend these perms to admins
# This is get or create so the tests don't fail -- it should already exist
admin_group, _ = group_model.objects.using(db_alias).get_or_create(name="admin")
admin_group.permissions.add(reg_perm)
admin_group.permissions.add(admin_perm)


class Migration(migrations.Migration):

dependencies = [
("bookwyrm", "0167_auto_20221125_1900"),
]

operations = [
migrations.RunPython(create_groups_and_perms, migrations.RunPython.noop)
]
Loading

0 comments on commit 5833553

Please sign in to comment.