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

Add privacy policy link as env var #2133

Merged
merged 4 commits into from
Oct 3, 2024

Conversation

awarn
Copy link
Collaborator

@awarn awarn commented Sep 14, 2024

Description

Simply adds env var for the link

Related issues

Resolves #2116

Copy link
Member

@richardolsson richardolsson left a comment

Choose a reason for hiding this comment

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

Nice work! I'd like for the use of the environment variable to be moved out of messageIds.ts but other than that this looks like a good solution to me!

Comment on lines 177 to 179
link: m(
process.env.ZETKIN_PRIVACY_POLICY_LINK || 'https://zetkin.org/privacy'
),
Copy link
Member

Choose a reason for hiding this comment

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

I'm afraid we can't do this here, because the default text needs to be static.

Instead of putting the environment variable here, can you put the same || logic wherever feat.surveys.surveyForm.policy.link is used?

Or maybe remove the translated message altogether and we can just require all instances to have this environment variable to function correctly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, having multiple places the variable is set without a real use case for it seems weird. If it doesn't change with the translation, then I say we put it only in environment. And we can still fall back on the original, right?

Copy link
Member

Choose a reason for hiding this comment

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

I think we should fall back to the translation, like this (wherever the message is used today):

const privacyUrl = process.env.ZETKIN_PRIVACY_POLICY_LINK || messages.surveyForm.policy.link();

Now there's another potential problem here which is that the ZETKIN_PRIVACY_POLICY_LINK variable will not be available on the frontend. This is solved elsewhere by explicitly adding the environment variable to the Environment that can then be accessed by useEnv().

Copy link
Member

Choose a reason for hiding this comment

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

The reason why I prefer using the translation as the fallback is that for some instances (e.g. the main Zetkin instance used by most organizations) it is still useful to be able to have different translated versions of the same privacy policy, and for that the messages is a good solution.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Aah, okay, yes. Then I understand the priority here, I think. I'll make the change.

Copy link
Member

@richardolsson richardolsson left a comment

Choose a reason for hiding this comment

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

Nice work! I have looked at the code and tried running the build locally with and without the environment variable to test it's effect. I left a comment below about the intrinsic problems of this solution, but after thinking about it more closely I realized there isn't really a (small) better solution.

One thing that we could do is write a Playwright test to make sure the link works as expected at runtime. Are you familiar and comfortable with Playwright tests and want to have a go at it, or do you want me to?

@@ -22,6 +22,9 @@ export type SurveyPrivacyPolicyProps = {

const SurveyPrivacyPolicy: FC<SurveyPrivacyPolicyProps> = ({ survey }) => {
const messages = useMessages(messageIds);
const privacyUrl =
process.env.ZETKIN_PRIVACY_POLICY_LINK || messages.surveyForm.policy.link();
Copy link
Member

Choose a reason for hiding this comment

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

This works, because this is a React Server Component, i.e. it's rendered on the server where environment variables are available. If this component is ever rendered by the client, it will not work.

In those cases, we need to use useEnv() instead. But that wouldn't work in a RSC (like this one) because it relies on context.

So this is the right way to do it, but also error-prone because it's easy to forget to change to useEnv() if this component is ever modified to be client-rendered. I'm mentioning it here for future forensics into potential bugs.

Copy link
Member

@richardolsson richardolsson left a comment

Choose a reason for hiding this comment

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

I think the tests you've added provide sufficiently good coverage to feel comfortable releasing this into the wild.

The only problem I see with the "raw" approach to updating process.env at the beginning of each test is that it might create flaky tests in the future (if other tests also rely on this environment variable). But if we end up there, we can look into tweaking it then.

appUri,
page,
}) => {
process.env.ZETKIN_PRIVACY_POLICY_LINK = 'https://foo.bar';
Copy link
Member

Choose a reason for hiding this comment

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

I believe(?) there are other ways of mocking environment variables in jest, that makes sure they are reset after a test runs.

@richardolsson richardolsson merged commit fcd8604 into zetkin:main Oct 3, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Data protection link always leads to zetkin.org regardless of instance
2 participants