Refactor Visibletype Orgs (#382)

refactor VisibleType

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/382
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
6543 2020-07-16 02:17:33 +00:00 committed by techknowlogick
parent 1026b1014c
commit b04ccca570
3 changed files with 28 additions and 44 deletions

View file

@ -22,8 +22,7 @@ func TestAdminOrg(t *testing.T) {
UserName: orgName, UserName: orgName,
FullName: orgName + " FullName", FullName: orgName + " FullName",
Description: "test adminCreateOrg", Description: "test adminCreateOrg",
// enum: public,limited,private Visibility: VisibleTypePublic,
Visibility: "public",
}) })
assert.NoError(t, err) assert.NoError(t, err)
assert.NotEmpty(t, newOrg) assert.NotEmpty(t, newOrg)

View file

@ -23,6 +23,20 @@ type Organization struct {
Visibility string `json:"visibility"` Visibility string `json:"visibility"`
} }
// VisibleType defines the visibility
type VisibleType string
const (
// VisibleTypePublic Visible for everyone
VisibleTypePublic VisibleType = "public"
// VisibleTypeLimited Visible for every connected user
VisibleTypeLimited VisibleType = "limited"
// VisibleTypePrivate Visible only for organization's members
VisibleTypePrivate VisibleType = "private"
)
// ListOrgsOptions options for listing organizations // ListOrgsOptions options for listing organizations
type ListOrgsOptions struct { type ListOrgsOptions struct {
ListOptions ListOptions
@ -55,13 +69,12 @@ type CreateOrgOption struct {
Description string `json:"description"` Description string `json:"description"`
Website string `json:"website"` Website string `json:"website"`
Location string `json:"location"` Location string `json:"location"`
// possible values are `public` (default), `limited` or `private` Visibility VisibleType `json:"visibility"`
Visibility string `json:"visibility"`
} }
// checkVisibilityOpt check if mode exist // checkVisibilityOpt check if mode exist
func checkVisibilityOpt(v string) bool { func checkVisibilityOpt(v VisibleType) bool {
return v == "public" || v == "limited" || v == "private" return v == VisibleTypePublic || v == VisibleTypeLimited || v == VisibleTypePrivate
} }
// Validate the CreateOrgOption struct // Validate the CreateOrgOption struct
@ -94,8 +107,7 @@ type EditOrgOption struct {
Description string `json:"description"` Description string `json:"description"`
Website string `json:"website"` Website string `json:"website"`
Location string `json:"location"` Location string `json:"location"`
// possible values are `public`, `limited` or `private` Visibility VisibleType `json:"visibility"`
Visibility string `json:"visibility"`
} }
// Validate the EditOrgOption struct // Validate the EditOrgOption struct

View file

@ -1,27 +0,0 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package gitea
// VisibleType defines the visibility (Organization only)
type VisibleType int
const (
// VisibleTypePublic Visible for everyone
VisibleTypePublic VisibleType = iota
// VisibleTypeLimited Visible for every connected user
VisibleTypeLimited
// VisibleTypePrivate Visible only for organization's members
VisibleTypePrivate
)
// ExtractKeysFromMapString provides a slice of keys from map
func ExtractKeysFromMapString(in map[string]VisibleType) (keys []string) {
for k := range in {
keys = append(keys, k)
}
return
}