This repository has been archived by the owner on May 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Create space user's dropdown form for adding other org users #1172
Merged
Merged
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e56bc8c
Add new constants to check for user role by username
rememberlenny 4ac8ee1
Create ability to get all users in org that aren't in space
rememberlenny 503e7f4
Create functions used to check space org role status
rememberlenny 0bba2f7
Create the component to manage the org parent user selector
rememberlenny 931eef7
Add the selector to the user component
rememberlenny 9fa5cbc
Get the selector based user adding working
rememberlenny 2461e0c
Add a component test
rememberlenny 651e522
Remove unused store cases
rememberlenny 9c2815e
Create check again space users
rememberlenny fa73119
Take care of linting
rememberlenny 04a8972
Lint tests
rememberlenny 1d3f87f
Fix linting
rememberlenny 55defcd
Remove unused comment
rememberlenny 33a9778
Rename component to be easily grokable
rememberlenny 4947863
Pull out constants
rememberlenny 42cb434
Rework file names and component reference
rememberlenny a94ab91
Get the error working on the component
rememberlenny 06ad595
Get the working selector check
rememberlenny 02106fb
Merge branch 'master' of github.com:18F/cg-dashboard into lkb-dropdow…
rememberlenny b98bf11
Save the changes on the user store check
rememberlenny a7813cf
Fix linting
rememberlenny 80ca7d6
Add the selector detection
rememberlenny fe47005
Rename the component
rememberlenny 38ed848
Change the function argument names
rememberlenny ff12ede
Rename usersSelectorDisabled
rememberlenny 5d8b81d
Linting
rememberlenny 57ac1d0
Re-update user action names
rememberlenny 339846c
Fix new var name on params around addUserRoles
rememberlenny f655f6e
Rename classes for specificity
rememberlenny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/** | ||
* Renders a form that allows org users to invite new users | ||
* to cloud.gov | ||
*/ | ||
|
||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import Action from './action.jsx'; | ||
import FormStore from '../stores/form_store'; | ||
import { Form, FormSelect } from './form'; | ||
import PanelDocumentation from './panel_documentation.jsx'; | ||
import userActions from '../actions/user_actions'; | ||
import { validateString } from '../util/validators'; | ||
|
||
const AUDITOR_NAME = 'auditors'; | ||
const SPACE_AUDITOR_NAME = 'space_auditor'; | ||
const USERS_PARENT_ENTITY_USER_FORM_GUID = 'users-parent-entity-users-form'; | ||
|
||
const propTypes = { | ||
orgUsersSelectorDisabled: PropTypes.bool, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be renamed to |
||
currentUserAccess: PropTypes.bool, | ||
parentEntityUsers: PropTypes.array, | ||
error: PropTypes.object, | ||
parentEntity: PropTypes.string, | ||
currentEntityGuid: PropTypes.string, | ||
currentEntity: PropTypes.string | ||
}; | ||
const defaultProps = { | ||
orgUsersSelectorDisabled: false, | ||
currentUserAccess: false, | ||
error: {} | ||
}; | ||
|
||
export default class UsersSelector extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.validateString = validateString().bind(this); | ||
this._onSubmitForm = this._onSubmitForm.bind(this); | ||
} | ||
|
||
componentDidMount() { | ||
FormStore.create(USERS_PARENT_ENTITY_USER_FORM_GUID); | ||
} | ||
|
||
_onSubmitForm(errs, values) { | ||
const { currentEntity } = this.props; | ||
const { currentEntityGuid } = this.props; | ||
const user_role = AUDITOR_NAME; | ||
const resource_role_name = SPACE_AUDITOR_NAME; | ||
if (values.userGuid) { | ||
const userGuid = values.userGuid.value; | ||
userActions.addUserRoles(resource_role_name, user_role, userGuid, currentEntityGuid, currentEntity); | ||
} | ||
} | ||
|
||
get invitationMessage() { | ||
const { parentEntity } = this.props; | ||
const { currentEntity } = this.props; | ||
|
||
return `Invite an existing user in this ${parentEntity}` + | ||
` to this ${currentEntity}.`; | ||
} | ||
|
||
get userSelector() { | ||
const { parentEntityUsers } = this.props; | ||
const orgUsers = parentEntityUsers.map((user) => | ||
({ value: user.guid, label: user.username }) | ||
); | ||
|
||
if (!orgUsers) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<FormSelect | ||
formGuid={ USERS_PARENT_ENTITY_USER_FORM_GUID } | ||
classes={ ['test-users'] } | ||
label="Username" | ||
name="userGuid" | ||
options={ orgUsers } | ||
validator={ this.validateString } | ||
/> | ||
); | ||
} | ||
|
||
render() { | ||
const { orgUsersSelectorDisabled } = this.props; | ||
const { currentEntity } = this.props; | ||
|
||
if (!this.props.currentUserAccess) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="test-users-selector"> | ||
<PanelDocumentation description> | ||
<p>{ this.invitationMessage }</p> | ||
</PanelDocumentation> | ||
<Form | ||
guid={ USERS_PARENT_ENTITY_USER_FORM_GUID } | ||
classes={ ['org_user_selector'] } | ||
ref="form" | ||
onSubmit={ this._onSubmitForm } | ||
> | ||
{ this.userSelector } | ||
<Action | ||
label="submit" | ||
type="submit" | ||
disabled={ orgUsersSelectorDisabled } | ||
> | ||
Add user to this { currentEntity } | ||
</Action> | ||
</Form> | ||
</div> | ||
); | ||
} | ||
|
||
} | ||
|
||
UsersSelector.propTypes = propTypes; | ||
|
||
UsersSelector.defaultProps = defaultProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh sorry for the confusing conversation.
we were saying
apiKey
->resource
and you can revert
resource_role_name
toroles
and leaveroles
as-is for now.we will address the naming when we address
addUserRoles
andaddedUserRoles
and the mapping to the frontend rolesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should stick to camel case as well