Skip to content

Commit 3219157

Browse files
committed
[ENG-4149] require login to deploy named templates (#4450)
* integration_tests.yml: init masenf/rx_shout as a template fix test * [ENG-4149] require login to deploy template * Send loginv2 telemetry event
1 parent 0c81922 commit 3219157

File tree

4 files changed

+52
-21
lines changed

4 files changed

+52
-21
lines changed

.github/workflows/integration_tests.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,36 @@ jobs:
162162
--python-version "${{ matrix.python-version }}" --commit-sha "${{ github.sha }}"
163163
--pr-id "${{ github.event.pull_request.id }}" --branch-name "${{ github.head_ref || github.ref_name }}"
164164
--app-name "reflex-web" --path ./reflex-web/.web
165+
166+
rx-shout-from-template:
167+
strategy:
168+
fail-fast: false
169+
runs-on: ubuntu-latest
170+
steps:
171+
- uses: actions/checkout@v4
172+
- uses: ./.github/actions/setup_build_env
173+
with:
174+
python-version: '3.11.4'
175+
run-poetry-install: true
176+
create-venv-at-path: .venv
177+
- name: Create app directory
178+
run: mkdir rx-shout-from-template
179+
- name: Init reflex-web from template
180+
run: poetry run reflex init --template https://github.com/masenf/rx_shout
181+
working-directory: ./rx-shout-from-template
182+
- name: ignore reflex pin in requirements
183+
run: sed -i -e '/reflex==/d' requirements.txt
184+
working-directory: ./rx-shout-from-template
185+
- name: Install additional dependencies
186+
run: poetry run uv pip install -r requirements.txt
187+
working-directory: ./rx-shout-from-template
188+
- name: Run Website and Check for errors
189+
run: |
190+
# Check that npm is home
191+
npm -v
192+
poetry run bash scripts/integration.sh ./rx-shout-from-template prod
165193
194+
166195
reflex-web-macos:
167196
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
168197
strategy:

reflex/reflex.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,9 @@ def loginv2(loglevel: constants.LogLevel = typer.Option(config.loglevel)):
370370

371371
check_version()
372372

373-
hosting_cli.login()
373+
validated_info = hosting_cli.login()
374+
if validated_info is not None:
375+
telemetry.send("loginv2", user_uuid=validated_info.get("user_id"))
374376

375377

376378
@cli.command()

reflex/utils/prerequisites.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,13 +1408,22 @@ def validate_and_create_app_using_remote_template(app_name, template, templates)
14081408
"""
14091409
# If user selects a template, it needs to exist.
14101410
if template in templates:
1411+
from reflex_cli.v2.utils import hosting
1412+
1413+
authenticated_token = hosting.authenticated_token()
1414+
if not authenticated_token or not authenticated_token[0]:
1415+
console.print(
1416+
f"Please use `reflex loginv2` to access the '{template}' template."
1417+
)
1418+
raise typer.Exit(3)
1419+
14111420
template_url = templates[template].code_url
14121421
else:
14131422
# Check if the template is a github repo.
14141423
if template.startswith("https://github.com"):
14151424
template_url = f"{template.strip('/').replace('.git', '')}/archive/main.zip"
14161425
else:
1417-
console.error(f"Template `{template}` not found.")
1426+
console.error(f"Template `{template}` not found or invalid.")
14181427
raise typer.Exit(1)
14191428

14201429
if template_url is None:
@@ -1451,7 +1460,7 @@ def generate_template_using_ai(template: str | None = None) -> str:
14511460

14521461

14531462
def fetch_remote_templates(
1454-
template: Optional[str] = None,
1463+
template: str,
14551464
) -> tuple[str, dict[str, Template]]:
14561465
"""Fetch the available remote templates.
14571466
@@ -1460,9 +1469,6 @@ def fetch_remote_templates(
14601469
14611470
Returns:
14621471
The selected template and the available templates.
1463-
1464-
Raises:
1465-
Exit: If the template is not valid or if the template is not specified.
14661472
"""
14671473
available_templates = {}
14681474

@@ -1474,19 +1480,7 @@ def fetch_remote_templates(
14741480
console.debug(f"Error while fetching templates: {e}")
14751481
template = constants.Templates.DEFAULT
14761482

1477-
if template == constants.Templates.DEFAULT:
1478-
return template, available_templates
1479-
1480-
if template in available_templates:
1481-
return template, available_templates
1482-
1483-
else:
1484-
if template is not None:
1485-
console.error(f"{template!r} is not a valid template name.")
1486-
console.print(
1487-
f"Go to the templates page ({constants.Templates.REFLEX_TEMPLATES_URL}) and copy the command to init with a template."
1488-
)
1489-
raise typer.Exit(0)
1483+
return template, available_templates
14901484

14911485

14921486
def initialize_app(
@@ -1501,6 +1495,9 @@ def initialize_app(
15011495
15021496
Returns:
15031497
The name of the template.
1498+
1499+
Raises:
1500+
Exit: If the template is not valid or unspecified.
15041501
"""
15051502
# Local imports to avoid circular imports.
15061503
from reflex.utils import telemetry
@@ -1528,7 +1525,10 @@ def initialize_app(
15281525
# change to the default to allow creation of default app
15291526
template = constants.Templates.DEFAULT
15301527
elif template == constants.Templates.CHOOSE_TEMPLATES:
1531-
template, templates = fetch_remote_templates()
1528+
console.print(
1529+
f"Go to the templates page ({constants.Templates.REFLEX_TEMPLATES_URL}) and copy the command to init with a template."
1530+
)
1531+
raise typer.Exit(0)
15321532

15331533
# If the blank template is selected, create a blank app.
15341534
if template in (constants.Templates.DEFAULT,):

reflex/utils/telemetry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def _prepare_event(event: str, **kwargs) -> dict:
129129

130130
cpuinfo = get_cpu_info()
131131

132-
additional_keys = ["template", "context", "detail"]
132+
additional_keys = ["template", "context", "detail", "user_uuid"]
133133
additional_fields = {
134134
key: value for key in additional_keys if (value := kwargs.get(key)) is not None
135135
}

0 commit comments

Comments
 (0)