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

Replace deprecated gapi.auth2 with GIS #2762

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
52df47c
Replace gapi.auth2
sumomomomomo Jan 26, 2024
a3f5468
Clean up PersistenceSaga + add persistence for GIS login
sumomomomomo Jan 31, 2024
70846e4
Update Google Drive Login Buttons UI + Use session for login persistence
sumomomomomo Jan 31, 2024
58ba4c7
Cleanup + Fix PersistenceSaga test
sumomomomomo Feb 5, 2024
7a08116
Add updated yarn lockfile
sayomaki Feb 5, 2024
688a8a9
Fix formatting through `yarn format`
sayomaki Feb 5, 2024
ecdf4b4
Fix packages + use gapi.client to fetch email
sumomomomomo Feb 14, 2024
0fb1028
Revert googleUser placeholder
sumomomomomo Feb 14, 2024
47b89a6
Migrate to google-oauth-gsi
sumomomomomo Feb 14, 2024
ff559bc
Remove console.log from PersistenceSaga.tsx
sumomomomomo Feb 14, 2024
beee70a
Remove unused deps
sumomomomomo Feb 14, 2024
58b7981
Modify googleLogin
sumomomomomo Feb 14, 2024
892b4a2
Fix failing tests
RichDom2185 Feb 23, 2024
1ae6324
Format SessionActions.ts
sumomomomomo Mar 28, 2024
7b2156f
Merge branch 'master' into replace-gapi
RichDom2185 Apr 10, 2024
c89437a
Merge branch 'master' of https://github.com/source-academy/frontend i…
RichDom2185 Apr 13, 2024
17fca67
Merge branch 'master' into replace-gapi
RichDom2185 Apr 13, 2024
4a26089
Merge branch 'master' into replace-gapi
RichDom2185 Apr 14, 2024
212e5f8
Merge branch 'master' into replace-gapi
martin-henz Apr 14, 2024
f091586
Merge branch 'master' of https://github.com/source-academy/frontend i…
RichDom2185 May 3, 2024
5652dfc
Merge branch 'replace-gapi' of https://github.com/source-academy/fron…
RichDom2185 May 3, 2024
936d586
Migrate new reducers to RTK
RichDom2185 May 3, 2024
504531d
Remove google-oauth-gsi, put script in index.html instead
sumomomomomo May 9, 2024
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@
"@testing-library/user-event": "^14.4.3",
"@types/acorn": "^6.0.0",
"@types/gapi": "^0.0.44",
"@types/gapi.auth2": "^0.0.57",
"@types/gapi.client": "^1.0.5",
"@types/gapi.client.drive": "^3.0.14",
"@types/google.accounts": "^0.0.14",
"@types/google.picker": "^0.0.39",
"@types/jest": "^29.0.0",
"@types/js-yaml": "^4.0.5",
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<script src="%PUBLIC_URL%/externalLibs/index.js"></script>
<script type="text/javascript" src="https://apis.google.com/js/api.js"></script>
<script type="text/javascript" src="https://apis.google.com/js/client.js"></script>
<script type="text/javascript" src="https://accounts.google.com/gsi/client"></script>
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
Expand Down
1 change: 1 addition & 0 deletions src/commons/application/ApplicationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ export const defaultSession: SessionState = {
assessmentOverviews: undefined,
agreedToResearch: undefined,
sessionId: Date.now(),
googleAccessToken: undefined,
githubOctokitObject: { octokit: undefined },
gradingOverviews: undefined,
students: undefined,
Expand Down
15 changes: 15 additions & 0 deletions src/commons/application/actions/SessionActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
FETCH_USER_AND_COURSE,
LOGIN,
LOGIN_GITHUB,
LOGIN_GOOGLE,
LOGOUT_GITHUB,
LOGOUT_GOOGLE,
NotificationConfiguration,
Expand All @@ -58,13 +59,15 @@ import {
REAUTOGRADE_ANSWER,
REAUTOGRADE_SUBMISSION,
REMOVE_GITHUB_OCTOKIT_OBJECT_AND_ACCESS_TOKEN,
REMOVE_GOOGLE_USER_AND_ACCESS_TOKEN,
SET_ADMIN_PANEL_COURSE_REGISTRATIONS,
SET_ASSESSMENT_CONFIGURATIONS,
SET_CONFIGURABLE_NOTIFICATION_CONFIGS,
SET_COURSE_CONFIGURATION,
SET_COURSE_REGISTRATION,
SET_GITHUB_ACCESS_TOKEN,
SET_GITHUB_OCTOKIT_OBJECT,
SET_GOOGLE_ACCESS_TOKEN,
SET_GOOGLE_USER,
SET_NOTIFICATION_CONFIGS,
SET_TOKENS,
Expand Down Expand Up @@ -161,6 +164,8 @@ export const fetchStudents = createAction(FETCH_STUDENTS, () => ({ payload: {} }

export const login = createAction(LOGIN, (providerId: string) => ({ payload: providerId }));

export const loginGoogle = createAction(LOGIN_GOOGLE, () => ({ payload: {} }));

export const logoutGoogle = createAction(LOGOUT_GOOGLE, () => ({ payload: {} }));

export const loginGitHub = createAction(LOGIN_GITHUB, () => ({ payload: {} }));
Expand Down Expand Up @@ -205,6 +210,11 @@ export const setAdminPanelCourseRegistrations = createAction(

export const setGoogleUser = createAction(SET_GOOGLE_USER, (user?: string) => ({ payload: user }));

export const setGoogleAccessToken = createAction(
SET_GOOGLE_ACCESS_TOKEN,
(accessToken?: string) => ({ payload: accessToken })
);

export const setGitHubOctokitObject = createAction(
SET_GITHUB_OCTOKIT_OBJECT,
(authToken?: string) => ({ payload: generateOctokitInstance(authToken || '') })
Expand All @@ -219,6 +229,11 @@ export const removeGitHubOctokitObjectAndAccessToken = createAction(
() => ({ payload: {} })
);

export const removeGoogleUserAndAccessToken = createAction(
REMOVE_GOOGLE_USER_AND_ACCESS_TOKEN,
() => ({ payload: {} })
);

export const submitAnswer = createAction(
SUBMIT_ANSWER,
(id: number, answer: string | number | ContestEntry[]) => ({ payload: { id, answer } })
Expand Down
9 changes: 9 additions & 0 deletions src/commons/application/reducers/SessionsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import { SourceActionType } from '../../utils/ActionsHelper';
import { logOut } from '../actions/CommonsActions';
import {
removeGitHubOctokitObjectAndAccessToken,
removeGoogleUserAndAccessToken,
setAdminPanelCourseRegistrations,
setAssessmentConfigurations,
setConfigurableNotificationConfigs,
setCourseConfiguration,
setCourseRegistration,
setGitHubAccessToken,
setGitHubOctokitObject,
setGoogleAccessToken,
setGoogleUser,
setNotificationConfigs,
setTokens,
Expand Down Expand Up @@ -112,6 +114,13 @@ const newSessionsReducer = createReducer(defaultSession, builder => {
.addCase(remoteExecUpdateSession, (state, action) => {
state.remoteExecutionSession = action.payload;
})
.addCase(setGoogleAccessToken, (state, action) => {
state.googleAccessToken = action.payload;
})
.addCase(removeGoogleUserAndAccessToken, (state, action) => {
state.googleUser = undefined;
state.googleAccessToken = undefined;
})
.addCase(removeGitHubOctokitObjectAndAccessToken, (state, action) => {
state.githubOctokitObject = { octokit: undefined };
state.githubAccessToken = undefined;
Expand Down
4 changes: 4 additions & 0 deletions src/commons/application/types/SessionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const FETCH_STUDENTS = 'FETCH_STUDENTS';
export const FETCH_TEAM_FORMATION_OVERVIEW = 'FETCH_TEAM_FORMATION_OVERVIEW';
export const FETCH_TEAM_FORMATION_OVERVIEWS = 'FETCH_TEAM_FORMATION_OVERVIEWS';
export const LOGIN = 'LOGIN';
export const LOGIN_GOOGLE = 'LOGIN_GOOGLE';
export const LOGOUT_GOOGLE = 'LOGOUT_GOOGLE';
export const LOGIN_GITHUB = 'LOGIN_GITHUB';
export const LOGOUT_GITHUB = 'LOGOUT_GITHUB';
Expand All @@ -42,6 +43,7 @@ export const SET_COURSE_REGISTRATION = 'SET_COURSE_REGISTRATION';
export const SET_ASSESSMENT_CONFIGURATIONS = 'SET_ASSESSMENT_CONFIGURATIONS';
export const SET_ADMIN_PANEL_COURSE_REGISTRATIONS = 'SET_ADMIN_PANEL_COURSE_REGISTRATIONS';
export const SET_GOOGLE_USER = 'SET_GOOGLE_USER';
export const SET_GOOGLE_ACCESS_TOKEN = 'SET_GOOGLE_ACCESS_TOKEN';
export const SET_GITHUB_OCTOKIT_OBJECT = 'SET_GITHUB_OCTOKIT_OBJECT';
export const SET_GITHUB_ACCESS_TOKEN = 'SET_GITHUB_ACCESS_TOKEN';
export const SUBMIT_ANSWER = 'SUBMIT_ANSWER';
Expand All @@ -52,6 +54,7 @@ export const REAUTOGRADE_SUBMISSION = 'REAUTOGRADE_SUBMISSION';
export const REAUTOGRADE_ANSWER = 'REAUTOGRADE_ANSWER';
export const REMOVE_GITHUB_OCTOKIT_OBJECT_AND_ACCESS_TOKEN =
'REMOVE_GITHUB_OCTOKIT_OBJECT_AND_ACCESS_TOKEN';
export const REMOVE_GOOGLE_USER_AND_ACCESS_TOKEN = 'REMOVE_GOOGLE_USER_AND_ACCESS_TOKEN';
export const UNPUBLISH_GRADING = 'UNPUBLISH_GRADING';
export const UNSUBMIT_SUBMISSION = 'UNSUBMIT_SUBMISSION';
export const UPDATE_ASSESSMENT_OVERVIEWS = 'UPDATE_ASSESSMENT_OVERVIEWS';
Expand Down Expand Up @@ -134,6 +137,7 @@ export type SessionState = {
readonly gradings: { [id: number]: GradingQuery };
readonly notifications: Notification[];
readonly googleUser?: string;
readonly googleAccessToken?: string;
readonly githubOctokitObject: { octokit: Octokit | undefined };
readonly githubAccessToken?: string;
readonly remoteExecutionDevices?: Device[];
Expand Down
28 changes: 22 additions & 6 deletions src/commons/controlBar/ControlBarGoogleDriveButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ const stateToIntent: { [state in PersistenceState]: Intent } = {
type Props = {
isFolderModeEnabled: boolean;
loggedInAs?: string;
accessToken?: string;
currentFile?: PersistenceFile;
isDirty?: boolean;
onClickOpen?: () => any;
onClickSave?: () => any;
onClickSaveAs?: () => any;
onClickLogOut?: () => any;
onClickLogIn?: () => any;
onPopoverOpening?: () => any;
};

Expand All @@ -40,7 +42,12 @@ export const ControlBarGoogleDriveButtons: React.FC<Props> = props => {
/>
);
const openButton = (
<ControlButton label="Open" icon={IconNames.DOCUMENT_OPEN} onClick={props.onClickOpen} />
<ControlButton
label="Open"
icon={IconNames.DOCUMENT_OPEN}
onClick={props.onClickOpen}
isDisabled={props.accessToken ? false : true}
/>
);
const saveButton = (
<ControlButton
Expand All @@ -52,13 +59,22 @@ export const ControlBarGoogleDriveButtons: React.FC<Props> = props => {
/>
);
const saveAsButton = (
<ControlButton label="Save as" icon={IconNames.SEND_TO} onClick={props.onClickSaveAs} />
<ControlButton
label="Save as"
icon={IconNames.SEND_TO}
onClick={props.onClickSaveAs}
isDisabled={props.accessToken ? false : true}
/>
);
const logoutButton = props.loggedInAs && (
<Tooltip content={`Logged in as ${props.loggedInAs}`}>
<ControlButton label="Log out" icon={IconNames.LOG_OUT} onClick={props.onClickLogOut} />

const loginButton = props.accessToken ? (
<Tooltip content={`Logged in as ${props.loggedInAs}`} disabled={!props.loggedInAs}>
<ControlButton label="Log Out" icon={IconNames.LOG_OUT} onClick={props.onClickLogOut} />
</Tooltip>
) : (
<ControlButton label="Log In" icon={IconNames.LOG_IN} onClick={props.onClickLogIn} />
);

const tooltipContent = props.isFolderModeEnabled
? 'Currently unsupported in Folder mode'
: undefined;
Expand All @@ -73,7 +89,7 @@ export const ControlBarGoogleDriveButtons: React.FC<Props> = props => {
{openButton}
{saveButton}
{saveAsButton}
{logoutButton}
{loginButton}
</ButtonGroup>
</div>
}
Expand Down
Loading
Loading