code.gitea.io/gitea@v1.19.3/modules/structs/visible_type.go (about) 1 // Copyright 2019 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package structs 5 6 // VisibleType defines the visibility of user and org 7 type VisibleType int 8 9 const ( 10 // VisibleTypePublic Visible for everyone 11 VisibleTypePublic VisibleType = iota 12 13 // VisibleTypeLimited Visible for every connected user 14 VisibleTypeLimited 15 16 // VisibleTypePrivate Visible only for self or admin user 17 VisibleTypePrivate 18 ) 19 20 // VisibilityModes is a map of Visibility types 21 var VisibilityModes = map[string]VisibleType{ 22 "public": VisibleTypePublic, 23 "limited": VisibleTypeLimited, 24 "private": VisibleTypePrivate, 25 } 26 27 // IsPublic returns true if VisibleType is public 28 func (vt VisibleType) IsPublic() bool { 29 return vt == VisibleTypePublic 30 } 31 32 // IsLimited returns true if VisibleType is limited 33 func (vt VisibleType) IsLimited() bool { 34 return vt == VisibleTypeLimited 35 } 36 37 // IsPrivate returns true if VisibleType is private 38 func (vt VisibleType) IsPrivate() bool { 39 return vt == VisibleTypePrivate 40 } 41 42 // VisibilityString provides the mode string of the visibility type (public, limited, private) 43 func (vt VisibleType) String() string { 44 for k, v := range VisibilityModes { 45 if vt == v { 46 return k 47 } 48 } 49 return "" 50 } 51 52 // ExtractKeysFromMapString provides a slice of keys from map 53 func ExtractKeysFromMapString(in map[string]VisibleType) (keys []string) { 54 for k := range in { 55 keys = append(keys, k) 56 } 57 return keys 58 }