Skip to content

Commit

Permalink
Merge branch 'main' into signout
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtavis authored Sep 17, 2024
2 parents fd5bd93 + 96529e5 commit 80554ce
Show file tree
Hide file tree
Showing 191 changed files with 6,840 additions and 4,301 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/pr_ci_i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,21 @@ jobs:
with:
python-version: "3.11"

- name: Execute i18n Values Check
- name: Execute i18n Key Identifiers Check
working-directory: ./frontend/i18n/check
run: python i18n_check_values.py
run: python i18n_check_key_identifiers.py

- name: Execute i18n Keys Check
- name: Execute i18n Unused Keys Check
if: always()
working-directory: ./frontend/i18n/check
run: python i18n_check_keys.py
run: python i18n_check_unused_keys.py

- name: Execute i18n Non Source Keys Check
if: always()
working-directory: ./frontend/i18n/check
run: python i18n_check_non_source_keys.py

- name: Execute i18n Repeat Values Check
if: always()
working-directory: ./frontend/i18n/check
run: python i18n_check_repeat_values.py
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
# - id: pretty-format-json

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.0
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"eslint.validate": ["javascript", "typescript", "vue"]
"eslint.validate": ["javascript", "typescript", "vue"],
"typescript.tsdk": "./frontend/node_modules/typescript/lib"
}
33 changes: 30 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ If you have questions or would like to communicate with the team, please [join u
- [Learning the tech stack](#learning-the-tech)
- [Development environment](#dev-env)
- [Style guide](#style-guide)
- [Testing](#testing)
- [Linting](#linting)
- [Issues and projects](#issues-projects)
- [Bug reports](#bug-reports)
Expand Down Expand Up @@ -303,6 +304,35 @@ From there you'll be able to visit http://localhost:6006/ to view the documentat

Please see the [activist style guide](https://github.com/activist-org/activist/blob/main/STYLEGUIDE.md) for details about how to follow the code style for the project. We made these guidelines to assure that we as a community write clean, cohesive code that's easy to write and review. Suggestions for the style guide are welcome.
<a id="testing"></a>
## Testing [`⇧`](#contents)
### Backend
Please run the following commands from the project root to test the backend:
```bash
# Start the Docker container:
docker compose --env-file .env.dev up backend --build -d # -d to hide logs
# Enter the backend container:
docker exec -it django_backend sh
# Run backend tests:
pytest
# Once tests are finished:
exit
```
### Frontend
Running frontend tests locally is currently WIP.
> [!NOTE]
> When working on the frontend, activist recommends manual typechecking. From within the `frontend` directory run `yarn run postinstall` followed by `yarn nuxi typecheck` to confirm your changes are type-safe. Existing TS errors may be ignored. PRs to fix these are always welcome!
<a id="linting"></a>
## Linting [`⇧`](#contents)
Expand Down Expand Up @@ -405,9 +435,6 @@ When making a contribution, adhering to the [GitHub flow](https://docs.github.co
git pull --rebase upstream <dev-branch>
```

> [!NOTE]
> When working on the frontend, activist recommends manual typechecking. From within the `frontend` directory run `yarn run postinstall` followed by `yarn nuxi typecheck` to confirm your changes are type-safe. Existing TS errors may be ignored. PRs to fix these are always welcome!

6. Push your topic branch up to your fork:

```bash
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![nuxt](https://img.shields.io/badge/Nuxt%203-41b883.svg?logo=nuxt.js&logoColor=ffffff)](#tech-stack)
[![vue](https://img.shields.io/badge/Vue%203-41b883.svg?logo=vue.js&logoColor=ffffff)](#tech-stack)
[![tailwind](https://img.shields.io/badge/Tailwind%203-38BDF8.svg?logo=tailwindcss&logoColor=ffffff)](#tech-stack)
[![license](https://img.shields.io/github/license/activist-org/activist-iOS.svg?label=%20)](https://github.com/activist-org/activist/blob/main/LICENSE.txt)
[![license](https://img.shields.io/github/license/activist-org/activist.svg?label=%20)](https://github.com/activist-org/activist/blob/main/LICENSE.txt)
[![coc](https://img.shields.io/badge/Contributor%20Covenant-ff69b4.svg)](https://github.com/activist-org/activist/blob/main/.github/CODE_OF_CONDUCT.md)
[![instagram](https://img.shields.io/badge/Instagram-8134AF.svg?logo=instagram&logoColor=ffffff)](https://instagram.com/activist_org)
[![weblate](https://img.shields.io/badge/Weblate-144D3F.svg?logo=weblate&logoColor=ffffff)](https://hosted.weblate.org/projects/activist/activist)
Expand Down Expand Up @@ -203,7 +203,7 @@ git remote add upstream https://github.com/activist-org/activist.git
```bash
docker compose --env-file .env.dev up
# Or with new dependencies:
# Or with new dependencies or backend model changes:
# docker compose --env-file .env.dev up --build
# And to stop the containers when you're done working:
Expand Down
63 changes: 30 additions & 33 deletions STYLEGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ Vue files (`.vue`) are Single-File Components that have `<template>`, `<script>`
></element>
```

> [!NOTE]
> Put the aria label as the last attribute on any given element so it's easy to see if it's missing (`aria-label` for as an HTML attribute and `ariaLabel` as a component prop)
Please see the [Vue.js style guide](https://vuejs.org/style-guide) for general suggestions on how to write Vue files.

### Page Routing
Expand Down Expand Up @@ -239,48 +242,42 @@ activist is a global platform and must function in countless different regions a
>
> - This is the source from which all the other languages are translated from
> - Edits to the other files should be made on activist's [public localization project on Weblate](https://hosted.weblate.org/projects/activist/activist)
> - Please alphabetize the keys, with your code editor likely having built in functionality for this
> - Do not put the dictionary into different levels!
> - The purpose of one flat dictionary is so that we can search for the key in the codebase and easily find its uses and where it's defined
> - Do not put the JSON dictionaries into different levels!
> - The purpose of the flat dictionaries is so that we can search for the key in the codebase and easily find its uses and where it's defined
> - Do not include periods in aria-labels (screen reader user will configure their own preferences for a hard stop)
> - Put the aria label as the last attribute on any given element so it's easy to see if it's missing (`aria-label` for as an HTML attribute and `ariaLabel` as a prop)
Localization keys should be defined based on their component or page within the platform and the content that they refer to (`CONTENT_REFERENCE` below). Please use the following rules as a guide if you find yourself needing to create new localization keys:
Localization keys should be defined based on the file in which they're used within the platform and the content that they refer to (`CONTENT_REFERENCE` below). Please use the following rules as a guide if you find yourself needing to create new localization keys:

- Separate directories and references by `.` and CamelCase file name words by `-` in keys
- Ex: `"components.search-bar.CONTENT_REFERENCE"` for the `SearchBar` component
- If the localization key is being passed to a component prop, include it in the content reference
- Ex: `"components.shield-topic.topic.CONTENT_REFERENCE"` for passing a localized `topic` prop to the `ShieldTopic` component
- `"CONTENT_REFERENCE"` in this case would be a reference to the name of a topic like `"environment"`
- Separate directories and references by `.` and PascalCase/camelCase file name components by `_` in keys
- Ex: `"components.search_bar.CONTENT_REFERENCE"` for the `SearchBar` component
- Even though Nuxt allows for us to nest components in directories, avoid repetition in the directory path used to define the localization key
- Ex: if you're defining a key within `DropdownCreate`:
-`"components.dropdown-create.CONTENT_REFERENCE"`
-`"components.dropdown.dropdown-create.CONTENT_REFERENCE"`
- Define keys based on the lowest level component or other entity in which they're used
- Ex: you're working on the about page for organizations and there's a `BtnAction` that's getting a localization key:
-`"components.btn-action.CONTENT_REFERENCE"`
-`"pages.organizations.id.about.CONTENT_REFERENCE"`
- The reason for this is we want to make sure that we can reuse keys wherever we can
- In the above example, if we defined the key based on its location on the organization about page when it's a `BtnAction` with a text like `"Support"`, then we'd need to create a different version of this key for each occurrence of the button depending on the location
- With the system detailed above, we have the `components.btn-action.label.support` key that we can use anywhere that we have a support button ✨
- Please end all aria-label keys with `-alt-text` so the localization team knows that they're for screen readers
- Ex: If you're defining a key within `CardAbout`:
-`"components.card_about.CONTENT_REFERENCE"`
-`"components.card.card_about.CONTENT_REFERENCE"`
- Define keys based on the lowest level file in which they're used
- Use `_global` to indicate that a key is used in multiple places in a given directory
- Ex: You're creating a key that's used by multiple cards:
-`"components.card._global.CONTENT_REFERENCE"`
-`"components.card.INDIVIDUAL_COMPONENT.CONTENT_REFERENCE"`
- Please end all aria-label keys with `_alt_text` so the localization team knows that they're for screen readers
- If you need a capitalized and lower case version of a word, signify the lower case version with `_lower` at the end of the key
- For pages with long texts please follow the below naming criteria:
- `"header"`: the main header (h1) of the given page
- `"section-#"`: a section that iterates by one with every header and subheader
- `"section-#-#"`: a subsection, with other `#-#` patterns also being possible (see below)
- `"section-#-subheader"`: marks the start of a new section (h2 and beyond)
- `"section-#-paragraph-#"`: a paragraph with one or more sentences
- `"section-#-paragraph-#-#"`: a paragraph with separate parts to insert things like links
- `"section-#-list-#-item-#"`: an item in a list
- `"section-#-list-#-item-#-#"`: a subitem of the given item
- If you're creating a value that already exists, move it and the original to a `_global` sub name at the lowest shared name in `en-US.json`
- If there are different uses of the same value in one file, then alphabetically combine the final keys with dashes (ex: `header-title`)
- `"header"`: The main header (h1) of the given page
- `"section_#"`: A section that iterates by one with every header and subheader
- `"section_#_#"`: A subsection, with other `#_#` patterns also being possible (see below)
- `"section_#_subheader"`: Marks the start of a new section (h2 and beyond)
- `"section_#_paragraph_#"`: A paragraph with one or more sentences
- `"section_#_paragraph_#_#"`: A paragraph with separate parts to insert things like links
- `"section_#_list_#_item_#"`: An item in a list
- `"section_#_list_#_item_#_#"`: A subitem of the given item
- If there are different uses of the same value in one file, then alphabetically combine the final keys with dashes (ex: `header_title`)
- Please alphabetize the keys, with your code editor likely having built in functionality for this
- Please always assign the full key as a string to assure that i18n content checks can pick up if the key has been used
- Eg: `section-1-2` and not `section-{var_number}-2`
- Eg: `section_1_2` and not `section_{var_number}_2`
- This makes sure that content writers and the i18n team are only working with language that's actively in use

The activist team is happy to help if there's any confusion with the above rules! Feel free to ask in the issue you're working on or even check once a PR is made and we'll make sure that conventions are being followed.
> [!NOTE]
> The activist community also maintains the [i18n-check project](https://github.com/activist-org/i18n-check-action?tab=readme-ov-file#contentions) that enforces all of the above in pull requests. Do your best and we'll help you out during the PR process! You can also join us in the [localization room on Matrix](https://matrix.to/#/!DzbdYyfhjinQBWXgQe:matrix.org?via=matrix.org) if you have questions :)
<a id="images-icons"></a>

Expand Down
2 changes: 0 additions & 2 deletions backend/authentication/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ def verification_partner(
if not create:
# Simple build, do nothing.
return
if extracted:
pass


# MARK: Bridge Tables
Expand Down
2 changes: 1 addition & 1 deletion backend/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def create_user(


class SupportEntityType(models.Model):
id = models.IntegerField(primary_key=True)
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
name = models.CharField(max_length=255)

def __str__(self) -> str:
Expand Down
11 changes: 5 additions & 6 deletions backend/authentication/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import uuid


@pytest.mark.django_db
pytestmark = pytest.mark.django_db


def test_str_methods() -> None:
support_entity_type = SupportEntityTypeFactory.build()
support = SupportFactory.build()
Expand All @@ -41,7 +43,6 @@ def test_str_methods() -> None:
assert str(user_topic) == str(user_topic.id)


@pytest.mark.django_db
def test_signup(client: Client) -> None:
"""
Test the signup function.
Expand Down Expand Up @@ -152,14 +153,13 @@ def test_signup(client: Client) -> None:
assert user.verification_code is None


@pytest.mark.django_db
def test_login(client: Client) -> None:
"""
Test login view.
Scenarios:
1. User that signed up with email, that has not confirmed their email
2. User that signed up with email, confimred email address. Is logged in successfully
2. User that signed up with email, confirmed email address. Is logged in successfully
3. User exists but password is incorrect
4. User does not exists and tries to login
"""
Expand All @@ -174,7 +174,7 @@ def test_login(client: Client) -> None:
)
assert response.status_code == 400

# 2. User that signed up with email, confimred email address. Is logged in successfully
# 2. User that signed up with email, confirmed email address. Is logged in successfully
user.is_confirmed = True
user.save()
response = client.post(
Expand Down Expand Up @@ -204,7 +204,6 @@ def test_login(client: Client) -> None:
assert response.status_code == 400


@pytest.mark.django_db
def test_pwreset(client: Client) -> None:
"""
Test password reset view.
Expand Down
3 changes: 2 additions & 1 deletion backend/backend/custom_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
please check the path: backend/backend/settings.py
"""

# Pagination settings
# MARK: Pagination

PAGINATION_PAGE_SIZE = 20
PAGINATION_MAX_PAGE_SIZE = 100
2 changes: 1 addition & 1 deletion backend/backend/exception_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def bad_request_logger(exception: Any, context: dict[str, Any]) -> Response | None:
# Get the DRF exception handler standard error response
# Get the DRF exception handler standard error response.
response = exception_handler(exception, context)

if response is not None:
Expand Down
40 changes: 35 additions & 5 deletions backend/backend/management/commands/populate_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,58 @@
from django.core.management.base import BaseCommand

from authentication.factories import UserFactory
from authentication.models import UserModel
from entities.factories import GroupFactory, OrganizationFactory
from entities.models import Group, Organization
from events.factories import EventFactory
from events.models import Event


class Options(TypedDict):
users: int
orgs: int
groups: int
events: int


# ATTN: We're not actually putting texts into the DB.
class Command(BaseCommand):
help = "Populate the database with dummy data"

def add_arguments(self, parser: ArgumentParser) -> None:
parser.add_argument("--users", type=int, default=100)
parser.add_argument("--users", type=int, default=10)
parser.add_argument("--orgs", type=int, default=10)
parser.add_argument("--groups", type=int, default=10)
parser.add_argument("--events", type=int, default=10)

def handle(self, *args: str, **options: Unpack[Options]) -> None:
number_of_users = options["users"]
number_of_users = options.get("users")
number_of_orgs = options.get("orgs")
number_of_groups = options.get("groups")
number_of_events = options.get("events")

# Clear all tables before creating new data.
UserModel.objects.exclude(username="admin").delete()
Organization.objects.all().delete()
Group.objects.all().delete()
Event.objects.all().delete()

try:
UserFactory.create_batch(number_of_users)
UserFactory.create_batch(size=number_of_users)
OrganizationFactory.create_batch(size=number_of_orgs)
GroupFactory.create_batch(size=number_of_groups)
EventFactory.create_batch(size=number_of_events)
self.stdout.write(
self.style.ERROR(f"Number of users created: {number_of_users}")
self.style.ERROR(
f"Number of users created: {number_of_users}\n"
f"Number of organizations created: {number_of_orgs}\n"
f"Number of groups created: {number_of_groups}\n"
f"Number of events created: {number_of_events}\n"
)
)
except Exception as error:
self.stdout.write(
self.style.ERROR(
f"An error occured during the creation of dummy data: {error}"
f"An error occurred during the creation of dummy data: {error}"
)
)
2 changes: 1 addition & 1 deletion backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
EMAIL_PORT = os.getenv("EMAIL_PORT")
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD")
EMAIL_USE_TLS = bool(os.getenv("EMAIL_USE_TLS") == "True")
EMAIL_USE_TLS = os.getenv("EMAIL_USE_TLS") == "True"
# DEVELOPMENT ONLY
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

Expand Down
3 changes: 1 addition & 2 deletions backend/backend/tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

@pytest.fixture
def api_client() -> APIClient:
client = APIClient()
return client
return APIClient()
Loading

0 comments on commit 80554ce

Please sign in to comment.