From d99f4ab0035631aacc44739af0a936e59daf83b7 Mon Sep 17 00:00:00 2001 From: Antoine GIRARD Date: Tue, 28 Nov 2017 21:58:37 +0100 Subject: Git LFS lock api (#2938) * Implement routes * move to api/sdk and create model * Implement add + list * List return 200 empty list no 404 * Add verify lfs lock api * Add delete and start implementing auth control * Revert to code.gitea.io/sdk/gitea vendor * Apply needed check for all lfs locks route * Add simple tests * fix lint * Improve tests * Add delete test + fix * Add lfs ascii header * Various fixes from review + remove useless code + add more corner case testing * Remove repo link since only id is needed. Save a little of memory and cpu time. * Improve tests * Use TEXT column format for path + test * fix mispell * Use NewRequestWithJSON for POST tests * Clean path * Improve DB format * Revert uniquess repoid+path * (Re)-setup uniqueness + max path length * Fixed TEXT in place of VARCHAR * Settle back to maximum VARCHAR(3072) * Let place for repoid in key * Let place for repoid in key * Let place for repoid in key * Revert back --- models/error.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'models/error.go') diff --git a/models/error.go b/models/error.go index 7ea4e9e2f2..50d9cba171 100644 --- a/models/error.go +++ b/models/error.go @@ -506,6 +506,63 @@ func (err ErrLastOrgOwner) Error() string { return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID) } +//.____ ____________________ +//| | \_ _____/ _____/ +//| | | __) \_____ \ +//| |___| \ / \ +//|_______ \___ / /_______ / +// \/ \/ \/ + +// ErrLFSLockNotExist represents a "LFSLockNotExist" kind of error. +type ErrLFSLockNotExist struct { + ID int64 + RepoID int64 + Path string +} + +// IsErrLFSLockNotExist checks if an error is a ErrLFSLockNotExist. +func IsErrLFSLockNotExist(err error) bool { + _, ok := err.(ErrLFSLockNotExist) + return ok +} + +func (err ErrLFSLockNotExist) Error() string { + return fmt.Sprintf("lfs lock does not exist [id: %d, rid: %d, path: %s]", err.ID, err.RepoID, err.Path) +} + +// ErrLFSLockUnauthorizedAction represents a "LFSLockUnauthorizedAction" kind of error. +type ErrLFSLockUnauthorizedAction struct { + RepoID int64 + UserName string + Action string +} + +// IsErrLFSLockUnauthorizedAction checks if an error is a ErrLFSLockUnauthorizedAction. +func IsErrLFSLockUnauthorizedAction(err error) bool { + _, ok := err.(ErrLFSLockUnauthorizedAction) + return ok +} + +func (err ErrLFSLockUnauthorizedAction) Error() string { + return fmt.Sprintf("User %s doesn't have rigth to %s for lfs lock [rid: %d]", err.UserName, err.Action, err.RepoID) +} + +// ErrLFSLockAlreadyExist represents a "LFSLockAlreadyExist" kind of error. +type ErrLFSLockAlreadyExist struct { + RepoID int64 + Path string +} + +// IsErrLFSLockAlreadyExist checks if an error is a ErrLFSLockAlreadyExist. +func IsErrLFSLockAlreadyExist(err error) bool { + _, ok := err.(ErrLFSLockAlreadyExist) + return ok +} + +func (err ErrLFSLockAlreadyExist) Error() string { + return fmt.Sprintf("lfs lock already exists [rid: %d, path: %s]", err.RepoID, err.Path) +} + // __________ .__ __ // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | | -- cgit v1.2.3