Skip to content

Commit

Permalink
feat: Hackathon admin add users UI (#854)
Browse files Browse the repository at this point in the history
* Updated examples/access-token-server pkg json

- Also added yarn.lock file

* Pass store object to provider

- Pass existing store object into provider. Found out 2 stores were
created when createStore function is passed into Provider's 'store'
prop. This would lead to sagas being called twice for one action.

* Implemented admin add user logic

- Added addUsers saga which does (in rough order):
- - Check for existing Hackathon Role
- - Check for or creates group for default hackathon
- - Creates or updates user and enables them
- - Adds user to the hackathon group
- - Sets up user api3, email creds
- - Sends password reset token email
- - Updates user attributes, landing_page and hackathon attr
- Added parseCsv saga to parse csv of users, then call addUsers
- Added Admin UI tab and UI to add CSV of users and single user
- Updated package.json with papaparse dependency for csv parsing
- Updated yarn.lock
- Update hackathon Readme with new directions and api entitlements

Co-authored-by: John Kaster <kaster@google.com>
  • Loading branch information
jeremytchang and jkaster authored Oct 21, 2021
1 parent b019a6f commit a6fe4fd
Show file tree
Hide file tree
Showing 16 changed files with 5,719 additions and 43 deletions.
6 changes: 4 additions & 2 deletions examples/access-token-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
"@types/jest": "^26.0.14",
"@types/jsonwebtoken": "^8.5.0",
"@types/node": "^14.11.2",
"@types/node-fetch": "^3.0.3",
"jest": "^26.4.2",
"node-fetch": "^2.6.1",
"nodemon": "^2.0.4",
"test": "^0.6.0",
"ts-jest": "^26.5.6",
"ts-node": "^10.2.1"
"ts-node": "^10.2.1",
"typescript": "^4.4.3"
}
}
}
4,937 changes: 4,937 additions & 0 deletions examples/access-token-server/yarn.lock

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions packages/hackathon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ application: hackathon_app {
use_iframes: no
use_clipboard: no
external_api_urls: ["http://localhost:8081/*", "https://sheets.googleapis.com/*"]
core_api_methods: ["me", "all_roles", "all_user_attributes", "delete_user_attribute", "create_user_attribute", "search_groups", "search_users", "user_roles", "role_users"]
core_api_methods: ["me", "user_roles", "all_user_attributes", "delete_user_attribute", "create_user_attribute", "search_groups", "search_users", "all_roles"]
core_api_methods: ["me", "all_roles", "all_user_attributes", "delete_user_attribute", "create_user_attribute", "search_groups", "search_users", "user_roles", "role_users", "search_roles", "create_group", "set_role_groups", "set_user_attribute_group_values", "set_user_attribute_user_value", "create_user_credentials_email", "send_user_credentials_email_password_reset", "create_user_credentials_api3", "add_group_user", "update_user", "create_user", "search_groups_with_roles", "role_groups"]
oauth2_urls: []
scoped_user_attributes: ["sheet_id", "token_server_url"]
}
Expand All @@ -56,17 +55,9 @@ A Looker instance hosts the Hackathon app. Three Looker _roles_ and one _group_

### Hacker

Someone who has signed up for a Hackathon belongs to a group specifically created for that Hackathon. The name of this group is `Looker_Hackathon: <hackathon_id>`.
Someone who has signed up for a Hackathon belongs to a group specifically created for that Hackathon. The name of this group is `Looker_Hack: <hackathon_id>`.

When using the Hackathon registration [Python registration script](/examples/python/hackathon_app/README.md#bulk-import-script), the same `hackathon_id` provided there will be used to name the group for the Hackathon.

e.g., for Looker's first **Hack@Home**, if the `hackathon_id` is `hack_at_home`, the group name the Hackathon app will use to find signed up users is `Looker_Hackathon: hack_at_home`.

If registering users via the Looker admin interface instead, be sure to:

- create the correctly named hackathon group first
- add all registered users to that group
- add all other roles and group those users should have for the Hackathon
e.g., for Looker's first **Hack@Home**, if the `_id` is `hack_at_home`, the Hackathon app will use the group name`Looker_Hack: hack_at_home` to find signed up users.

### Staff

Expand All @@ -82,14 +73,22 @@ Anyone who has the Looker `Admin` role is also a Hackathon administrator because

## Setting up a Hackathon

You need to be a Looker Admin to set up the Hackathon extension
You need to be a Looker Admin to set up the Hackathon extension and add users.

- If you don't have a production hackathon sheet, copy the Hackathon GSheets template to a new sheet
- Create a new Hackathon entry in the `hackathons` tab. To override the selection of the Hackathon for the extension to view, set the `default` column of the desired hackathon to `TRUE`.
- Copy the Hackathon GSheets template to a new sheet. (To be linked)
- Add a new row in the `hackathons` tab for your hackathon. To override which hackathon the extension views, set the `default` column of the desired hackathon row to `TRUE`.
- Grant your service account access to the new GSheet
- Open the Hackathon extension in Looker
- Admin | Configuration
- provide the requested values
- save them
- Reload the page
- Open the Hackathon extension in Looker.
- Configure Hackathon extension GSheet connection
- Admin | Configuration
- Provide the requested values
- Submit
- Reload the page
- See the banner listing the desired hackathon in the Welcome message
- Create `Hackathon` role with permissions you deem necessary for hackathon users.
- Add users through app, which will create the hackathon group and assign the `Hackathon` role and accomplish other administrative tasks.
- Admin | Add users
- Add Users with CSV or individually
- Submit
- Reload the page
- Create `Hackathon Staff` and `Hackathon Judge` roles, set up their permissions, and and assign them to users.
1 change: 1 addition & 0 deletions packages/hackathon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@styled-icons/material-outlined": "^10.28.0",
"@styled-icons/material-rounded": "^10.28.0",
"lodash": "^4.17.20",
"papaparse": "^5.3.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-hot-loader": "^4.13.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/hackathon/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import { ExtensionProvider } from '@looker/extension-sdk-react'
import { ComponentsProvider } from '@looker/components'
import { hot } from 'react-hot-loader/root'
import { Hackathon } from './Hackathon'
import { configureStore } from './data/store'
import store from './data/store'

export const App: FC = hot(() => {
return (
<Provider store={configureStore()}>
<Provider store={store}>
<ExtensionProvider>
<ComponentsProvider>
<Hackathon />
Expand Down
80 changes: 80 additions & 0 deletions packages/hackathon/src/data/add_user/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
MIT License
Copyright (c) 2021 Looker Data Sciences, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

export interface UserToAdd {
first: string
last: string
email: string
}

export enum Actions {
PARSE_CSV = 'PARSE_CSV',
ADD_USERS = 'ADD_USERS',
INCREMENT_USERS_ADDED = 'INCREMENT_USERS_ADDED',
RESET_ADD_USERS = 'RESET_ADD_USERS',
}

export interface ParseCsvAction {
type: Actions.PARSE_CSV
payload: File
}

export interface AddUsersAction {
type: Actions.ADD_USERS
payload: Array<UserToAdd>
}

export interface IncrementUsersAddedAction {
type: Actions.INCREMENT_USERS_ADDED
}

export interface ResetAddUsersAction {
type: Actions.RESET_ADD_USERS
}

export type AddUserAction =
| ParseCsvAction
| AddUsersAction
| IncrementUsersAddedAction
| ResetAddUsersAction

export const parseCsv = (csvFile: File): ParseCsvAction => ({
type: Actions.PARSE_CSV,
payload: csvFile,
})

export const addUsers = (usersToAdd: Array<UserToAdd>): AddUsersAction => ({
type: Actions.ADD_USERS,
payload: usersToAdd,
})

export const incrementUsersAdded = (): IncrementUsersAddedAction => ({
type: Actions.INCREMENT_USERS_ADDED,
})

export const resetAddUsers = (): ResetAddUsersAction => ({
type: Actions.RESET_ADD_USERS,
})
80 changes: 80 additions & 0 deletions packages/hackathon/src/data/add_user/reducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
MIT License
Copyright (c) 2021 Looker Data Sciences, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import type { AddUserAction, UserToAdd } from './actions'
import { Actions } from './actions'

export enum ADD_STAGES {
INIT,
USERS_ADDING,
USERS_ADDED,
}

export interface AddUserState {
usersToAdd: Array<UserToAdd>
usersAdded: number
stage: ADD_STAGES
}

const defaultState: Readonly<AddUserState> = Object.freeze({
usersToAdd: [],
usersAdded: 0,
stage: ADD_STAGES.INIT,
})

export const addUserReducer = (
state: AddUserState = defaultState,
action: AddUserAction
): AddUserState => {
switch (action.type) {
case Actions.PARSE_CSV:
return {
...defaultState,
}
case Actions.ADD_USERS:
return {
...defaultState,
stage: ADD_STAGES.USERS_ADDING,
usersToAdd: action.payload,
usersAdded: 0,
}
case Actions.INCREMENT_USERS_ADDED:
return {
...state,
usersAdded: state.usersAdded + 1,
stage:
state.usersAdded + 1 < state.usersToAdd.length
? ADD_STAGES.USERS_ADDING
: ADD_STAGES.INIT,
}
case Actions.RESET_ADD_USERS:
return {
...defaultState,
}
default:
return state
}
}
Loading

0 comments on commit a6fe4fd

Please sign in to comment.