2014-08-14 10:12:21 +04:00
|
|
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
2019-02-18 19:00:27 +03:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 21:20:29 +03:00
|
|
|
// SPDX-License-Identifier: MIT
|
2014-08-14 10:12:21 +04:00
|
|
|
|
|
|
|
package org
|
|
|
|
|
|
|
|
import (
|
2021-04-05 18:30:52 +03:00
|
|
|
"net/http"
|
2021-11-16 21:18:25 +03:00
|
|
|
"net/url"
|
2015-09-18 00:21:27 +03:00
|
|
|
"strings"
|
|
|
|
|
2016-11-10 19:24:48 +03:00
|
|
|
"code.gitea.io/gitea/models"
|
2021-09-24 14:32:56 +03:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2021-12-12 18:48:20 +03:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-24 12:49:20 +03:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-11-10 08:13:16 +03:00
|
|
|
"code.gitea.io/gitea/models/webhook"
|
2016-11-10 19:24:48 +03:00
|
|
|
"code.gitea.io/gitea/modules/base"
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
2022-03-29 10:23:45 +03:00
|
|
|
repo_module "code.gitea.io/gitea/modules/repository"
|
2016-11-10 19:24:48 +03:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2021-01-26 18:36:53 +03:00
|
|
|
"code.gitea.io/gitea/modules/web"
|
2021-11-22 18:21:55 +03:00
|
|
|
user_setting "code.gitea.io/gitea/routers/web/user/setting"
|
2021-04-06 22:44:05 +03:00
|
|
|
"code.gitea.io/gitea/services/forms"
|
2021-11-18 20:42:27 +03:00
|
|
|
"code.gitea.io/gitea/services/org"
|
2022-07-28 06:59:39 +03:00
|
|
|
container_service "code.gitea.io/gitea/services/packages/container"
|
2022-06-06 11:01:49 +03:00
|
|
|
repo_service "code.gitea.io/gitea/services/repository"
|
2021-11-22 18:21:55 +03:00
|
|
|
user_service "code.gitea.io/gitea/services/user"
|
2014-08-14 10:12:21 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2016-11-18 06:03:03 +03:00
|
|
|
// tplSettingsOptions template path for render settings
|
|
|
|
tplSettingsOptions base.TplName = "org/settings/options"
|
|
|
|
// tplSettingsDelete template path for render delete repository
|
|
|
|
tplSettingsDelete base.TplName = "org/settings/delete"
|
|
|
|
// tplSettingsHooks template path for render hook settings
|
|
|
|
tplSettingsHooks base.TplName = "org/settings/hooks"
|
Add Organization Wide Labels (#10814)
* Add organization wide labels
Implement organization wide labels similar to organization wide
webhooks. This lets you create individual labels for organizations that can be used
for all repos under that organization (so being able to reuse the same
label across multiple repos).
This makes it possible for small organizations with many repos to use
labels effectively.
Fixes #7406
* Add migration
* remove comments
* fix tests
* Update options/locale/locale_en-US.ini
Removed unused translation string
* show org labels in issue search label filter
* Use more clear var name
* rename migration after merge from master
* comment typo
* update migration again after rebase with master
* check for orgID <=0 per guillep2k review
* fmt
* Apply suggestions from code review
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* remove unused code
* Make sure RepoID is 0 when searching orgID per code review
* more changes/code review requests
* More descriptive translation var per code review
* func description/delete comment when issue label deleted instead of hiding it
* remove comment
* only use issues in that repo when calculating number of open issues for org label on repo label page
* Add integration test for IssuesSearch API with labels
* remove unused function
* Update models/issue_label.go
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* Use subquery in GetLabelIDsInReposByNames
* Fix tests to use correct orgID
* fix more tests
* IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well
* update comment for clarity
* Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition
* Don't sort repos by date in IssuesSearch API
After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures:
SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45
Returns different results for MySQL than other engines. However, the similar query:
SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30
Returns the same results.
This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function.
* linter is back!
* code review
* remove now unused option
* Fix newline at end of files
* more unused code
* update to master
* check for matching ids before query
* Update models/issue_label.go
Co-Authored-By: 6543 <6543@obermui.de>
* Update models/issue_label.go
* update comments
* Update routers/org/setting.go
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Co-authored-by: 6543 <6543@obermui.de>
2020-04-01 07:14:46 +03:00
|
|
|
// tplSettingsLabels template path for render labels settings
|
|
|
|
tplSettingsLabels base.TplName = "org/settings/labels"
|
Implement actions (#21937)
Close #13539.
Co-authored by: @lunny @appleboy @fuxiaohei and others.
Related projects:
- https://gitea.com/gitea/actions-proto-def
- https://gitea.com/gitea/actions-proto-go
- https://gitea.com/gitea/act
- https://gitea.com/gitea/act_runner
### Summary
The target of this PR is to bring a basic implementation of "Actions",
an internal CI/CD system of Gitea. That means even though it has been
merged, the state of the feature is **EXPERIMENTAL**, and please note
that:
- It is disabled by default;
- It shouldn't be used in a production environment currently;
- It shouldn't be used in a public Gitea instance currently;
- Breaking changes may be made before it's stable.
**Please comment on #13539 if you have any different product design
ideas**, all decisions reached there will be adopted here. But in this
PR, we don't talk about **naming, feature-creep or alternatives**.
### ⚠️ Breaking
`gitea-actions` will become a reserved user name. If a user with the
name already exists in the database, it is recommended to rename it.
### Some important reviews
- What is `DEFAULT_ACTIONS_URL` in `app.ini` for?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1055954954
- Why the api for runners is not under the normal `/api/v1` prefix?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1061173592
- Why DBFS?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1061301178
- Why ignore events triggered by `gitea-actions` bot?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1063254103
- Why there's no permission control for actions?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1090229868
### What it looks like
<details>
#### Manage runners
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205870657-c72f590e-2e08-4cd4-be7f-2e0abb299bbf.png">
#### List runs
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205872794-50fde990-2b45-48c1-a178-908e4ec5b627.png">
#### View logs
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205872501-9b7b9000-9542-4991-8f55-18ccdada77c3.png">
</details>
### How to try it
<details>
#### 1. Start Gitea
Clone this branch and [install from
source](https://docs.gitea.io/en-us/install-from-source).
Add additional configurations in `app.ini` to enable Actions:
```ini
[actions]
ENABLED = true
```
Start it.
If all is well, you'll see the management page of runners:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205877365-8e30a780-9b10-4154-b3e8-ee6c3cb35a59.png">
#### 2. Start runner
Clone the [act_runner](https://gitea.com/gitea/act_runner), and follow
the
[README](https://gitea.com/gitea/act_runner/src/branch/main/README.md)
to start it.
If all is well, you'll see a new runner has been added:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205878000-216f5937-e696-470d-b66c-8473987d91c3.png">
#### 3. Enable actions for a repo
Create a new repo or open an existing one, check the `Actions` checkbox
in settings and submit.
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205879705-53e09208-73c0-4b3e-a123-2dcf9aba4b9c.png">
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205879383-23f3d08f-1a85-41dd-a8b3-54e2ee6453e8.png">
If all is well, you'll see a new tab "Actions":
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205881648-a8072d8c-5803-4d76-b8a8-9b2fb49516c1.png">
#### 4. Upload workflow files
Upload some workflow files to `.gitea/workflows/xxx.yaml`, you can
follow the [quickstart](https://docs.github.com/en/actions/quickstart)
of GitHub Actions. Yes, Gitea Actions is compatible with GitHub Actions
in most cases, you can use the same demo:
```yaml
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
```
If all is well, you'll see a new run in `Actions` tab:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205884473-79a874bc-171b-4aaf-acd5-0241a45c3b53.png">
#### 5. Check the logs of jobs
Click a run and you'll see the logs:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205884800-994b0374-67f7-48ff-be9a-4c53f3141547.png">
#### 6. Go on
You can try more examples in [the
documents](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions)
of GitHub Actions, then you might find a lot of bugs.
Come on, PRs are welcome.
</details>
See also: [Feature Preview: Gitea
Actions](https://blog.gitea.io/2022/12/feature-preview-gitea-actions/)
---------
Co-authored-by: a1012112796 <1012112796@qq.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: ChristopherHX <christopher.homberger@web.de>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
2023-01-31 04:45:19 +03:00
|
|
|
// tplSettingsRunners template path for render runners settings
|
|
|
|
tplSettingsRunners base.TplName = "org/settings/runners"
|
|
|
|
// tplSettingsRunnersEdit template path for render runners edit settings
|
|
|
|
tplSettingsRunnersEdit base.TplName = "org/settings/runners_edit"
|
2014-08-14 10:12:21 +04:00
|
|
|
)
|
|
|
|
|
2016-11-18 06:03:03 +03:00
|
|
|
// Settings render the main settings page
|
2016-03-11 19:56:52 +03:00
|
|
|
func Settings(ctx *context.Context) {
|
2014-08-14 10:12:21 +04:00
|
|
|
ctx.Data["Title"] = ctx.Tr("org.settings")
|
2021-11-25 18:15:58 +03:00
|
|
|
ctx.Data["PageIsOrgSettings"] = true
|
2014-08-14 10:12:21 +04:00
|
|
|
ctx.Data["PageIsSettingsOptions"] = true
|
2019-07-23 21:50:39 +03:00
|
|
|
ctx.Data["CurrentVisibility"] = ctx.Org.Organization.Visibility
|
2019-09-30 02:20:27 +03:00
|
|
|
ctx.Data["RepoAdminChangeTeamAccess"] = ctx.Org.Organization.RepoAdminChangeTeamAccess
|
2021-04-05 18:30:52 +03:00
|
|
|
ctx.HTML(http.StatusOK, tplSettingsOptions)
|
2014-08-14 10:12:21 +04:00
|
|
|
}
|
|
|
|
|
2021-07-08 14:38:13 +03:00
|
|
|
// SettingsPost response for settings change submitted
|
2021-01-26 18:36:53 +03:00
|
|
|
func SettingsPost(ctx *context.Context) {
|
2021-04-06 22:44:05 +03:00
|
|
|
form := web.GetForm(ctx).(*forms.UpdateOrgSettingForm)
|
2014-08-14 10:12:21 +04:00
|
|
|
ctx.Data["Title"] = ctx.Tr("org.settings")
|
2021-11-25 18:15:58 +03:00
|
|
|
ctx.Data["PageIsOrgSettings"] = true
|
2014-08-14 10:12:21 +04:00
|
|
|
ctx.Data["PageIsSettingsOptions"] = true
|
2019-07-23 21:50:39 +03:00
|
|
|
ctx.Data["CurrentVisibility"] = ctx.Org.Organization.Visibility
|
2014-08-14 10:12:21 +04:00
|
|
|
|
|
|
|
if ctx.HasError() {
|
2021-04-05 18:30:52 +03:00
|
|
|
ctx.HTML(http.StatusOK, tplSettingsOptions)
|
2014-08-14 10:12:21 +04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
org := ctx.Org.Organization
|
2021-06-02 15:03:59 +03:00
|
|
|
nameChanged := org.Name != form.Name
|
2014-08-14 10:12:21 +04:00
|
|
|
|
|
|
|
// Check if organization name has been changed.
|
2015-09-18 00:21:27 +03:00
|
|
|
if org.LowerName != strings.ToLower(form.Name) {
|
2022-05-20 17:08:52 +03:00
|
|
|
isExist, err := user_model.IsUserExist(ctx, org.ID, form.Name)
|
2014-08-14 10:12:21 +04:00
|
|
|
if err != nil {
|
2018-01-11 00:34:17 +03:00
|
|
|
ctx.ServerError("IsUserExist", err)
|
2014-08-14 10:12:21 +04:00
|
|
|
return
|
|
|
|
} else if isExist {
|
2015-09-06 17:56:31 +03:00
|
|
|
ctx.Data["OrgName"] = true
|
2016-11-18 06:03:03 +03:00
|
|
|
ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplSettingsOptions, &form)
|
2014-08-14 10:12:21 +04:00
|
|
|
return
|
2023-03-14 10:45:21 +03:00
|
|
|
} else if err = user_model.ChangeUserName(ctx, org.AsUser(), form.Name); err != nil {
|
2022-01-20 18:18:46 +03:00
|
|
|
switch {
|
|
|
|
case db.IsErrNameReserved(err):
|
2015-09-06 17:56:31 +03:00
|
|
|
ctx.Data["OrgName"] = true
|
2022-01-20 18:18:46 +03:00
|
|
|
ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tplSettingsOptions, &form)
|
|
|
|
case db.IsErrNamePatternNotAllowed(err):
|
|
|
|
ctx.Data["OrgName"] = true
|
|
|
|
ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplSettingsOptions, &form)
|
|
|
|
default:
|
2018-01-11 00:34:17 +03:00
|
|
|
ctx.ServerError("ChangeUserName", err)
|
2014-08-14 10:12:21 +04:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2022-07-28 06:59:39 +03:00
|
|
|
|
|
|
|
if err := container_service.UpdateRepositoryNames(ctx, org.AsUser(), form.Name); err != nil {
|
|
|
|
ctx.ServerError("UpdateRepositoryNames", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-12-23 12:50:14 +03:00
|
|
|
// reset ctx.org.OrgLink with new name
|
2021-11-16 21:18:25 +03:00
|
|
|
ctx.Org.OrgLink = setting.AppSubURL + "/org/" + url.PathEscape(form.Name)
|
2015-09-06 17:56:31 +03:00
|
|
|
log.Trace("Organization name changed: %s -> %s", org.Name, form.Name)
|
2021-06-02 15:03:59 +03:00
|
|
|
nameChanged = false
|
2014-08-14 10:12:21 +04:00
|
|
|
}
|
2021-06-02 15:03:59 +03:00
|
|
|
|
2015-09-18 00:21:27 +03:00
|
|
|
// In case it's just a case change.
|
|
|
|
org.Name = form.Name
|
|
|
|
org.LowerName = strings.ToLower(form.Name)
|
2014-08-14 10:12:21 +04:00
|
|
|
|
2022-03-22 10:03:22 +03:00
|
|
|
if ctx.Doer.IsAdmin {
|
2015-12-12 03:24:57 +03:00
|
|
|
org.MaxRepoCreation = form.MaxRepoCreation
|
|
|
|
}
|
|
|
|
|
2015-09-06 17:56:31 +03:00
|
|
|
org.FullName = form.FullName
|
2014-08-14 10:12:21 +04:00
|
|
|
org.Description = form.Description
|
|
|
|
org.Website = form.Website
|
|
|
|
org.Location = form.Location
|
2019-09-23 23:08:03 +03:00
|
|
|
org.RepoAdminChangeTeamAccess = form.RepoAdminChangeTeamAccess
|
2020-06-07 03:45:12 +03:00
|
|
|
|
|
|
|
visibilityChanged := form.Visibility != org.Visibility
|
|
|
|
org.Visibility = form.Visibility
|
|
|
|
|
2022-05-20 17:08:52 +03:00
|
|
|
if err := user_model.UpdateUser(ctx, org.AsUser(), false); err != nil {
|
2018-01-11 00:34:17 +03:00
|
|
|
ctx.ServerError("UpdateUser", err)
|
2014-08-14 10:12:21 +04:00
|
|
|
return
|
|
|
|
}
|
2020-06-07 03:45:12 +03:00
|
|
|
|
|
|
|
// update forks visibility
|
|
|
|
if visibilityChanged {
|
2022-06-06 11:01:49 +03:00
|
|
|
repos, _, err := repo_model.GetUserRepositories(&repo_model.SearchRepoOptions{
|
2022-01-20 20:46:10 +03:00
|
|
|
Actor: org.AsUser(), Private: true, ListOptions: db.ListOptions{Page: 1, PageSize: org.NumRepos},
|
|
|
|
})
|
2021-11-19 14:41:40 +03:00
|
|
|
if err != nil {
|
2020-06-07 03:45:12 +03:00
|
|
|
ctx.ServerError("GetRepositories", err)
|
|
|
|
return
|
|
|
|
}
|
2021-11-19 14:41:40 +03:00
|
|
|
for _, repo := range repos {
|
2021-06-02 15:03:59 +03:00
|
|
|
repo.OwnerName = org.Name
|
2023-03-01 01:17:51 +03:00
|
|
|
if err := repo_service.UpdateRepository(ctx, repo, true); err != nil {
|
2020-06-07 03:45:12 +03:00
|
|
|
ctx.ServerError("UpdateRepository", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-06-02 15:03:59 +03:00
|
|
|
} else if nameChanged {
|
2021-12-12 18:48:20 +03:00
|
|
|
if err := repo_model.UpdateRepositoryOwnerNames(org.ID, org.Name); err != nil {
|
2021-06-02 15:03:59 +03:00
|
|
|
ctx.ServerError("UpdateRepository", err)
|
|
|
|
return
|
|
|
|
}
|
2020-06-07 03:45:12 +03:00
|
|
|
}
|
|
|
|
|
2014-08-14 10:12:21 +04:00
|
|
|
log.Trace("Organization setting updated: %s", org.Name)
|
|
|
|
ctx.Flash.Success(ctx.Tr("org.settings.update_setting_success"))
|
2015-11-25 03:28:24 +03:00
|
|
|
ctx.Redirect(ctx.Org.OrgLink + "/settings")
|
2014-08-14 10:12:21 +04:00
|
|
|
}
|
|
|
|
|
2016-11-18 06:03:03 +03:00
|
|
|
// SettingsAvatar response for change avatar on settings page
|
2021-01-26 18:36:53 +03:00
|
|
|
func SettingsAvatar(ctx *context.Context) {
|
2021-04-06 22:44:05 +03:00
|
|
|
form := web.GetForm(ctx).(*forms.AvatarForm)
|
|
|
|
form.Source = forms.AvatarLocal
|
2021-11-22 18:21:55 +03:00
|
|
|
if err := user_setting.UpdateAvatarSetting(ctx, form, ctx.Org.Organization.AsUser()); err != nil {
|
2015-09-07 00:12:02 +03:00
|
|
|
ctx.Flash.Error(err.Error())
|
|
|
|
} else {
|
|
|
|
ctx.Flash.Success(ctx.Tr("org.settings.update_avatar_success"))
|
|
|
|
}
|
|
|
|
|
2016-03-06 19:36:30 +03:00
|
|
|
ctx.Redirect(ctx.Org.OrgLink + "/settings")
|
|
|
|
}
|
|
|
|
|
2021-07-08 14:38:13 +03:00
|
|
|
// SettingsDeleteAvatar response for delete avatar on settings page
|
2016-03-11 19:56:52 +03:00
|
|
|
func SettingsDeleteAvatar(ctx *context.Context) {
|
2021-11-22 18:21:55 +03:00
|
|
|
if err := user_service.DeleteAvatar(ctx.Org.Organization.AsUser()); err != nil {
|
2016-03-06 19:36:30 +03:00
|
|
|
ctx.Flash.Error(err.Error())
|
|
|
|
}
|
|
|
|
|
2015-09-07 00:12:02 +03:00
|
|
|
ctx.Redirect(ctx.Org.OrgLink + "/settings")
|
|
|
|
}
|
|
|
|
|
2020-02-03 19:46:33 +03:00
|
|
|
// SettingsDelete response for deleting an organization
|
2016-03-11 19:56:52 +03:00
|
|
|
func SettingsDelete(ctx *context.Context) {
|
2014-08-14 10:12:21 +04:00
|
|
|
ctx.Data["Title"] = ctx.Tr("org.settings")
|
2021-11-25 18:15:58 +03:00
|
|
|
ctx.Data["PageIsOrgSettings"] = true
|
2014-08-14 10:12:21 +04:00
|
|
|
ctx.Data["PageIsSettingsDelete"] = true
|
|
|
|
|
|
|
|
if ctx.Req.Method == "POST" {
|
2021-11-18 20:42:27 +03:00
|
|
|
if ctx.Org.Organization.Name != ctx.FormString("org_name") {
|
2021-03-01 17:33:05 +03:00
|
|
|
ctx.Data["Err_OrgName"] = true
|
|
|
|
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_org_name"), tplSettingsDelete, nil)
|
2015-09-06 18:25:08 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-18 20:42:27 +03:00
|
|
|
if err := org.DeleteOrganization(ctx.Org.Organization); err != nil {
|
2015-03-18 04:51:39 +03:00
|
|
|
if models.IsErrUserOwnRepos(err) {
|
2014-08-14 10:12:21 +04:00
|
|
|
ctx.Flash.Error(ctx.Tr("form.org_still_own_repo"))
|
2015-11-25 03:28:24 +03:00
|
|
|
ctx.Redirect(ctx.Org.OrgLink + "/settings/delete")
|
2022-03-30 11:42:47 +03:00
|
|
|
} else if models.IsErrUserOwnPackages(err) {
|
|
|
|
ctx.Flash.Error(ctx.Tr("form.org_still_own_packages"))
|
|
|
|
ctx.Redirect(ctx.Org.OrgLink + "/settings/delete")
|
2015-03-18 04:51:39 +03:00
|
|
|
} else {
|
2018-01-11 00:34:17 +03:00
|
|
|
ctx.ServerError("DeleteOrganization", err)
|
2014-08-14 10:12:21 +04:00
|
|
|
}
|
|
|
|
} else {
|
2021-11-18 20:42:27 +03:00
|
|
|
log.Trace("Organization deleted: %s", ctx.Org.Organization.Name)
|
2016-11-27 13:14:25 +03:00
|
|
|
ctx.Redirect(setting.AppSubURL + "/")
|
2014-08-14 10:12:21 +04:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-05 18:30:52 +03:00
|
|
|
ctx.HTML(http.StatusOK, tplSettingsDelete)
|
2014-08-14 10:12:21 +04:00
|
|
|
}
|
2014-09-04 15:17:00 +04:00
|
|
|
|
2016-11-18 06:03:03 +03:00
|
|
|
// Webhooks render webhook list page
|
2016-03-11 19:56:52 +03:00
|
|
|
func Webhooks(ctx *context.Context) {
|
2014-09-04 15:17:00 +04:00
|
|
|
ctx.Data["Title"] = ctx.Tr("org.settings")
|
2021-11-25 18:15:58 +03:00
|
|
|
ctx.Data["PageIsOrgSettings"] = true
|
2014-09-04 15:17:00 +04:00
|
|
|
ctx.Data["PageIsSettingsHooks"] = true
|
2019-03-19 05:33:20 +03:00
|
|
|
ctx.Data["BaseLink"] = ctx.Org.OrgLink + "/settings/hooks"
|
2021-01-15 02:24:03 +03:00
|
|
|
ctx.Data["BaseLinkNew"] = ctx.Org.OrgLink + "/settings/hooks"
|
2015-08-26 16:45:51 +03:00
|
|
|
ctx.Data["Description"] = ctx.Tr("org.settings.hooks_desc")
|
2014-09-04 15:17:00 +04:00
|
|
|
|
2023-03-10 17:28:32 +03:00
|
|
|
ws, err := webhook.ListWebhooksByOpts(ctx, &webhook.ListWebhookOptions{OwnerID: ctx.Org.Organization.ID})
|
2014-09-04 15:17:00 +04:00
|
|
|
if err != nil {
|
2023-03-10 17:28:32 +03:00
|
|
|
ctx.ServerError("ListWebhooksByOpts", err)
|
2014-09-04 15:17:00 +04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Data["Webhooks"] = ws
|
2021-04-05 18:30:52 +03:00
|
|
|
ctx.HTML(http.StatusOK, tplSettingsHooks)
|
2014-09-04 15:17:00 +04:00
|
|
|
}
|
2015-08-26 16:45:51 +03:00
|
|
|
|
2016-11-18 06:03:03 +03:00
|
|
|
// DeleteWebhook response for delete webhook
|
2016-03-11 19:56:52 +03:00
|
|
|
func DeleteWebhook(ctx *context.Context) {
|
2023-03-10 17:28:32 +03:00
|
|
|
if err := webhook.DeleteWebhookByOwnerID(ctx.Org.Organization.ID, ctx.FormInt64("id")); err != nil {
|
|
|
|
ctx.Flash.Error("DeleteWebhookByOwnerID: " + err.Error())
|
2015-08-26 16:45:51 +03:00
|
|
|
} else {
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
|
|
|
|
}
|
|
|
|
|
2021-04-05 18:30:52 +03:00
|
|
|
ctx.JSON(http.StatusOK, map[string]interface{}{
|
2015-08-26 16:45:51 +03:00
|
|
|
"redirect": ctx.Org.OrgLink + "/settings/hooks",
|
|
|
|
})
|
|
|
|
}
|
Add Organization Wide Labels (#10814)
* Add organization wide labels
Implement organization wide labels similar to organization wide
webhooks. This lets you create individual labels for organizations that can be used
for all repos under that organization (so being able to reuse the same
label across multiple repos).
This makes it possible for small organizations with many repos to use
labels effectively.
Fixes #7406
* Add migration
* remove comments
* fix tests
* Update options/locale/locale_en-US.ini
Removed unused translation string
* show org labels in issue search label filter
* Use more clear var name
* rename migration after merge from master
* comment typo
* update migration again after rebase with master
* check for orgID <=0 per guillep2k review
* fmt
* Apply suggestions from code review
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* remove unused code
* Make sure RepoID is 0 when searching orgID per code review
* more changes/code review requests
* More descriptive translation var per code review
* func description/delete comment when issue label deleted instead of hiding it
* remove comment
* only use issues in that repo when calculating number of open issues for org label on repo label page
* Add integration test for IssuesSearch API with labels
* remove unused function
* Update models/issue_label.go
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* Use subquery in GetLabelIDsInReposByNames
* Fix tests to use correct orgID
* fix more tests
* IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well
* update comment for clarity
* Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition
* Don't sort repos by date in IssuesSearch API
After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures:
SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45
Returns different results for MySQL than other engines. However, the similar query:
SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30
Returns the same results.
This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function.
* linter is back!
* code review
* remove now unused option
* Fix newline at end of files
* more unused code
* update to master
* check for matching ids before query
* Update models/issue_label.go
Co-Authored-By: 6543 <6543@obermui.de>
* Update models/issue_label.go
* update comments
* Update routers/org/setting.go
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Co-authored-by: 6543 <6543@obermui.de>
2020-04-01 07:14:46 +03:00
|
|
|
|
|
|
|
// Labels render organization labels page
|
|
|
|
func Labels(ctx *context.Context) {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.labels")
|
2021-11-25 18:15:58 +03:00
|
|
|
ctx.Data["PageIsOrgSettings"] = true
|
Add Organization Wide Labels (#10814)
* Add organization wide labels
Implement organization wide labels similar to organization wide
webhooks. This lets you create individual labels for organizations that can be used
for all repos under that organization (so being able to reuse the same
label across multiple repos).
This makes it possible for small organizations with many repos to use
labels effectively.
Fixes #7406
* Add migration
* remove comments
* fix tests
* Update options/locale/locale_en-US.ini
Removed unused translation string
* show org labels in issue search label filter
* Use more clear var name
* rename migration after merge from master
* comment typo
* update migration again after rebase with master
* check for orgID <=0 per guillep2k review
* fmt
* Apply suggestions from code review
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* remove unused code
* Make sure RepoID is 0 when searching orgID per code review
* more changes/code review requests
* More descriptive translation var per code review
* func description/delete comment when issue label deleted instead of hiding it
* remove comment
* only use issues in that repo when calculating number of open issues for org label on repo label page
* Add integration test for IssuesSearch API with labels
* remove unused function
* Update models/issue_label.go
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* Use subquery in GetLabelIDsInReposByNames
* Fix tests to use correct orgID
* fix more tests
* IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well
* update comment for clarity
* Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition
* Don't sort repos by date in IssuesSearch API
After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures:
SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45
Returns different results for MySQL than other engines. However, the similar query:
SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30
Returns the same results.
This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function.
* linter is back!
* code review
* remove now unused option
* Fix newline at end of files
* more unused code
* update to master
* check for matching ids before query
* Update models/issue_label.go
Co-Authored-By: 6543 <6543@obermui.de>
* Update models/issue_label.go
* update comments
* Update routers/org/setting.go
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Co-authored-by: 6543 <6543@obermui.de>
2020-04-01 07:14:46 +03:00
|
|
|
ctx.Data["PageIsOrgSettingsLabels"] = true
|
|
|
|
ctx.Data["RequireTribute"] = true
|
2022-03-29 10:23:45 +03:00
|
|
|
ctx.Data["LabelTemplates"] = repo_module.LabelTemplates
|
2021-04-05 18:30:52 +03:00
|
|
|
ctx.HTML(http.StatusOK, tplSettingsLabels)
|
Add Organization Wide Labels (#10814)
* Add organization wide labels
Implement organization wide labels similar to organization wide
webhooks. This lets you create individual labels for organizations that can be used
for all repos under that organization (so being able to reuse the same
label across multiple repos).
This makes it possible for small organizations with many repos to use
labels effectively.
Fixes #7406
* Add migration
* remove comments
* fix tests
* Update options/locale/locale_en-US.ini
Removed unused translation string
* show org labels in issue search label filter
* Use more clear var name
* rename migration after merge from master
* comment typo
* update migration again after rebase with master
* check for orgID <=0 per guillep2k review
* fmt
* Apply suggestions from code review
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* remove unused code
* Make sure RepoID is 0 when searching orgID per code review
* more changes/code review requests
* More descriptive translation var per code review
* func description/delete comment when issue label deleted instead of hiding it
* remove comment
* only use issues in that repo when calculating number of open issues for org label on repo label page
* Add integration test for IssuesSearch API with labels
* remove unused function
* Update models/issue_label.go
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* Use subquery in GetLabelIDsInReposByNames
* Fix tests to use correct orgID
* fix more tests
* IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well
* update comment for clarity
* Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition
* Don't sort repos by date in IssuesSearch API
After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures:
SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45
Returns different results for MySQL than other engines. However, the similar query:
SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30
Returns the same results.
This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function.
* linter is back!
* code review
* remove now unused option
* Fix newline at end of files
* more unused code
* update to master
* check for matching ids before query
* Update models/issue_label.go
Co-Authored-By: 6543 <6543@obermui.de>
* Update models/issue_label.go
* update comments
* Update routers/org/setting.go
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Co-authored-by: 6543 <6543@obermui.de>
2020-04-01 07:14:46 +03:00
|
|
|
}
|