Skip to content

Only show privacy policy notice on Gitpod Cloud #18985

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

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions components/dashboard/src/Analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ export type Event =
| "organisation_authorised"
| "dotfile_repo_changed"
| "feedback_submitted"
| "workspace_class_changed";
| "workspace_class_changed"
| "privacy_policy_update_accepted";
type InternalEvent = Event | "path_changed" | "dashboard_clicked";

export type EventProperties = TrackOrgAuthorised | TrackInviteUrlRequested | TrackDotfileRepo | TrackFeedback;
export type EventProperties =
| TrackOrgAuthorised
| TrackInviteUrlRequested
| TrackDotfileRepo
| TrackFeedback
| TrackPolicyUpdateClick;
type InternalEventProperties = EventProperties | TrackDashboardClick | TrackPathChanged;

export interface TrackOrgAuthorised {
Expand All @@ -43,6 +49,12 @@ export interface TrackFeedback {
error_object?: StartWorkspaceError;
error_message?: string;
}

export interface TrackPolicyUpdateClick {
path: string;
success: boolean;
}

interface TrackDashboardClick {
dnt?: boolean;
path: string;
Expand Down
32 changes: 24 additions & 8 deletions components/dashboard/src/AppNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
* See License-AGPL.txt in the project root for license information.
*/

import dayjs from "dayjs";
import deepMerge from "deepmerge";
import { useCallback, useEffect, useState } from "react";
import Alert, { AlertType } from "./components/Alert";
import dayjs from "dayjs";
import { useUserLoader } from "./hooks/use-user-loader";
import { getGitpodService } from "./service/service";
import deepMerge from "deepmerge";
import { isGitpodIo } from "./utils";
import { trackEvent } from "./Analytics";

const KEY_APP_DISMISSED_NOTIFICATIONS = "gitpod-app-notifications-dismissed";
const PRIVACY_POLICY_LAST_UPDATED = "2023-10-17";
Expand All @@ -27,9 +29,23 @@ const UPDATED_PRIVACY_POLICY: Notification = {
type: "info",
preventDismiss: true,
onClose: async () => {
const userUpdates = { additionalData: { profile: { acceptedPrivacyPolicyDate: dayjs().toISOString() } } };
const previousUser = await getGitpodService().server.getLoggedInUser();
await getGitpodService().server.updateLoggedInUser(deepMerge(previousUser, userUpdates));
let dismissSuccess = false;
try {
const userUpdates = { additionalData: { profile: { acceptedPrivacyPolicyDate: dayjs().toISOString() } } };
const previousUser = await getGitpodService().server.getLoggedInUser();
const updatedUser = await getGitpodService().server.updateLoggedInUser(
deepMerge(previousUser, userUpdates),
);
dismissSuccess = !!updatedUser;
} catch (err) {
console.error("Failed to update user's privacy policy acceptance date", err);
dismissSuccess = false;
} finally {
trackEvent("privacy_policy_update_accepted", {
path: window.location.pathname,
success: dismissSuccess,
});
}
},
message: (
<span className="text-md">
Expand All @@ -48,10 +64,10 @@ export function AppNotifications() {

useEffect(() => {
const notifications = [];
if (!loading && user?.additionalData?.profile) {
if (!loading && isGitpodIo()) {
if (
!user.additionalData.profile.acceptedPrivacyPolicyDate ||
new Date(PRIVACY_POLICY_LAST_UPDATED) > new Date(user.additionalData.profile?.acceptedPrivacyPolicyDate)
!user?.additionalData?.profile?.acceptedPrivacyPolicyDate ||
new Date(PRIVACY_POLICY_LAST_UPDATED) > new Date(user.additionalData.profile.acceptedPrivacyPolicyDate)
) {
notifications.push(UPDATED_PRIVACY_POLICY);
}
Expand Down
2 changes: 1 addition & 1 deletion components/server/src/user/user-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class UserService {
}
if (newUser.additionalData) {
// When a user is created, it does not have `additionalData.profile` set, so it's ok to rewrite it here.
newUser.additionalData.profile = { acceptedPrivacyPolicyDate: new Date().toISOString() };
// todo:revert newUser.additionalData.profile = { acceptedPrivacyPolicyDate: new Date().toISOString() };
Copy link
Contributor

Choose a reason for hiding this comment

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

what should I do with this todo? Revert immediately?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also wouldn't new users get the notification now as well, because seeing the terms during signup is not recorded?

}
}

Expand Down