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

Give SuperAdmin DefaultRole on PUT /me #2632

Merged
merged 4 commits into from
Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion integrations/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ func TestServer(t *testing.T) {
"organization": "default"
},
{
"name": "admin",
"name": "viewer",
"organization": "1"
}
],
Expand Down
7 changes: 3 additions & 4 deletions server/me.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/influxdata/chronograf"
"github.com/influxdata/chronograf/oauth2"
"github.com/influxdata/chronograf/organizations"
"github.com/influxdata/chronograf/roles"
)

type meLinks struct {
Expand Down Expand Up @@ -96,7 +95,7 @@ func (s *Service) UpdateMe(auth oauth2.Authenticator) func(http.ResponseWriter,
}

// validate that the organization exists
_, err = s.Store.Organizations(serverCtx).Get(serverCtx, chronograf.OrganizationQuery{ID: &req.Organization})
org, err := s.Store.Organizations(serverCtx).Get(serverCtx, chronograf.OrganizationQuery{ID: &req.Organization})
if err != nil {
Error(w, http.StatusBadRequest, err.Error(), s.Logger)
return
Expand Down Expand Up @@ -151,8 +150,8 @@ func (s *Service) UpdateMe(auth oauth2.Authenticator) func(http.ResponseWriter,
// If the user is a super admin give them an admin role in the
// requested organization.
u.Roles = append(u.Roles, chronograf.Role{
Organization: req.Organization,
Name: roles.AdminRoleName,
Organization: org.ID,
Name: org.DefaultRole,
})
if err := s.Store.Users(serverCtx).Update(serverCtx, u); err != nil {
unknownErrorWithMessage(w, err, s.Logger)
Expand Down
11 changes: 0 additions & 11 deletions ui/src/admin/components/chronograf/OrganizationsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class OrganizationsTable extends Component {
currentOrganization,
authConfig: {superAdminNewUsers},
onChangeAuthConfig,
me,
} = this.props
const {isCreatingOrganization} = this.state

Expand Down Expand Up @@ -93,7 +92,6 @@ class OrganizationsTable extends Component {
onRename={onRenameOrg}
onChooseDefaultRole={onChooseDefaultRole}
currentOrganization={currentOrganization}
userHasRoleInOrg={!!me.organizations.find(o => org.id === o.id)}
/>
)}
<Authorized requiredRole={SUPERADMIN_ROLE}>
Expand Down Expand Up @@ -146,14 +144,5 @@ OrganizationsTable.propTypes = {
authConfig: shape({
superAdminNewUsers: bool,
}),
me: shape({
organizations: arrayOf(
shape({
id: string.isRequired,
name: string.isRequired,
defaultRole: string.isRequired,
})
),
}),
}
export default OrganizationsTable
19 changes: 4 additions & 15 deletions ui/src/admin/components/chronograf/OrganizationsTableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,9 @@ class OrganizationsTableRow extends Component {
}

handleChangeCurrentOrganization = async () => {
const {
router,
links,
meChangeOrganization,
organization,
userHasRoleInOrg,
} = this.props

await meChangeOrganization(
links.me,
{organization: organization.id},
{userHasRoleInOrg}
)
const {router, links, meChangeOrganization, organization} = this.props

await meChangeOrganization(links.me, {organization: organization.id})
router.push('')
}

Expand Down Expand Up @@ -204,7 +194,7 @@ class OrganizationsTableRow extends Component {
}
}

const {arrayOf, bool, func, shape, string} = PropTypes
const {arrayOf, func, shape, string} = PropTypes

OrganizationsTableRow.propTypes = {
organization: shape({
Expand Down Expand Up @@ -235,7 +225,6 @@ OrganizationsTableRow.propTypes = {
}),
}),
meChangeOrganization: func.isRequired,
userHasRoleInOrg: bool.isRequired,
}

OrganizationsTableRowDeleteButton.propTypes = {
Expand Down
14 changes: 9 additions & 5 deletions ui/src/shared/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {linksReceived} from 'shared/actions/links'
import {publishAutoDismissingNotification} from 'shared/dispatchers'
import {errorThrown} from 'shared/actions/errors'

import {LONG_NOTIFICATION_DISMISS_DELAY} from 'shared/constants'

export const authExpired = auth => ({
type: 'AUTH_EXPIRED',
payload: {
Expand Down Expand Up @@ -84,18 +86,20 @@ export const getMeAsync = ({shouldResetMe = false} = {}) => async dispatch => {

export const meChangeOrganizationAsync = (
url,
organization,
{userHasRoleInOrg = true} = {}
organization
) => async dispatch => {
dispatch(meChangeOrganizationRequested())
try {
const {data: me, auth, logoutLink} = await updateMeAJAX(url, organization)
const currentRole = me.roles.find(
r => r.organization === me.currentOrganization.id
)
dispatch(
publishAutoDismissingNotification(
'success',
`Now signed in to ${me.currentOrganization.name}${userHasRoleInOrg
? ''
: ' with Admin role.'}`
`Now logged in to '${me.currentOrganization
.name}' as '${currentRole.name}'`,
LONG_NOTIFICATION_DISMISS_DELAY
)
)
dispatch(meChangeOrganizationCompleted())
Expand Down
1 change: 1 addition & 0 deletions ui/src/shared/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ export const PRESENTATION_MODE_ANIMATION_DELAY = 0 // In milliseconds.
export const PRESENTATION_MODE_NOTIFICATION_DELAY = 2000 // In milliseconds.

export const SHORT_NOTIFICATION_DISMISS_DELAY = 2000 // in milliseconds
export const LONG_NOTIFICATION_DISMISS_DELAY = 4000 // in milliseconds

export const REVERT_STATE_DELAY = 1500 // ms

Expand Down
66 changes: 35 additions & 31 deletions ui/src/sources/containers/SourcePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import {publishNotification} from 'shared/actions/notifications'
import {connect} from 'react-redux'

import Notifications from 'shared/components/Notifications'
import SourceForm from 'src/sources/components/SourceForm'
import FancyScrollbar from 'shared/components/FancyScrollbar'
import SourceIndicator from 'shared/components/SourceIndicator'
Expand Down Expand Up @@ -200,42 +201,45 @@ class SourcePage extends Component {
}

return (
<div className={`${isInitialSource ? '' : 'page'}`}>
{isInitialSource
? null
: <div className="page-header">
<div className="page-header__container page-header__source-page">
<div className="page-header__col-md-8">
<div className="page-header__left">
<h1 className="page-header__title">
{editMode ? 'Edit Source' : 'Add a New Source'}
</h1>
</div>
<div className="page-header__right">
<SourceIndicator />
<div>
<Notifications />
<div className={`${isInitialSource ? '' : 'page'}`}>
{isInitialSource
? null
: <div className="page-header">
<div className="page-header__container page-header__source-page">
<div className="page-header__col-md-8">
<div className="page-header__left">
<h1 className="page-header__title">
{editMode ? 'Edit Source' : 'Add a New Source'}
</h1>
</div>
<div className="page-header__right">
<SourceIndicator />
</div>
</div>
</div>
</div>
</div>}
<FancyScrollbar className="page-contents">
<div className="container-fluid">
<div className="row">
<div className="col-md-8 col-md-offset-2">
<div className="panel panel-minimal">
<SourceForm
source={source}
editMode={editMode}
onInputChange={this.handleInputChange}
onSubmit={this.handleSubmit}
onBlurSourceURL={this.handleBlurSourceURL}
isInitialSource={isInitialSource}
gotoPurgatory={this.gotoPurgatory}
/>
</div>}
<FancyScrollbar className="page-contents">
<div className="container-fluid">
<div className="row">
<div className="col-md-8 col-md-offset-2">
<div className="panel panel-minimal">
<SourceForm
source={source}
editMode={editMode}
onInputChange={this.handleInputChange}
onSubmit={this.handleSubmit}
onBlurSourceURL={this.handleBlurSourceURL}
isInitialSource={isInitialSource}
gotoPurgatory={this.gotoPurgatory}
/>
</div>
</div>
</div>
</div>
</div>
</FancyScrollbar>
</FancyScrollbar>
</div>
</div>
)
}
Expand Down