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.

41 lines
935 B

  1. // Copyright 2014 The Gogs 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 models
  5. import (
  6. "strings"
  7. "time"
  8. )
  9. // Access types.
  10. const (
  11. AU_READABLE = iota + 1
  12. AU_WRITABLE
  13. )
  14. // Access represents the accessibility of user and repository.
  15. type Access struct {
  16. Id int64
  17. UserName string `xorm:"unique(s)"`
  18. RepoName string `xorm:"unique(s)"`
  19. Mode int `xorm:"unique(s)"`
  20. Created time.Time `xorm:"created"`
  21. }
  22. // AddAccess adds new access record.
  23. func AddAccess(access *Access) error {
  24. _, err := orm.Insert(access)
  25. return err
  26. }
  27. // HasAccess returns true if someone can read or write given repository.
  28. func HasAccess(userName, repoName string, mode int) (bool, error) {
  29. return orm.Get(&Access{
  30. Id: 0,
  31. UserName: strings.ToLower(userName),
  32. RepoName: strings.ToLower(repoName),
  33. Mode: mode,
  34. })
  35. }