diff --git a/pkg/api/datasources.go b/pkg/api/datasources.go index 46c5a41cdf8..e9eb78fbe13 100644 --- a/pkg/api/datasources.go +++ b/pkg/api/datasources.go @@ -22,7 +22,7 @@ func GetDataSources(c *m.ReqContext) Response { Datasources: query.Result, } - datasources := []*m.DataSource{} + var datasources []*m.DataSource if err := bus.Dispatch(&dsFilterQuery); err != nil { if err != bus.ErrHandlerNotFound { return Error(500, "Could not get datasources", err) diff --git a/public/app/features/datasources/AddDataSourcePermissions.tsx b/public/app/features/datasources/AddDataSourcePermissions.tsx new file mode 100644 index 00000000000..fb5832e88b3 --- /dev/null +++ b/public/app/features/datasources/AddDataSourcePermissions.tsx @@ -0,0 +1,122 @@ +import React, { PureComponent } from 'react'; +import { UserPicker } from 'app/core/components/Picker/UserPicker'; +import { Team, TeamPicker } from 'app/core/components/Picker/TeamPicker'; +import DescriptionPicker, { OptionWithDescription } from 'app/core/components/Picker/DescriptionPicker'; +import { dataSourceAclLevels, AclTarget, DataSourcePermissionLevel } from 'app/types/acl'; +import { User } from 'app/types'; + +export interface Props { + onAddPermission: (state) => void; + onCancel: () => void; +} + +interface State { + userId: number; + teamId: number; + type: AclTarget; + permission: DataSourcePermissionLevel; +} + +export class AddDataSourcePermissions extends PureComponent { + cleanState = () => ({ + userId: 0, + teamId: 0, + type: AclTarget.Team, + permission: DataSourcePermissionLevel.Query, + }); + + state = this.cleanState(); + + isValid() { + switch (this.state.type) { + case AclTarget.Team: + return this.state.teamId > 0; + case AclTarget.User: + return this.state.userId > 0; + } + return true; + } + + onTeamSelected = (team: Team) => { + this.setState({ teamId: team ? team.id : 0 }); + }; + + onUserSelected = (user: User) => { + this.setState({ userId: user ? user.id : 0 }); + }; + + onPermissionChanged = (permission: OptionWithDescription) => { + this.setState({ permission: permission.value }); + }; + + onTypeChanged = event => { + const type = event.target.value as AclTarget; + + this.setState({ type: type, userId: 0, teamId: 0 }); + }; + + onSubmit = async event => { + event.preventDefault(); + + await this.props.onAddPermission(this.state); + this.setState(this.cleanState()); + }; + + render() { + const { onCancel } = this.props; + const { type } = this.state; + + const pickerClassName = 'width-20'; + const aclTargets = [{ value: AclTarget.Team, text: 'Team' }, { value: AclTarget.User, text: 'User' }]; + + return ( +
+ +
+
Add Permission For
+
+
+ +
+ {type === AclTarget.User && ( +
+ +
+ )} + + {type === AclTarget.Team && ( +
+ +
+ )} +
+ +
+
+ +
+
+
+
+ ); + } +} + +export default AddDataSourcePermissions; diff --git a/public/app/features/datasources/__snapshots__/AddDataSourcePermissions.test.tsx.snap b/public/app/features/datasources/__snapshots__/AddDataSourcePermissions.test.tsx.snap new file mode 100644 index 00000000000..dab46c7609e --- /dev/null +++ b/public/app/features/datasources/__snapshots__/AddDataSourcePermissions.test.tsx.snap @@ -0,0 +1,175 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Render should render component 1`] = ` +
+ +
+
+ Add Permission For +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+`; + +exports[`Render should render user picker 1`] = ` +
+ +
+
+ Add Permission For +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+`; diff --git a/public/app/features/datasources/__snapshots__/DataSourcePermissionsList.test.tsx.snap b/public/app/features/datasources/__snapshots__/DataSourcePermissionsList.test.tsx.snap new file mode 100644 index 00000000000..dba51823549 --- /dev/null +++ b/public/app/features/datasources/__snapshots__/DataSourcePermissionsList.test.tsx.snap @@ -0,0 +1,327 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Render should render component 1`] = ` + + + + + + + + + + +
+ + + Admin + + (Role) + + + + Can + +
+ +
+
+ +
+`; + +exports[`Render should render items 1`] = ` + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + Admin + + (Role) + + + + Can + +
+ +
+
+ +
+ + + + testUser + + + + (User) + + + + Can + +
+ +
+
+ +
+ + + + A-team + + + + (Team) + + + + Can + +
+ +
+
+ +
+`;