You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

org_type.go 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. package structs
  5. // VisibleType defines the visibility (Organization only)
  6. type VisibleType int
  7. const (
  8. // VisibleTypePublic Visible for everyone
  9. VisibleTypePublic VisibleType = iota
  10. // VisibleTypeLimited Visible for every connected user
  11. VisibleTypeLimited
  12. // VisibleTypePrivate Visible only for organization's members
  13. VisibleTypePrivate
  14. )
  15. // VisibilityModes is a map of org Visibility types
  16. var VisibilityModes = map[string]VisibleType{
  17. "public": VisibleTypePublic,
  18. "limited": VisibleTypeLimited,
  19. "private": VisibleTypePrivate,
  20. }
  21. // IsPublic returns true if VisibleType is public
  22. func (vt VisibleType) IsPublic() bool {
  23. return vt == VisibleTypePublic
  24. }
  25. // IsLimited returns true if VisibleType is limited
  26. func (vt VisibleType) IsLimited() bool {
  27. return vt == VisibleTypeLimited
  28. }
  29. // IsPrivate returns true if VisibleType is private
  30. func (vt VisibleType) IsPrivate() bool {
  31. return vt == VisibleTypePrivate
  32. }
  33. // VisibilityString provides the mode string of the visibility type (public, limited, private)
  34. func (vt VisibleType) String() string {
  35. for k, v := range VisibilityModes {
  36. if vt == v {
  37. return k
  38. }
  39. }
  40. return ""
  41. }
  42. // ExtractKeysFromMapString provides a slice of keys from map
  43. func ExtractKeysFromMapString(in map[string]VisibleType) (keys []string) {
  44. for k := range in {
  45. keys = append(keys, k)
  46. }
  47. return
  48. }