Lunny Xiao
34283a74e8
Allow detect whether it's in a database transaction for a context.Context ( #21756 )
...
Fix #19513
This PR introduce a new db method `InTransaction(context.Context)`,
and also builtin check on `db.TxContext` and `db.WithTx`.
There is also a new method `db.AutoTx` has been introduced but could be used by other PRs.
`WithTx` will always open a new transaction, if a transaction exist in context, return an error.
`AutoTx` will try to open a new transaction if no transaction exist in context.
That means it will always enter a transaction if there is no error.
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: 6543 <6543@obermui.de>
2022-11-12 21:18:50 +01:00
delvh
0ebb45cfe7
Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) ( #21551 )
...
Found using
`find . -type f -name '*.go' -print -exec vim {} -c
':%s/fmt\.Errorf(\(.*\)%v\(.*\)err/fmt.Errorf(\1%w\2err/g' -c ':wq' \;`
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2022-10-24 20:29:17 +01:00
KN4CK3R
c3b2e44392
Add team member invite by email ( #20307 )
...
Allows to add (not registered) team members by email.
related #5353
Invite by mail:
![grafik](https://user-images.githubusercontent.com/1666336/178154779-adcc547f-c0b7-4a2a-a131-4e41a3d9d3ad.png )
Pending invitations:
![grafik](https://user-images.githubusercontent.com/1666336/178154882-9d739bb8-2b04-46c1-a025-c1f4be26af98.png )
Email:
![grafik](https://user-images.githubusercontent.com/1666336/178164716-f2f90893-7ba6-4a5e-a3db-42538a660258.png )
Join form:
![grafik](https://user-images.githubusercontent.com/1666336/178154840-aaab983a-d922-4414-b01a-9b1a19c5cef7.png )
Co-authored-by: Jack Hay <jjphay@gmail.com>
2022-10-19 14:40:28 +02:00
zeripath
716fcfcf72
Make every not exist error unwrappable to a fs.ErrNotExist ( #20891 )
...
A lot of our code is repeatedly testing if individual errors are
specific types of Not Exist errors. This is repetitative and unnecesary.
`Unwrap() error` provides a common way of labelling an error as a
NotExist error and we can/should use this.
This PR has chosen to use the common `io/fs` errors e.g.
`fs.ErrNotExist` for our errors. This is in some ways not completely
correct as these are not filesystem errors but it seems like a
reasonable thing to do and would allow us to simplify a lot of our code
to `errors.Is(err, fs.ErrNotExist)` instead of
`package.IsErr...NotExist(err)`
I am open to suggestions to use a different base error - perhaps
`models/db.ErrNotExist` if that would be felt to be better.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: delvh <dev.lh@web.de>
2022-10-18 07:50:37 +02:00
6543
c5e88fb03d
[API] teamSearch show teams with no members if user is admin ( #21204 )
...
close #21176
2022-09-19 20:02:29 +08:00
Lunny Xiao
1d8543e7db
Move some files into models' sub packages ( #20262 )
...
* Move some files into models' sub packages
* Move functions
* merge main branch
* Fix check
* fix check
* Fix some tests
* Fix lint
* Fix lint
* Revert lint changes
* Fix error comments
* Fix lint
Co-authored-by: 6543 <6543@obermui.de>
2022-08-25 10:31:57 +08:00
Gusted
0b4c166e8a
Fix SQL Query for SearchTeam
( #20844 )
...
- Currently the function takes in the `UserID` option, but isn't being
used within the SQL query. This patch fixes that by checking that only
teams are being returned that the user belongs to.
Fix #20829
Co-authored-by: delvh <dev.lh@web.de>
2022-08-21 17:24:05 +01:00
Lunny Xiao
86c85c19b6
Refactor AssertExistsAndLoadBean to use generics ( #20797 )
...
* Refactor AssertExistsAndLoadBean to use generics
* Fix tests
Co-authored-by: zeripath <art27@cantab.net>
2022-08-16 10:22:25 +08:00
Tyrone Yeh
931c02d152
Add order by for assignee no sort issue ( #20053 )
...
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2022-07-14 18:00:10 +02:00
luzpaz
d29d6d1991
Fix various typos ( #20338 )
...
* Fix various typos
Found via `codespell -q 3 -S ./options/locale,./options/license,./public/vendor -L actived,allways,attachements,ba,befores,commiter,pullrequest,pullrequests,readby,splitted,te,unknwon`
Co-authored-by: zeripath <art27@cantab.net>
2022-07-12 23:32:37 +02:00
Lunny Xiao
0649c54275
Adjust transaction handling via db.Context ( #20031 )
2022-06-20 14:38:58 +02:00
Wim
cb50375e2b
Add more linters to improve code readability ( #19989 )
...
Add nakedret, unconvert, wastedassign, stylecheck and nolintlint linters to improve code readability
- nakedret - https://github.com/alexkohler/nakedret - nakedret is a Go static analysis tool to find naked returns in functions greater than a specified function length.
- unconvert - https://github.com/mdempsky/unconvert - Remove unnecessary type conversions
- wastedassign - https://github.com/sanposhiho/wastedassign - wastedassign finds wasted assignment statements.
- notlintlint - Reports ill-formed or insufficient nolint directives
- stylecheck - https://staticcheck.io/docs/checks/#ST - keep style consistent
- excluded: [ST1003 - Poorly chosen identifier](https://staticcheck.io/docs/checks/#ST1003 ) and [ST1005 - Incorrectly formatted error string](https://staticcheck.io/docs/checks/#ST1005 )
2022-06-20 12:02:49 +02:00
Lunny Xiao
d91d4db344
Move tests as seperate sub packages to reduce duplicated file names ( #19951 )
2022-06-15 09:02:00 +02:00
Lunny Xiao
fd7d83ace6
Move almost all functions' parameter db.Engine to context.Context ( #19748 )
...
* Move almost all functions' parameter db.Engine to context.Context
* remove some unnecessary wrap functions
2022-05-20 22:08:52 +08:00
Lunny Xiao
d81e31ad78
Move org functions ( #19753 )
...
* Move org functions
* Fix comment
2022-05-20 12:20:51 +02:00
zuzuviewer
77e9346342
Fix duplicate entry error when add team member ( #19702 )
2022-05-14 16:30:19 +03:00
6543
06e4687cec
more context for models ( #19511 )
...
make more usage of context, to have more db transaction in one session
(make diff of #9307 smaller)
2022-04-28 13:48:48 +02:00
qwerty287
ae6a52440a
Fix panic in team repos API ( #19431 )
...
* Fix panic in team repos API
* Fix pagination
* fmt
2022-04-20 18:43:26 +08:00
Lunny Xiao
b8911fb456
Use a struct as test options ( #19393 )
...
* Use a struct as test options
* Fix name
* Fix test
2022-04-14 21:58:21 +08:00
Lunny Xiao
89b9d42f08
Fix broken of team create ( #19288 )
...
* Fix broken of team create
* Update models/organization/team.go
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2022-04-01 14:05:31 +08:00
6543
3e88af898a
Make git.OpenRepository accept Context ( #19260 )
...
* OpenRepositoryCtx -> OpenRepository
* OpenRepository -> openRepositoryWithDefaultContext, only for internal usage
2022-03-30 03:13:41 +08:00
Lunny Xiao
b06b9a056c
Move organization related structs into sub package ( #18518 )
...
* Move organization related structs into sub package
* Fix test
* Fix lint
* Move more functions into sub packages
* Fix bug
* Fix test
* Update models/organization/team_repo.go
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
* Apply suggestions from code review
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
* Fix fmt
* Follow suggestion from @Gusted
* Fix test
* Fix test
* Fix bug
* Use ctx but db.DefaultContext on routers
* Fix bug
* Fix bug
* fix bug
* Update models/organization/team_user.go
* Fix bug
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2022-03-29 14:29:02 +08:00