summaryrefslogtreecommitdiffstats
path: root/models
Commit message (Collapse)AuthorAgeFilesLines
* Fix offBy1 errors (#17606)Gusted2021-11-141-1/+8
| | | | | | | | | | | | | | | | | | | | | * Fix offBy1 errors - Partially resolves #17596 - Resolve errors from go-critic `offBy1: Index() can return -1; maybe you wanted to do Index()+1`. * Match golang spec * Remove comments * Update migrations.go * Apply suggestions from code review Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Decouple unit test code from business code (#17623)wxiaoguang2021-11-1270-648/+791
|
* unbind the CheckConsistency for some structs so that they can be moved to ↵Lunny Xiao2021-11-121-20/+33
| | | | | | | | | sub packages easier (#17612) * unbind the CheckConsistency for some structs so that they can be moved to sub packages easier * Fix functions name * Fix typo
* Move EmailAddress & UserRedirect into models/user/ (#17607)Lunny Xiao2021-11-1116-592/+652
| | | | | | | | | | | | | | | | | | | | | * Move EmailAddress into models/user/ * Fix test * rename user_mail to user_email * Fix test * Move UserRedirect into models/user/ * Fix lint & test * Fix lint * Fix lint * remove nolint comment * Fix lint
* Refactor commentTags functionality (#17558)Gusted2021-11-112-9/+35
| | | | | | | | | | | | | | | | | | | | | | | | * feat: Allow multiple tags on comments - Allow for multiples tags(Currently Poster + {Owner, Writer}). - Utilize the Poster tag within the commentTag function and remove the checking from templates. - Use bitwise on CommentTags to enable specific tags. - Don't show poster tag(view_content.tmpl) on the initial issue comment. * Change parameters naming * Change function name * refactor variable wording * Merge 'master' branch into 'tags-comments' branch * Change naming * `tag` -> `role` Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Move oauth2 error to oauth2 service package (#17603)Lunny Xiao2021-11-111-24/+0
|
* Fix 500 when a comment was deleted which has a notification (#17550)Lunny Xiao2021-11-101-2/+8
| | | | | | | | | | * Fix 500 when a comment was deleted which has a notification * Tolerate missing Comment in other places too Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Andrew Thornton <art27@cantab.net> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Move webhook into models/webhook/ (#17579)Lunny Xiao2021-11-1011-338/+376
|
* Added GetUserByIDCtx. (#17602)KN4CK3R2021-11-093-5/+10
| | | Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Move unit into models/unit/ (#17576)Lunny Xiao2021-11-0923-191/+215
| | | | | * Move unit into models/unit/ * Rename unit.UnitType as unit.Type
* Update `User` model comments about permissions (#17583)wxiaoguang2021-11-091-5/+12
|
* Use provided database Engine (#17595)Gusted2021-11-092-2/+2
| | | | - Don't get the engine from `db.DefaultContext`, instead use the provided one which is passed as paramater `e`.
* Allow U2F 2FA without TOTP (#11573)Kamil Domański2021-11-086-4/+31
| | | | | | | This change enables the usage of U2F without being forced to enroll an TOTP authenticator. The `/user/auth/u2f` has been changed to hide the "use TOTP instead" bar if TOTP is not enrolled. Fixes #5410 Fixes #17495
* Fix stats upon searching issues (#17566)Gusted2021-11-082-5/+45
| | | | | | | | | | | * Fix stat chunks searching - Fixes a issue whereby the given chunk of issueIDs wasn't respected and thus the returned results where not the correct results. * Add tests Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: zeripath <art27@cantab.net>
* Only allow returned deleted branche to be on repo (#17570)Gusted2021-11-082-1/+26
| | | | | | | - This will only allow `GetDeletedBranchByID` to return deletedBranch which are on the repo, and thus don't return a deletedBranch from another repo. - This just should prevent possible bugs in the futher when a code is passing the wrong ID into this function.
* Avoid double imports (#17569)Gusted2021-11-081-3/+2
| | | | | Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Fix bug on admin subcommand (#17533)Lunny Xiao2021-11-071-41/+14
| | | | | | | * Fix bug on admin subcommand * Add signals for all initDB Co-authored-by: Lauris BH <lauris@nix.lv>
* Fix database keyword quote problem on migration v161 (#17522)Lunny Xiao2021-11-051-1/+12
| | | | | | * support rerun migration v161 Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
* Simplify Gothic to use our session store instead of creating a different ↵zeripath2021-11-032-19/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | store (#17507) * Simplify Gothic to use our session store instead of creating a different store We have been using xormstore to provide a separate session store for our OAuth2 logins however, this relies on using gorilla context and some doubling of our session storing. We can however, simplify and simply use our own chi-based session store. Thus removing a cookie and some of the weirdness with missing contexts. Signed-off-by: Andrew Thornton <art27@cantab.net> * as per review Signed-off-by: Andrew Thornton <art27@cantab.net> * as per review Signed-off-by: Andrew Thornton <art27@cantab.net> * Handle MaxTokenLength Signed-off-by: Andrew Thornton <art27@cantab.net> * oops Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: Lauris BH <lauris@nix.lv>
* Rename db Engines related functions (#17481)Lunny Xiao2021-10-302-15/+15
| | | | | * Rename db Engines related functions Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Quote the table name in CountOrphanedObjects (#17487)zeripath2021-10-301-1/+1
| | | | | | | | | CountOrphanedObjects needs to quote the table it is joining with as this table may be `user`. Fix #17485 Signed-off-by: Andrew Thornton <art27@cantab.net>
* Run Migrate in Install rather than just SyncTables (#17475)zeripath2021-10-291-3/+22
| | | | | | | | | | | | | | | | | | * Run Migrate in Install rather than just SyncTables The underlying problem in #17328 appears to be that users are re-running the install page during upgrades. The function that tests and creates the db did not intend for this and thus instead the migration scripts being run - a simple sync tables occurs. This then causes a weird partially migrated DB which causes, in this release cycle, the duplicate column in task table error. It is likely the cause of some weird partial migration errors in other cycles too. This PR simply ensures that the migration scripts are also run at this point too. Fix #17328 Signed-off-by: Andrew Thornton <art27@cantab.net>
* Ensure that restricted users can access repos for which they are members ↵zeripath2021-10-281-2/+2
| | | | | | | | | | | | | | | | | (#17460) There is a small bug in the way that repo access is checked in repoAssignment: Accessibility is checked by checking if the user has a marked access to the repository instead of checking if the user has any team granted access. This PR changes this permissions check to use HasAccess() which does the correct test. There is also a fix in the release api ListReleases where it should return draft releases if the user is a member of a team with write access to the releases. The PR also adds a testcase. Signed-off-by: Andrew Thornton <art27@cantab.net>
* In many cases user avatar link should be an absolute URL with http host (#17420)wxiaoguang2021-10-251-2/+7
|
* Fix issue content history problems, improve UI (#17404)wxiaoguang2021-10-232-2/+3
| | | | | * Improve: make diff result better, make the HTML element fit the full height in the content history diff dialog * Bug fix: when edit the main issue, the poster is wrongly set to the issue poster
* Refactor update checker to use AppState (#17387)wxiaoguang2021-10-214-133/+20
| | | | | | | | We have the `AppState` module now, it can store app related data easily. We do not need to create separate tables for each feature. So the update checker can use `AppState` instead of a one-row dedicate table. And the code of update checker is moved from `models` to `modules`.
* Fix history count failure (#17351)Lunny Xiao2021-10-211-1/+1
| | | Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Sync gitea app path for git hooks and authorized keys when starting (#17335)wxiaoguang2021-10-213-0/+82
| | | | | | | | | | | Gitea writes its own AppPath into git hook scripts. If Gitea's AppPath changes, then the git push will fail. This PR: * Introduce an AppState module, it can persist app states into database * During GlobalInit, Gitea will check if the current AppPath is the same as last one. If they don't match, Gitea will sync git hooks. * Refactor some code to make them more clear. * Also, "Detect if gitea binary's name changed" #11341 is related, we call models.RewriteAllPublicKeys to update ssh authorized_keys file
* Use a variable but a function for IsProd because of a slight performance ↵Lunny Xiao2021-10-201-2/+2
| | | | increment (#17368)
* Allow mocking timeutil (#17354)John Olheiser2021-10-181-0/+6
| | | Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Move session to models/login (#17338)Lunny Xiao2021-10-171-1/+1
| | | Move model/session.go to models/login
* Add simple update checker to Gitea (#17212)techknowlogick2021-10-163-0/+146
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add simple update checker to Gitea * update struct and remove comments * fix lint * Update custom/conf/app.example.ini * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md Co-authored-by: delvh <dev.lh@web.de> * Update custom/conf/app.example.ini Co-authored-by: delvh <dev.lh@web.de> * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md Co-authored-by: delvh <dev.lh@web.de> * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md Co-authored-by: Steven <61625851+justusbunsi@users.noreply.github.com> * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md * Update modules/cron/tasks_extended.go Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> * Update custom/conf/app.example.ini Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> * take PR feedback into account and display banner on admin dashboard for alerts * Add more detailed message * placate lint * update per feedback Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Steven <61625851+justusbunsi@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Don't panic if we fail to parse U2FRegistration data (#17304)David Jimenez2021-10-142-1/+27
| | | | | | | | | * Don't panic if we fail to parse a U2FRegistration data Downgrade logging statement from Fatal to Error so that errors parsing U2FRegistration data does not panic; instead, the invalid key will be skipped and we will attempt to parse the next one, if available. Signed-off-by: David Jimenez <dvejmz@sgfault.com>
* Ensure that git daemon export ok is created for mirrors (#17243)zeripath2021-10-132-26/+41
| | | | | | | | | | | | | * Ensure that git daemon export ok is created for mirrors There is an issue with #16508 where it appears that create repo requires that the repo does not exist. This causes #17241 where an error is reported because of this. This PR fixes this and also runs update-server-info for mirrors and generated repos. Fix #17241 Signed-off-by: Andrew Thornton <art27@cantab.net>
* Add user status filter to admin user management page (#16770)wxiaoguang2021-10-123-9/+57
| | | | | | | | | | | | | | | | | | | | It makes Admin's life easier to filter users by various status. * introduce window.config.PageData to pass template data to javascript module and small refactor move legacy window.ActivityTopAuthors to window.config.PageData.ActivityTopAuthors make HTML structure more IDE-friendly in footer.tmpl and head.tmpl remove incorrect <style class="list-search-style"></style> in head.tmpl use log.Error instead of log.Critical in admin user search * use LEFT JOIN instead of SubQuery when admin filters users by 2fa. revert non-en locale. * use OptionalBool instead of status map * refactor SearchUserOptions.toConds to SearchUserOptions.toSearchQueryBase * add unit test for user search * only allow admin to use filters to search users
* [API] Add endpount to get user org permissions (#17232)Romain2021-10-121-0/+13
| | | | | | | | | | | | * Add endpoint * Add swagger response + generate swagger * Stop execution if user / org is not found * Add tests Co-authored-by: 6543 <6543@obermui.de>
* Save and view issue/comment content history (#16909)wxiaoguang2021-10-108-3/+385
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * issue content history * Use timeutil.TimeStampNow() for content history time instead of issue/comment.UpdatedUnix (which are not updated in time) * i18n for frontend * refactor * clean up * fix refactor * re-format * temp refactor * follow db refactor * rename IssueContentHistory to ContentHistory, remove empty model tags * fix html * use avatar refactor to generate avatar url * add unit test, keep at most 20 history revisions. * re-format * syntax nit * Add issue content history table * Update models/migrations/v197.go Co-authored-by: 6543 <6543@obermui.de> * fix merge Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lauris BH <lauris@nix.lv>
* Add a simple way to rename branch like gh (#15870)a10121127962021-10-085-0/+157
| | | | | | | | | | - Update default branch if needed - Update protected branch if needed - Update all not merged pull request base branch name - Rename git branch - Record this rename work and auto redirect for old branch on ui Signed-off-by: a1012112796 <1012112796@qq.com> Co-authored-by: delvh <dev.lh@web.de>
* Fix incorrect repository count on organization tab of dashboard (#17256)Jimmy Praet2021-10-081-1/+1
| | | Fixes #17249
* Fix unwanted team review request deletion (#17257)Jimmy Praet2021-10-071-1/+1
| | | | Add missing issue_id = ? to where clause Fixes #17251
* Handle duplicate keys on GPG key ring (#17242)zeripath2021-10-071-0/+40
| | | | | | | | | | It is possible that a keyring can contain duplicate keys on a keyring due to jpegs or other layers. This currently leads to a confusing error for the user - where we report a duplicate key insertion. This PR simply coalesces keys into one key if there are duplicates. Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de>
* Fix broken Activities link in team dashboard (#17255)Jimmy Praet2021-10-071-1/+1
| | | | | Remove '/' suffix from organization dashboard link Fixes #17250
* Fix problem when database ID is not incremented as expected (#17229)finga2021-10-063-3/+3
| | | | | | Although #17124 fixed the same issue for the feed, some other parts with the same issue were found. Co-authored-by: finga <finga@onders.org>
* Avatar refactor, move avatar code from `models` to `models.avatars`, remove ↵wxiaoguang2021-10-064-194/+205
| | | | | | | | | | | | | | | | duplicated code (#17123) Why this refactor The goal is to move most files from `models` package to `models.xxx` package. Many models depend on avatar model, so just move this first. And the existing logic is not clear, there are too many function like `AvatarLink`, `RelAvatarLink`, `SizedRelAvatarLink`, `SizedAvatarLink`, `MakeFinalAvatarURL`, `HashedAvatarLink`, etc. This refactor make everything clear: * user.AvatarLink() * user.AvatarLinkWithSize(size) * avatars.GenerateEmailAvatarFastLink(email, size) * avatars.GenerateEmailAvatarFinalLink(email, size) And many duplicated code are deleted in route handler, the handler and the model share the same avatar logic now.
* Add metrics to get issues by repository (#17225)Romain2021-10-051-1/+19
|
* Fix stange behavior of DownloadPullDiffOrPatch in incorect index (#17223)pricly-yellow2021-10-052-0/+7
| | | | | | | Fix GetPullRequestByIndex by validate index > 1 Signed-off-by: Danila Kryukov <pricly_yellow@dismail.de> Co-authored-by: a1012112796 <1012112796@qq.com>
* Add metrics to get issues by label (#17201)Romain2021-10-031-0/+19
| | | | | | | | | | | | | | | | | | | | | * Add metrics to get issues by label * Add comment on IssueByLabelCount * Code review - Unify "AS" in SQL (#17201) * Code review - Remove useless join (#17201) * Code review - Disable issue_by_label by default in settings (#17201) * use e * restore empty line * update docs Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
* Add projects and project boards in exposed metrics (#17202)Romain2021-10-021-17/+21
| | | | | | | * Add projects and project boards in exposed metrics * Refactor db.GetEngine Co-authored-by: delvh <dev.lh@web.de>
* Always set a unique Message-ID header. (#17206)KN4CK3R2021-10-011-13/+0
|
* Kanban colored boards (#16647)Romain2021-09-293-2/+42
| | | Add a column Color in ProjectBoard and color picker in new / edit project board form.