Fix user can't choose "not selected" for default alias domain (#2196)

* update contributing guide: replace rye by poetry and add a section for mac

* fix the bug where user can't choose "not selected" for the default alias domain

* ruff format

* remove trailing space

---------

Co-authored-by: Son NK <son@simplelogin.io>
This commit is contained in:
Son Nguyen Kim 2024-08-27 23:26:12 +02:00 committed by GitHub
parent 4b82dff070
commit c1625a8002
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 8 deletions

View File

@ -20,7 +20,7 @@ SimpleLogin backend consists of 2 main components:
## Install dependencies ## Install dependencies
The project requires: The project requires:
- Python 3.10 and [rye](https://github.com/astral-sh/rye) to manage dependencies - Python 3.10 and poetry to manage dependencies
- Node v10 for front-end. - Node v10 for front-end.
- Postgres 13+ - Postgres 13+
@ -28,7 +28,7 @@ First, install all dependencies by running the following command.
Feel free to use `virtualenv` or similar tools to isolate development environment. Feel free to use `virtualenv` or similar tools to isolate development environment.
```bash ```bash
rye sync poetry sync
``` ```
On Mac, sometimes you might need to install some other packages via `brew`: On Mac, sometimes you might need to install some other packages via `brew`:
@ -55,7 +55,7 @@ brew install -s re2 pybind11
We use pre-commit to run all our linting and static analysis checks. Please run We use pre-commit to run all our linting and static analysis checks. Please run
```bash ```bash
rye run pre-commit install poetry run pre-commit install
``` ```
To install it in your development environment. To install it in your development environment.
@ -160,25 +160,25 @@ Here are the small sum-ups of the directory structures and their roles:
The code is formatted using [ruff](https://github.com/astral-sh/ruff), to format the code, simply run The code is formatted using [ruff](https://github.com/astral-sh/ruff), to format the code, simply run
``` ```
rye run ruff format . poetry run ruff format .
``` ```
The code is also checked with `flake8`, make sure to run `flake8` before creating the pull request by The code is also checked with `flake8`, make sure to run `flake8` before creating the pull request by
```bash ```bash
rye run flake8 poetry run flake8
``` ```
For HTML templates, we use `djlint`. Before creating a pull request, please run For HTML templates, we use `djlint`. Before creating a pull request, please run
```bash ```bash
rye run djlint --check templates poetry run djlint --check templates
``` ```
If some files aren't properly formatted, you can format all files with If some files aren't properly formatted, you can format all files with
```bash ```bash
rye run djlint --reformat . poetry run djlint --reformat .
``` ```
## Test sending email ## Test sending email
@ -226,3 +226,26 @@ Some features require a job handler (such as GDPR data export). To test such fea
```bash ```bash
python job_runner.py python job_runner.py
``` ```
# Setup for Mac
There are several ways to setup Python and manage the project dependencies on Mac. For info we have successfully used this setup on a Mac silicon:
```bash
# we haven't managed to make python 3.12 work
brew install python3.10
# make sure to update the PATH so python, pip point to Python3
# for us it can be done by adding "export PATH=/opt/homebrew/opt/python@3.10/libexec/bin:$PATH" to .zprofile
# Although pipx is the recommended way to install poetry,
# install pipx via brew will automatically install python 3.12
# and poetry will then use python 3.12
# so we recommend using poetry this way instead
curl -sSL https://install.python-poetry.org | python3 -
poetry install
# activate the virtualenv and you should be good to go!
source .venv/bin/activate
```

View File

@ -16,12 +16,13 @@ class CannotSetMailbox(Exception):
def set_default_alias_domain(user: User, domain_name: Optional[str]): def set_default_alias_domain(user: User, domain_name: Optional[str]):
if domain_name is None: if not domain_name:
LOG.i(f"User {user} has set no domain as default domain") LOG.i(f"User {user} has set no domain as default domain")
user.default_alias_public_domain_id = None user.default_alias_public_domain_id = None
user.default_alias_custom_domain_id = None user.default_alias_custom_domain_id = None
Session.flush() Session.flush()
return return
sl_domain: SLDomain = SLDomain.get_by(domain=domain_name) sl_domain: SLDomain = SLDomain.get_by(domain=domain_name)
if sl_domain: if sl_domain:
if sl_domain.hidden: if sl_domain.hidden: