summaryrefslogtreecommitdiffstats
path: root/models
Commit message (Collapse)AuthorAgeFilesLines
* Check if column exist before rename if exist, just return with no error ↵Lunny Xiao2021-12-021-0/+24
| | | | | | | | | | | (#17870) (#17882) * Check if column exist before rename if exist, just return with no error * Also check if errors column exist * Add comment for migration * Fix sqlite test
* fix 500 error while use a reserved name in org rename (#17878) (#17881)a10121127962021-12-021-3/+0
| | | | | fix #17876 Signed-off-by: a1012112796 <1012112796@qq.com>
* Fix user primary email changed (#17840)Lunny Xiao2021-11-282-7/+35
|
* Fix close issue but time watcher still running (#17761)Lunny Xiao2021-11-231-56/+126
| | | | | | | | | * Fix bug * Update models/issue_stopwatch.go Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: zeripath <art27@cantab.net>
* Fix bug when project board get open issue number (#17703) (#17726)Lunny Xiao2021-11-191-1/+3
| | | | | | | Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
* Fix golangci-lint warnings (#17598 et al) (#17668)Gusted2021-11-161-1/+8
| | | | | | | | | Backport #17598 Backport #17606 Backport #17608 Backport #17609 - Since https://gitea.com/gitea/test-env/pulls/10 the golangci-lint has been upgraded and is erroring about new warnings in the code, this PR fixes those warnings.
* backport(1.15): Fix stats upon searching issues (#17578)Gusted2021-11-082-5/+47
| | | | | | - Backport of https://github.com/go-gitea/gitea/pull/17566 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: zeripath <art27@cantab.net>
* Fix database keyword quote problem on migration v161 (#17523)Lunny Xiao2021-11-031-1/+12
| | | * support rerun migration v161
* Quote the table name in CountOrphanedObjects (#17487) (#17488)zeripath2021-10-301-1/+1
| | | | | | | | | | Backport #17487 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) (#17486)zeripath2021-10-301-3/+22
| | | | | | | | | | | | | | | | | Backport #17475 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) (#17464) Backport #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>
* Don't panic if we fail to parse U2FRegistration data (#17304) (#17371)zeripath2021-10-202-1/+27
| | | | | | | | | | | Backport #17304 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> Co-authored-by: David Jimenez <dvejmz@users.noreply.github.com>
* Allow mocking timeutil (#17354) (#17356)John Olheiser2021-10-181-0/+7
| | | Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Ensure that git daemon export ok is created for mirrors (#17243) (#17306)zeripath2021-10-141-26/+41
| | | | | | | | | | | | Backport #17243 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>
* Handle duplicate keys on GPG key ring (#17242) (#17284)zeripath2021-10-111-0/+40
| | | | | | | | | | | | | | Backport #17242 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> Co-authored-by: 6543 <6543@obermui.de>
* Fix incorrect repository count on organization tab of dashboard (#17266)Jimmy Praet2021-10-081-1/+1
| | | Fixes #17249
* Fix unwanted team review request deletion (#17257) (#17264)Jimmy Praet2021-10-071-1/+1
| | | | Add missing issue_id = ? to where clause Fixes #17251
* Fix broken Activities link in team dashboard (#17255) (#17258)Jimmy Praet2021-10-071-1/+1
| | | | | Remove '/' suffix from organization dashboard link Fixes #17250
* Fix stange behavior of DownloadPullDiffOrPatch in incorect index (#17223) ↵pricly-yellow2021-10-052-0/+7
| | | | | | | | (#17227) Fix GetPullRequestByIndex by validate index > 1 Signed-off-by: Danila Kryukov <pricly_yellow@dismail.de> Co-authored-by: a1012112796 <1012112796@qq.com>
* Nicely handle missing user in collaborations (#17049) (#17166)zeripath2021-09-283-5/+23
| | | | | | | | | | | | | | | | | Backport #17049 It is possible to have a collaboration in a repository which refers to a no-longer existing user. This causes the repository transfer to fail with an unusual error. This PR makes `repo.getCollaborators()` nicely handle the missing user by ghosting the collaboration but also adds consistency check. It also adds an Access consistency check. Fix #17044 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
* Create doctor command to fix repo_units broken by dumps from 1.14.3-1.14.6 ↵zeripath2021-09-272-13/+19
| | | | | | | | | | | | | | | | | | (#17136) (#17137) Backport #17136 There was a serious issue with the `gitea dump` command in 1.14.3-1.14.6 which led to corruption of the `config` field of the `repo_unit` table. This PR adds a doctor command to attempt to fix the broken repo_units. Users affected by #16961 should run: ``` gitea doctor --fix --run fix-broken-repo-units ``` Fix #16961 Signed-off-by: Andrew Thornton <art27@cantab.net>
* Correctly rollback in ForkRepository (#17034) (#17045)zeripath2021-09-151-5/+2
| | | | | | | | | | | | | | | | | Backport #17034 The rollback functionality in services/repository/repository.go:ForkRepository is incorrect and could lead to a deadlock as it uses DeleteRepository to delete the rolled-back repository - a function which creates its own transaction. This PR adjusts the rollback function to only use RemoveAll as any database changes will be automatically rolled-back. It also handles panics and adjusts the Close within WithTx to ensure that if there is a panic the session will always be closed. Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Decrement Fork Num when converting from Fork (#17035) (#17046)zeripath2021-09-151-0/+6
| | | | | | | | | | Backport #17035 When converting repositories from forks to normal the root NumFork needs to be decremented too. Fix #17026 Signed-off-by: Andrew Thornton <art27@cantab.net>
* Skip AllowedUserVisibilityModes validation on update user if it is an ↵65432021-09-081-2/+2
| | | | | | | | | organisation (#16988) (#16990) if AllowedUserVisibilityModes allow only public & limited, and orgs can be private, a user can create a repo to that organisation whitch will result in an update of the user. On this call the user is validaten and will be rejected since private is not allowed, but its not an user its an valid org ... Co-authored-by: Alexey 〒erentyev <axifnx@gmail.com> Co-authored-by: Alexey 〒erentyev <axifnx@gmail.com>
* Fix storage Iterate bug and Add storage doctor to delete garbage attachments ↵Lunny Xiao2021-09-071-0/+5
| | | | | | | | | (#16971) (#16977) * Fix storage Iterate bug and Add storage doctor to delete garbage attachments * Close object when used
* Add unique constraint back into issue_index (#16938)zeripath2021-09-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | There is a flaw in #16820 where it was missed that although xorm will not add a primary key to a table during syncing, it will remove an unique constraint. Users upgrading from 1.15.0 to 1.15.1 will therefore lose the unique constraint that makes this table work unless they run `gitea doctor recreate-table issue_index`. Postgres helpfully warns about this situation but MySQL does not. Main/1.16-dev is not affected by this issue as there is a migration that does the above recreation by default. Users moving directly to 1.15.1 from 1.14.x or lower are also not affected. Whilst we could force all users who ran 1.15.0 to do the above recreate-table call, this PR proposes an alternative: Just add the unique constraint back in for 1.15.x. This won't have any long term effects - just some wasted space for the unnecessary index. Fix #16936 Signed-off-by: Andrew Thornton <art27@cantab.net>
* Correctly return the number of Repositories for Organizations (#16807) (#16911)zeripath2021-09-011-12/+56
| | | | | | | | | | | | | | Backport #16807 Calculate and return the number of Repositories on the dashboard Organization list. This PR restores some of the logic that was removed in #14032 to calculate the number of repos on the dashboard orgs list. Fix #16648 Replaces #16799 Signed-off-by: Andrew Thornton <art27@cantab.net>
* Fix dump and restore respository (#16698) (#16898)Lunny Xiao2021-08-311-0/+5
| | | | | | | | | | * Fix dump and restore * return different error message for get commit * Fix missing delete release attachment when deleting repository * Fix ci and add some comments back port #16698 Co-authored-by: zeripath <art27@cantab.net>
* Upgrade xorm to v1.2.2 (#16663) & Add test to ensure that dumping of login ↵zeripath2021-08-282-1/+27
| | | | | | | | | | | | | | | | | | sources remains correct (#16847) (#16848) * Upgrade xorm to v1.2.2 (#16663) Backport #16663 Fix #16683 * Add test to ensure that dumping of login sources remains correct (#16847) #16831 has occurred because of a missed regression. This PR adds a simple test to try to prevent this occuring again. Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Add primary_key to issue_index (#16813) (#16820)zeripath2021-08-253-5/+5
| | | | | | | | | | | | | | | | | | | | Backport #16813 Make the group_id a primary key in issue_index. This already has an unique index and therefore is a good candidate for becoming a primary key. This PR also changes all other uses of this table to add the group_id as the primary key. The migration v192 from #16813 has not been backported but Xorm will work fine with non-primary keyed tables. If a user on 1.15 wishes to have the correct schema sooner than 1.16 - they can use gitea doctor recreate-table issue_index and gitea will recreate the table with the primary key. Fix #16802 Signed-off-by: Andrew Thornton art27@cantab.net
* Recreate Tables should Recreate indexes on MySQL (#16718) (#16739)zeripath2021-08-201-0/+15
| | | | | | | | The MySQL indexes are not being renamed at the same time as RENAME table despite the CASCADE. Therefore it is probably better to just recreate the indexes instead. Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
* Fix wrong user in OpenID response (#16736) (#16741)KN4CK3R2021-08-201-0/+16
| | | | | | | | | | | * Fix wrong user in OpenID response (#16736) * Fixed usage of wrong user. * Added tests. * Fixed wrong import. Co-authored-by: techknowlogick <techknowlogick@gitea.io>
* Update issue_index to finish migration (#16685) (#16687)65432021-08-131-0/+25
| | | | | * update issue_index to finish migration * One Func to RecalculateIssueIndexForRepo
* Restore compatibility with SQLServer 2008 R2 in migrations (#16638)zeripath2021-08-081-6/+3
| | | | | | | | | | | | | | | | This fixes two problems with MSSQL: * `ALTER TABLE DROP ... IF EXISTS ...` is only supported in SQL Server >16. The `IF EXISTS` here is a belt-and-braces and does not need to be present. Therefore can be dropped. Also stop attempting to drop the indexes as constraints as they're indexes! * System tables like: `sys.indexes` should be lowercase not uppercase because of collation issues. Fix #13615 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Lock goth/gothic and Re-attempt OAuth2 registration on login if registration ↵zeripath2021-07-291-5/+0
| | | | | | | | | | | | | | | | | | | | failed at startup (#16570) Backport #16564 This PR has two parts: * Add locking to goth and gothic calls with a RWMutex The goth and gothic calls are currently unlocked and thus are a cause of multiple potential races * Reattempt OAuth2 registration on login if registration failed If OAuth2 registration fails at startup we currently disable the login_source however an alternative approach could be to reattempt registration on login attempt. Fix #16096 Signed-off-by: Andrew Thornton <art27@cantab.net>
* not show private user's repo in explore view (#16550) (#16554)a10121127962021-07-271-5/+3
| | | | | | after #16069, visibility is also usefull for user, so this limit is not usefull. fix #16545
* Fix session bugs (#16552) (#16553)65432021-07-273-17/+47
| | | | | | | | | | | | | | | * Fix session bugs (#16552) * fix deadlog bug * Fix models/issue_stopwatch.go * Update models/issue_stopwatch.go Co-authored-by: zeripath <art27@cantab.net> * fix getLatestCommitStatus Co-authored-by: zeripath <art27@cantab.net>
* Switch to maintained jwt lib (#16532) (#16533)zeripath2021-07-241-1/+1
| | | | | Backport #16532 Co-authored-by: Matti R <matti@mdranta.net>
* Add basic edit ldap auth test & actually fix #16252 (#16465) (#16494)v1.15.0-rc2zeripath2021-07-222-13/+33
| | | | | | | | | | | | | | | | | | | | | | Backport #16465 One of the reasons why #16447 was needed and why #16268 was needed in the first place was because it appears that editing ldap configuration doesn't get tested. This PR therefore adds a basic test that will run the edit pipeline. In doing so it's now clear that #16447 and #16268 aren't actually solving #16252. It turns out that what actually happens is that is that the bytes are actually double encoded. This PR now changes the json unmarshal wrapper to handle this double encode. Fix #16252 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de>
* Restore creation of git-daemon-export-ok files (#16508) (#16514)zeripath2021-07-221-2/+13
| | | | | | | | | | | | | | | Backport #16508 Somewhere along the line the creation of git-daemon-export-ok files disappeared but the updating of these files when repo visibility changes remained. The problem is that the current state will create files even when the org or user is private. This PR restores creation correctly. Fix #15521 Signed-off-by: Andrew Thornton <art27@cantab.net>
* Fix crash following ldap authentication update (#16447) (#16448)zeripath2021-07-151-2/+2
| | | | | | | | | | | Backport #16447 Unfortunately #16268 contained a terrible error, whereby there was a double indirection taken when unmarshalling the source data. This fatally breaks authentication configuration reading. Fix #16342 Signed-off-by: Andrew Thornton <art27@cantab.net>
* Retry rename on lock induced failures (#16435)zeripath2021-07-154-10/+10
| | | | | | | | | | | | | | | | | | * Retry rename on lock induced failures Due to external locking on Windows it is possible for an os.Rename to fail if the files or directories are being used elsewhere. This PR simply suggests retrying the rename again similar to how we handle the os.Remove problems. Fix #16427 Signed-off-by: Andrew Thornton <art27@cantab.net> * resolve CI fail Co-authored-by: techknowlogick <techknowlogick@gitea.io>
* Fix activation of primary email addresses (#16385)Meano2021-07-131-21/+21
| | | | | | | | | | | | | | | | * fix: primary email cannot be activated * Primary email should be activated together with user account when 'RegisterEmailConfirm' is enabled. * To fix the existing error state. When 'RegisterEmailConfirm' is enabled, the admin should have permission to modify the activations status of user email. And the user should be allowed to send activation to primary email. * Only judge whether email is primary from email_address table. * Improve logging and refactor isEmailActive Co-authored-by: zeripath <art27@cantab.net>
* Add option to provide signature for a token to verify key ownership (#14054)zeripath2021-07-1310-700/+1006
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add option to provide signed token to verify key ownership Currently we will only allow a key to be matched to a user if it matches an activated email address. This PR provides a different mechanism - if the user provides a signature for automatically generated token (based on the timestamp, user creation time, user ID, username and primary email. * Ensure verified keys can act for all active emails for the user * Add code to mark keys as verified * Slight UI adjustments * Slight UI adjustments 2 * Simplify signature verification slightly * fix postgres test * add api routes * handle swapped primary-keys * Verify the no-reply address for verified keys * Only add email addresses that are activated to keys * Fix committer shortcut properly * Restructure gpg_keys.go * Use common Verification Token code Signed-off-by: Andrew Thornton <art27@cantab.net>
* Fix archive error when rename repo or user (#16399)Lunny Xiao2021-07-132-22/+7
| | | Use repo id instead of full name to generate archive path
* Add checkbox to delete pull branch after successful merge (#16049)Jimmy Praet2021-07-131-8/+9
| | | | | | | | | | | | | | | | | | | | | | | * Add checkbox to delete pull branch after successful merge * Omit DeleteBranchAfterMerge field in json * Log a warning instead of error when PR head branch deleted * Add DefaultDeleteBranchAfterMerge to PullRequestConfig * Add support for delete_branch_after_merge via API * Fix for API: the branch should be deleted from the HEAD repo If head and base repo are the same, reuse the already opened ctx.Repo.GitRepo * Don't delegate to CleanupBranch, only reuse branch deletion code CleanupBranch contains too much logic that has already been performed by the Merge * Reuse gitrepo in MergePullRequest Co-authored-by: Andrew Thornton <art27@cantab.net>
* Validate Issue Index before querying DB (#16406)Norwin2021-07-121-0/+3
|
* Fix various documentation, user-facing, and source comment typos (#16367)luzpaz2021-07-0821-32/+32
| | | | | * Fix various doc, user-facing, and source comment typos Found via `codespell -q 3 -S ./options/locale,./vendor -L ba,pullrequest,pullrequests,readby`
* Reserve user/repo pattern for rss feature (#16323)65432021-07-012-2/+2
|
* Escape reference to `user` table in models.SearchEmails (#16313)Adyanth H2021-06-301-1/+1
| | | | | Fix #16312 Signed-off-by: Adyanth H <adyanthh@gmail.com>