Rename superAdminFirstUserOnly to superAdminNewUsers & flip default logic accordingly

Signed-off-by: Michael de Sa <mjdesa@gmail.com>
pull/10616/head
Jared Scheib 2017-12-13 14:49:49 -08:00 committed by Michael de Sa
parent 63ea69e679
commit 058f5fbc20
12 changed files with 130 additions and 802 deletions

View File

@ -32,7 +32,11 @@ func (s *ConfigStore) Migrate(ctx context.Context) error {
}
func (s *ConfigStore) Initialize(ctx context.Context) error {
var cfg chronograf.Config
cfg := chronograf.Config{
Auth: chronograf.AuthConfig{
SuperAdminNewUsers: true,
},
}
return s.Update(ctx, &cfg)
}

View File

@ -22,7 +22,7 @@ func TestConfig_Get(t *testing.T) {
wants: wants{
config: &chronograf.Config{
Auth: chronograf.AuthConfig{
SuperAdminFirstUserOnly: false,
SuperAdminNewUsers: true,
},
},
},
@ -68,14 +68,14 @@ func TestConfig_Update(t *testing.T) {
args: args{
config: &chronograf.Config{
Auth: chronograf.AuthConfig{
SuperAdminFirstUserOnly: true,
SuperAdminNewUsers: false,
},
},
},
wants: wants{
config: &chronograf.Config{
Auth: chronograf.AuthConfig{
SuperAdminFirstUserOnly: true,
SuperAdminNewUsers: false,
},
},
},

View File

@ -597,7 +597,7 @@ func UnmarshalOrganizationPB(data []byte, o *Organization) error {
func MarshalConfig(c *chronograf.Config) ([]byte, error) {
return MarshalConfigPB(&Config{
Auth: &AuthConfig{
SuperAdminFirstUserOnly: c.Auth.SuperAdminFirstUserOnly,
SuperAdminNewUsers: c.Auth.SuperAdminNewUsers,
},
})
}
@ -616,7 +616,7 @@ func UnmarshalConfig(data []byte, c *chronograf.Config) error {
if pb.Auth == nil {
return fmt.Errorf("Auth config is nil")
}
c.Auth.SuperAdminFirstUserOnly = pb.Auth.SuperAdminFirstUserOnly
c.Auth.SuperAdminNewUsers = pb.Auth.SuperAdminNewUsers
return nil
}

File diff suppressed because it is too large Load Diff

View File

@ -169,7 +169,7 @@ message Config {
}
message AuthConfig {
bool SuperAdminFirstUserOnly = 1; // SuperAdminFirstUserOnly configuration option that specifies which users will auto become super admin
bool SuperAdminNewUsers = 1; // SuperAdminNewUsers configuration option that specifies which users will auto become super admin
}
// The following is a vim modeline, it autoconfigures vim to have the

View File

@ -607,8 +607,14 @@ type OrganizationsStore interface {
}
// AuthConfig is the global application config section for auth parameters
type AuthConfig struct {
SuperAdminFirstUserOnly bool `json:"superAdminFirstUserOnly"`
// SuperAdminNewUsers should be true by default to give a seamless upgrade to
// 1.4.0 for legacy users. It means that all new users will by default receive
// SuperAdmin status. If a SuperAdmin wants to change this behavior, they
// can toggle it off via the Chronograf UI, in which case newly authenticating
// users will simply receive whatever role they would otherwise receive.
SuperAdminNewUsers bool `json:"superAdminNewUsers"`
}
// Config is the global application Config for parameters that can be set via

View File

@ -34,7 +34,7 @@ func TestConfig(t *testing.T) {
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
Auth: chronograf.AuthConfig{
SuperAdminFirstUserOnly: true,
SuperAdminNewUsers: false,
},
},
},
@ -42,7 +42,7 @@ func TestConfig(t *testing.T) {
wants: wants{
statusCode: 200,
contentType: "application/json",
body: `{"auth": {"superAdminFirstUserOnly": true}, "links": {"self": "/chronograf/v1/config"}}`,
body: `{"auth": {"superAdminNewUsers": false}, "links": {"self": "/chronograf/v1/config"}}`,
},
},
}
@ -103,7 +103,7 @@ func TestConfigSection(t *testing.T) {
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
Auth: chronograf.AuthConfig{
SuperAdminFirstUserOnly: true,
SuperAdminNewUsers: false,
},
},
},
@ -114,7 +114,7 @@ func TestConfigSection(t *testing.T) {
wants: wants{
statusCode: 200,
contentType: "application/json",
body: `{"superAdminFirstUserOnly": true, "links": {"self": "/chronograf/v1/config/auth"}}`,
body: `{"superAdminNewUsers": false, "links": {"self": "/chronograf/v1/config/auth"}}`,
},
},
{
@ -123,7 +123,7 @@ func TestConfigSection(t *testing.T) {
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
Auth: chronograf.AuthConfig{
SuperAdminFirstUserOnly: true,
SuperAdminNewUsers: false,
},
},
},
@ -204,7 +204,7 @@ func TestReplaceConfigSection(t *testing.T) {
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
Auth: chronograf.AuthConfig{
SuperAdminFirstUserOnly: true,
SuperAdminNewUsers: false,
},
},
},
@ -212,13 +212,13 @@ func TestReplaceConfigSection(t *testing.T) {
args: args{
section: "auth",
payload: chronograf.AuthConfig{
SuperAdminFirstUserOnly: false,
SuperAdminNewUsers: true,
},
},
wants: wants{
statusCode: 200,
contentType: "application/json",
body: `{"superAdminFirstUserOnly": false, "links": {"self": "/chronograf/v1/config/auth"}}`,
body: `{"superAdminNewUsers": true, "links": {"self": "/chronograf/v1/config/auth"}}`,
},
},
{
@ -227,7 +227,7 @@ func TestReplaceConfigSection(t *testing.T) {
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
Auth: chronograf.AuthConfig{
SuperAdminFirstUserOnly: true,
SuperAdminNewUsers: false,
},
},
},

View File

@ -324,7 +324,7 @@ func (s *Service) newUsersAreSuperAdmin() bool {
if err != nil {
return false
}
return !cfg.Auth.SuperAdminFirstUserOnly
return cfg.Auth.SuperAdminNewUsers
}
func (s *Service) usersOrganizations(ctx context.Context, u *chronograf.User) ([]chronograf.Organization, error) {

View File

@ -52,7 +52,7 @@ func TestService_Me(t *testing.T) {
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
Auth: chronograf.AuthConfig{
SuperAdminFirstUserOnly: true,
SuperAdminNewUsers: false,
},
},
},
@ -246,7 +246,7 @@ func TestService_Me(t *testing.T) {
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
Auth: chronograf.AuthConfig{
SuperAdminFirstUserOnly: false,
SuperAdminNewUsers: true,
},
},
},
@ -308,7 +308,7 @@ func TestService_Me(t *testing.T) {
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
Auth: chronograf.AuthConfig{
SuperAdminFirstUserOnly: true,
SuperAdminNewUsers: false,
},
},
},
@ -370,7 +370,7 @@ func TestService_Me(t *testing.T) {
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
Auth: chronograf.AuthConfig{
SuperAdminFirstUserOnly: true,
SuperAdminNewUsers: false,
},
},
},
@ -431,7 +431,7 @@ func TestService_Me(t *testing.T) {
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
Auth: chronograf.AuthConfig{
SuperAdminFirstUserOnly: true,
SuperAdminNewUsers: false,
},
},
},
@ -486,7 +486,7 @@ func TestService_Me(t *testing.T) {
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
Auth: chronograf.AuthConfig{
SuperAdminFirstUserOnly: true,
SuperAdminNewUsers: false,
},
},
},
@ -508,7 +508,7 @@ func TestService_Me(t *testing.T) {
ConfigStore: &mocks.ConfigStore{
Config: &chronograf.Config{
Auth: chronograf.AuthConfig{
SuperAdminFirstUserOnly: true,
SuperAdminNewUsers: false,
},
},
},

View File

@ -34,9 +34,9 @@ class OrganizationsTable extends Component {
this.setState({isCreatingOrganization: false})
}
handleChangeAuthConfigSuperAdminFirstUserOnly = superAdminFirstUserOnly => {
handleChangeAuthConfigSuperAdminNewUsers = superAdminNewUsers => {
const {onUpdateAuthConfig} = this.props
onUpdateAuthConfig({superAdminFirstUserOnly})
onUpdateAuthConfig({superAdminNewUsers})
}
render() {
@ -47,7 +47,7 @@ class OrganizationsTable extends Component {
onChooseDefaultRole,
onTogglePublic,
currentOrganization,
authConfig: {superAdminFirstUserOnly},
authConfig: {superAdminNewUsers},
} = this.props
const {isCreatingOrganization} = this.state
@ -111,13 +111,11 @@ class OrganizationsTable extends Component {
<td style={{width: 70}}>
<SlideToggle
size="xs"
active={superAdminFirstUserOnly}
onToggle={
this.handleChangeAuthConfigSuperAdminFirstUserOnly
}
active={superAdminNewUsers}
onToggle={this.handleChangeAuthConfigSuperAdminNewUsers}
/>
</td>
<td>Make new Users SuperAdmins by default?</td>
<td>All new users are SuperAdmins</td>
</tr>
</tbody>
</table>
@ -148,7 +146,7 @@ OrganizationsTable.propTypes = {
onChooseDefaultRole: func.isRequired,
onUpdateAuthConfig: func.isRequired,
authConfig: shape({
superAdminFirstUserOnly: bool,
superAdminNewUsers: bool,
}),
}
export default OrganizationsTable

View File

@ -117,7 +117,7 @@ OrganizationsPage.propTypes = {
id: string.isRequired,
}),
authConfig: shape({
superAdminFirstUserOnly: bool,
superAdminNewUsers: bool,
}),
}

View File

@ -4,7 +4,7 @@ const initialState = {
users: [],
organizations: [],
authConfig: {
superAdminFirstUserOnly: true,
superAdminNewUsers: true,
},
}