Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit 13a7bf6

Browse files
lunnylafriks
authored andcommitted
move organization visibility from gitea to SDK and add it on CreateOptions (#165)
1 parent 2858b80 commit 13a7bf6

File tree

2 files changed

+63
-12
lines changed

2 files changed

+63
-12
lines changed

gitea/org.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import (
1212

1313
// Organization represents an organization
1414
type Organization struct {
15-
ID int64 `json:"id"`
16-
UserName string `json:"username"`
17-
FullName string `json:"full_name"`
18-
AvatarURL string `json:"avatar_url"`
19-
Description string `json:"description"`
20-
Website string `json:"website"`
21-
Location string `json:"location"`
15+
ID int64 `json:"id"`
16+
UserName string `json:"username"`
17+
FullName string `json:"full_name"`
18+
AvatarURL string `json:"avatar_url"`
19+
Description string `json:"description"`
20+
Website string `json:"website"`
21+
Location string `json:"location"`
22+
Visibility VisibleType `json:"visibility"`
2223
}
2324

2425
// ListMyOrgs list all of current user's organizations
@@ -42,11 +43,12 @@ func (c *Client) GetOrg(orgname string) (*Organization, error) {
4243
// CreateOrgOption options for creating an organization
4344
type CreateOrgOption struct {
4445
// required: true
45-
UserName string `json:"username" binding:"Required"`
46-
FullName string `json:"full_name"`
47-
Description string `json:"description"`
48-
Website string `json:"website"`
49-
Location string `json:"location"`
46+
UserName string `json:"username" binding:"Required"`
47+
FullName string `json:"full_name"`
48+
Description string `json:"description"`
49+
Website string `json:"website"`
50+
Location string `json:"location"`
51+
Visibility VisibleType `json:"visibility"`
5052
}
5153

5254
// EditOrgOption options for editing an organization

gitea/org_type.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2019 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package gitea
6+
7+
// VisibleType defines the visibility (Organization only)
8+
type VisibleType int
9+
10+
const (
11+
// VisibleTypePublic Visible for everyone
12+
VisibleTypePublic VisibleType = iota
13+
14+
// VisibleTypeLimited Visible for every connected user
15+
VisibleTypeLimited
16+
17+
// VisibleTypePrivate Visible only for organization's members
18+
VisibleTypePrivate
19+
)
20+
21+
// VisibilityModes is a map of org Visibility types
22+
var VisibilityModes = map[string]VisibleType{
23+
"public": VisibleTypePublic,
24+
"limited": VisibleTypeLimited,
25+
"private": VisibleTypePrivate,
26+
}
27+
28+
// IsPublic returns true if VisibleType is public
29+
func (vt VisibleType) IsPublic() bool {
30+
return vt == VisibleTypePublic
31+
}
32+
33+
// IsLimited returns true if VisibleType is limited
34+
func (vt VisibleType) IsLimited() bool {
35+
return vt == VisibleTypeLimited
36+
}
37+
38+
// IsPrivate returns true if VisibleType is private
39+
func (vt VisibleType) IsPrivate() bool {
40+
return vt == VisibleTypePrivate
41+
}
42+
43+
// ExtractKeysFromMapString provides a slice of keys from map
44+
func ExtractKeysFromMapString(in map[string]VisibleType) (keys []string) {
45+
for k := range in {
46+
keys = append(keys, k)
47+
}
48+
return
49+
}

0 commit comments

Comments
 (0)