Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web: applications: redirect user on application rename #11981

Closed
wants to merge 9 commits into from
9 changes: 9 additions & 0 deletions authentik/core/api/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,12 @@
# 3 data points per day, so 8 hour spans
.get_events_per(timedelta(days=7), ExtractHour, 7 * 3)
)

def perform_update(self, serializer):
"""Override perform_update to handle redirection after slug change"""
instance = self.get_object()
old_slug = instance.slug
super().perform_update(serializer)
new_slug = serializer.instance.slug
if old_slug != new_slug:
self.request.session["redirect_to"] = f"/applications/{new_slug}/"

Check warning on line 347 in authentik/core/api/applications.py

View check run for this annotation

Codecov / codecov/patch

authentik/core/api/applications.py#L347

Added line #L347 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is session["redirect_to"] used? This should not be required ideally, this should be purely handled in the frontend

5 changes: 5 additions & 0 deletions web/src/admin/applications/ApplicationForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ export class ApplicationForm extends WithCapabilitiesConfig(ModelForm<Applicatio
},
});
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be doing both this and the change below in a more generic way for all objects that are identified by a user-configurable identifier cc @kensternberg-authentik

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kensternberg-authentik . Sorry to bother. Would it be possible to get a comment regarding this comment if possible?

if (this.instance && this.instance.slug !== app.slug) {
window.location.href = `#/core/applications/${app.slug}`;
}

return app;
}

Expand Down
6 changes: 6 additions & 0 deletions web/src/admin/applications/ApplicationViewPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ export class ApplicationViewPage extends AKElement {
}
}

updated(changedProperties: PropertyValues<this>) {
if (changedProperties.has("applicationSlug") && this.applicationSlug) {
this.fetchApplication(this.applicationSlug);
}
}

render(): TemplateResult {
return html`<ak-page-header
header=${this.application?.name || msg("Loading")}
Expand Down
Loading