Commit 1be15162 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'ben.boeckel/gitlab-ce-api-visible-projects' into 'master'

Add visible projects API

## What does this MR do?

Add a new `/projects/visible` API endpoint. Originally created by @ben.boeckel in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5970.

## Are there points in the code the reviewer needs to double check?

Does the API make sense?

## Why was this MR needed?

The `/projects` endpoint only returned projects the user was explicitly a member of.

Closes #19361, #3119.

See merge request !6681
parents b58ea12a 7623ab0c
...@@ -5,6 +5,7 @@ v 8.13.0 (unreleased) ...@@ -5,6 +5,7 @@ v 8.13.0 (unreleased)
- Add link from system note to compare with previous version - Add link from system note to compare with previous version
- Improve issue load time performance by avoiding ORDER BY in find_by call - Improve issue load time performance by avoiding ORDER BY in find_by call
- Use gitlab-shell v3.6.2 (GIT TRACE logging) - Use gitlab-shell v3.6.2 (GIT TRACE logging)
- Add `/projects/visible` API endpoint (Ben Boeckel)
- Fix centering of custom header logos (Ashley Dumaine) - Fix centering of custom header logos (Ashley Dumaine)
- AbstractReferenceFilter caches project_refs on RequestStore when active - AbstractReferenceFilter caches project_refs on RequestStore when active
- Replaced the check sign to arrow in the show build view. !6501 - Replaced the check sign to arrow in the show build view. !6501
......
...@@ -20,7 +20,7 @@ Constants for project visibility levels are next: ...@@ -20,7 +20,7 @@ Constants for project visibility levels are next:
## List projects ## List projects
Get a list of projects accessible by the authenticated user. Get a list of projects for which the authenticated user is a member.
``` ```
GET /projects GET /projects
...@@ -28,11 +28,14 @@ GET /projects ...@@ -28,11 +28,14 @@ GET /projects
Parameters: Parameters:
- `archived` (optional) - if passed, limit by archived status | Attribute | Type | Required | Description |
- `visibility` (optional) - if passed, limit by visibility `public`, `internal`, `private` | --------- | ---- | -------- | ----------- |
- `order_by` (optional) - Return requests ordered by `id`, `name`, `path`, `created_at`, `updated_at` or `last_activity_at` fields. Default is `created_at` | `archived` | boolean | no | Limit by archived status |
- `sort` (optional) - Return requests sorted in `asc` or `desc` order. Default is `desc` | `visibility` | string | no | Limit by visibility `public`, `internal`, or `private` |
- `search` (optional) - Return list of authorized projects according to a search criteria | `order_by` | string | no | Return projects ordered by `id`, `name`, `path`, `created_at`, `updated_at`, or `last_activity_at` fields. Default is `created_at` |
| `sort` | string | no | Return projects sorted in `asc` or `desc` order. Default is `desc` |
| `search` | string | no | Return list of authorized projects matching the search criteria |
| `simple` | boolean | no | Return only the ID, URL, name, and path of each project |
```json ```json
[ [
...@@ -153,6 +156,138 @@ Parameters: ...@@ -153,6 +156,138 @@ Parameters:
] ]
``` ```
Get a list of projects which the authenticated user can see.
```
GET /projects/visible
```
Parameters:
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `archived` | boolean | no | Limit by archived status |
| `visibility` | string | no | Limit by visibility `public`, `internal`, or `private` |
| `order_by` | string | no | Return projects ordered by `id`, `name`, `path`, `created_at`, `updated_at`, or `last_activity_at` fields. Default is `created_at` |
| `sort` | string | no | Return projects sorted in `asc` or `desc` order. Default is `desc` |
| `search` | string | no | Return list of authorized projects matching the search criteria |
| `simple` | boolean | no | Return only the ID, URL, name, and path of each project |
```json
[
{
"id": 4,
"description": null,
"default_branch": "master",
"public": false,
"visibility_level": 0,
"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",
"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",
"web_url": "http://example.com/diaspora/diaspora-client",
"tag_list": [
"example",
"disapora client"
],
"owner": {
"id": 3,
"name": "Diaspora",
"created_at": "2013-09-30T13:46:02Z"
},
"name": "Diaspora Client",
"name_with_namespace": "Diaspora / Diaspora Client",
"path": "diaspora-client",
"path_with_namespace": "diaspora/diaspora-client",
"issues_enabled": true,
"open_issues_count": 1,
"merge_requests_enabled": true,
"builds_enabled": true,
"wiki_enabled": true,
"snippets_enabled": false,
"container_registry_enabled": false,
"created_at": "2013-09-30T13:46:02Z",
"last_activity_at": "2013-09-30T13:46:02Z",
"creator_id": 3,
"namespace": {
"created_at": "2013-09-30T13:46:02Z",
"description": "",
"id": 3,
"name": "Diaspora",
"owner_id": 1,
"path": "diaspora",
"updated_at": "2013-09-30T13:46:02Z"
},
"archived": false,
"avatar_url": "http://example.com/uploads/project/avatar/4/uploads/avatar.png",
"shared_runners_enabled": true,
"forks_count": 0,
"star_count": 0,
"runners_token": "b8547b1dc37721d05889db52fa2f02",
"public_builds": true,
"shared_with_groups": []
},
{
"id": 6,
"description": null,
"default_branch": "master",
"public": false,
"visibility_level": 0,
"ssh_url_to_repo": "git@example.com:brightbox/puppet.git",
"http_url_to_repo": "http://example.com/brightbox/puppet.git",
"web_url": "http://example.com/brightbox/puppet",
"tag_list": [
"example",
"puppet"
],
"owner": {
"id": 4,
"name": "Brightbox",
"created_at": "2013-09-30T13:46:02Z"
},
"name": "Puppet",
"name_with_namespace": "Brightbox / Puppet",
"path": "puppet",
"path_with_namespace": "brightbox/puppet",
"issues_enabled": true,
"open_issues_count": 1,
"merge_requests_enabled": true,
"builds_enabled": true,
"wiki_enabled": true,
"snippets_enabled": false,
"container_registry_enabled": false,
"created_at": "2013-09-30T13:46:02Z",
"last_activity_at": "2013-09-30T13:46:02Z",
"creator_id": 3,
"namespace": {
"created_at": "2013-09-30T13:46:02Z",
"description": "",
"id": 4,
"name": "Brightbox",
"owner_id": 1,
"path": "brightbox",
"updated_at": "2013-09-30T13:46:02Z"
},
"permissions": {
"project_access": {
"access_level": 10,
"notification_level": 3
},
"group_access": {
"access_level": 50,
"notification_level": 3
}
},
"archived": false,
"avatar_url": null,
"shared_runners_enabled": true,
"forks_count": 0,
"star_count": 0,
"runners_token": "b8547b1dc37721d05889db52fa2f02",
"public_builds": true,
"shared_with_groups": []
}
]
```
### List owned projects ### List owned projects
Get a list of projects which are owned by the authenticated user. Get a list of projects which are owned by the authenticated user.
...@@ -163,11 +298,13 @@ GET /projects/owned ...@@ -163,11 +298,13 @@ GET /projects/owned
Parameters: Parameters:
- `archived` (optional) - if passed, limit by archived status | Attribute | Type | Required | Description |
- `visibility` (optional) - if passed, limit by visibility `public`, `internal`, `private` | --------- | ---- | -------- | ----------- |
- `order_by` (optional) - Return requests ordered by `id`, `name`, `path`, `created_at`, `updated_at` or `last_activity_at` fields. Default is `created_at` | `archived` | boolean | no | Limit by archived status |
- `sort` (optional) - Return requests sorted in `asc` or `desc` order. Default is `desc` | `visibility` | string | no | Limit by visibility `public`, `internal`, or `private` |
- `search` (optional) - Return list of authorized projects according to a search criteria | `order_by` | string | no | Return projects ordered by `id`, `name`, `path`, `created_at`, `updated_at`, or `last_activity_at` fields. Default is `created_at` |
| `sort` | string | no | Return projects sorted in `asc` or `desc` order. Default is `desc` |
| `search` | string | no | Return list of authorized projects matching the search criteria |
### List starred projects ### List starred projects
...@@ -179,11 +316,13 @@ GET /projects/starred ...@@ -179,11 +316,13 @@ GET /projects/starred
Parameters: Parameters:
- `archived` (optional) - if passed, limit by archived status | Attribute | Type | Required | Description |
- `visibility` (optional) - if passed, limit by visibility `public`, `internal`, `private` | --------- | ---- | -------- | ----------- |
- `order_by` (optional) - Return requests ordered by `id`, `name`, `path`, `created_at`, `updated_at` or `last_activity_at` fields. Default is `created_at` | `archived` | boolean | no | Limit by archived status |
- `sort` (optional) - Return requests sorted in `asc` or `desc` order. Default is `desc` | `visibility` | string | no | Limit by visibility `public`, `internal`, or `private` |
- `search` (optional) - Return list of authorized projects according to a search criteria | `order_by` | string | no | Return projects ordered by `id`, `name`, `path`, `created_at`, `updated_at`, or `last_activity_at` fields. Default is `created_at` |
| `sort` | string | no | Return projects sorted in `asc` or `desc` order. Default is `desc` |
| `search` | string | no | Return list of authorized projects matching the search criteria |
### List ALL projects ### List ALL projects
...@@ -195,11 +334,13 @@ GET /projects/all ...@@ -195,11 +334,13 @@ GET /projects/all
Parameters: Parameters:
- `archived` (optional) - if passed, limit by archived status | Attribute | Type | Required | Description |
- `visibility` (optional) - if passed, limit by visibility `public`, `internal`, `private` | --------- | ---- | -------- | ----------- |
- `order_by` (optional) - Return requests ordered by `id`, `name`, `path`, `created_at`, `updated_at` or `last_activity_at` fields. Default is `created_at` | `archived` | boolean | no | Limit by archived status |
- `sort` (optional) - Return requests sorted in `asc` or `desc` order. Default is `desc` | `visibility` | string | no | Limit by visibility `public`, `internal`, or `private` |
- `search` (optional) - Return list of authorized projects according to a search criteria | `order_by` | string | no | Return projects ordered by `id`, `name`, `path`, `created_at`, `updated_at`, or `last_activity_at` fields. Default is `created_at` |
| `sort` | string | no | Return projects sorted in `asc` or `desc` order. Default is `desc` |
| `search` | string | no | Return list of authorized projects matching the search criteria |
### Get single project ### Get single project
...@@ -212,7 +353,9 @@ GET /projects/:id ...@@ -212,7 +353,9 @@ GET /projects/:id
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of a project | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID or NAMESPACE/PROJECT_NAME of the project |
```json ```json
{ {
...@@ -301,7 +444,9 @@ GET /projects/:id/events ...@@ -301,7 +444,9 @@ GET /projects/:id/events
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of a project | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID or NAMESPACE/PROJECT_NAME of the project |
```json ```json
[ [
...@@ -439,24 +584,26 @@ POST /projects ...@@ -439,24 +584,26 @@ POST /projects
Parameters: Parameters:
- `name` (required) - new project name | Attribute | Type | Required | Description |
- `path` (optional) - custom repository name for new project. By default generated based on name | --------- | ---- | -------- | ----------- |
- `namespace_id` (optional) - namespace for the new project (defaults to user) | `name` | string | yes | The name of the new project |
- `description` (optional) - short project description | `path` | string | no | Custom repository name for new project. By default generated based on name |
- `issues_enabled` (optional) | `namespace_id` | integer | no | Namespace for the new project (defaults to the current user's namespace) |
- `merge_requests_enabled` (optional) | `description` | string | no | Short project description |
- `builds_enabled` (optional) | `issues_enabled` | boolean | no | Enable issues for this project |
- `wiki_enabled` (optional) | `merge_requests_enabled` | boolean | no | Enable merge requests for this project |
- `snippets_enabled` (optional) | `builds_enabled` | boolean | no | Enable builds for this project |
- `container_registry_enabled` (optional) | `wiki_enabled` | boolean | no | Enable wiki for this project |
- `shared_runners_enabled` (optional) | `snippets_enabled` | boolean | no | Enable snippets for this project |
- `public` (optional) - if `true` same as setting visibility_level = 20 | `container_registry_enabled` | boolean | no | Enable container registry for this project |
- `visibility_level` (optional) | `shared_runners_enabled` | boolean | no | Enable shared runners for this project |
- `import_url` (optional) | `public` | boolean | no | If `true`, the same as setting `visibility_level` to 20 |
- `public_builds` (optional) | `visibility_level` | integer | no | See [project visibility level][#project-visibility-level] |
- `only_allow_merge_if_build_succeeds` (optional) | `import_url` | string | no | URL to import repository from |
- `lfs_enabled` (optional) | `public_builds` | boolean | no | If `true`, builds can be viewed by non-project-members |
- `request_access_enabled` (optional) - Allow users to request member access. | `only_allow_merge_if_build_succeeds` | boolean | no | Set whether merge requests can only be merged with successful builds |
| `lfs_enabled` | boolean | no | Enable LFS |
| `request_access_enabled` | boolean | no | Allow users to request member access |
### Create project for user ### Create project for user
...@@ -468,23 +615,27 @@ POST /projects/user/:user_id ...@@ -468,23 +615,27 @@ POST /projects/user/:user_id
Parameters: Parameters:
- `user_id` (required) - user_id of owner | Attribute | Type | Required | Description |
- `name` (required) - new project name | --------- | ---- | -------- | ----------- |
- `description` (optional) - short project description | `user_id` | integer | yes | The user ID of the project owner |
- `issues_enabled` (optional) | `name` | string | yes | The name of the new project |
- `merge_requests_enabled` (optional) | `path` | string | no | Custom repository name for new project. By default generated based on name |
- `builds_enabled` (optional) | `namespace_id` | integer | no | Namespace for the new project (defaults to the current user's namespace) |
- `wiki_enabled` (optional) | `description` | string | no | Short project description |
- `snippets_enabled` (optional) | `issues_enabled` | boolean | no | Enable issues for this project |
- `container_registry_enabled` (optional) | `merge_requests_enabled` | boolean | no | Enable merge requests for this project |
- `shared_runners_enabled` (optional) | `builds_enabled` | boolean | no | Enable builds for this project |
- `public` (optional) - if `true` same as setting visibility_level = 20 | `wiki_enabled` | boolean | no | Enable wiki for this project |
- `visibility_level` (optional) | `snippets_enabled` | boolean | no | Enable snippets for this project |
- `import_url` (optional) | `container_registry_enabled` | boolean | no | Enable container registry for this project |
- `public_builds` (optional) | `shared_runners_enabled` | boolean | no | Enable shared runners for this project |
- `only_allow_merge_if_build_succeeds` (optional) | `public` | boolean | no | If `true`, the same as setting `visibility_level` to 20 |
- `lfs_enabled` (optional) | `visibility_level` | integer | no | See [project visibility level][#project-visibility-level] |
- `request_access_enabled` (optional) - Allow users to request member access. | `import_url` | string | no | URL to import repository from |
| `public_builds` | boolean | no | If `true`, builds can be viewed by non-project-members |
| `only_allow_merge_if_build_succeeds` | boolean | no | Set whether merge requests can only be merged with successful builds |
| `lfs_enabled` | boolean | no | Enable LFS |
| `request_access_enabled` | boolean | no | Allow users to request member access |
### Edit project ### Edit project
...@@ -496,24 +647,26 @@ PUT /projects/:id ...@@ -496,24 +647,26 @@ PUT /projects/:id
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of a project | Attribute | Type | Required | Description |
- `name` (optional) - project name | --------- | ---- | -------- | ----------- |
- `path` (optional) - repository name for project | `id` | integer/string | yes | The ID or NAMESPACE/PROJECT_NAME of the project |
- `description` (optional) - short project description | `name` | string | yes | The name of the project |
- `default_branch` (optional) | `path` | string | no | Custom repository name for the project. By default generated based on name |
- `issues_enabled` (optional) | `description` | string | no | Short project description |
- `merge_requests_enabled` (optional) | `issues_enabled` | boolean | no | Enable issues for this project |
- `builds_enabled` (optional) | `merge_requests_enabled` | boolean | no | Enable merge requests for this project |
- `wiki_enabled` (optional) | `builds_enabled` | boolean | no | Enable builds for this project |
- `snippets_enabled` (optional) | `wiki_enabled` | boolean | no | Enable wiki for this project |
- `container_registry_enabled` (optional) | `snippets_enabled` | boolean | no | Enable snippets for this project |
- `shared_runners_enabled` (optional) | `container_registry_enabled` | boolean | no | Enable container registry for this project |
- `public` (optional) - if `true` same as setting visibility_level = 20 | `shared_runners_enabled` | boolean | no | Enable shared runners for this project |
- `visibility_level` (optional) | `public` | boolean | no | If `true`, the same as setting `visibility_level` to 20 |
- `public_builds` (optional) | `visibility_level` | integer | no | See [project visibility level][#project-visibility-level] |
- `only_allow_merge_if_build_succeeds` (optional) | `import_url` | string | no | URL to import repository from |
- `lfs_enabled` (optional) | `public_builds` | boolean | no | If `true`, builds can be viewed by non-project-members |
- `request_access_enabled` (optional) - Allow users to request member access. | `only_allow_merge_if_build_succeeds` | boolean | no | Set whether merge requests can only be merged with successful builds |
| `lfs_enabled` | boolean | no | Enable LFS |
| `request_access_enabled` | boolean | no | Allow users to request member access |
On success, method returns 200 with the updated project. If parameters are On success, method returns 200 with the updated project. If parameters are
invalid, 400 is returned. invalid, 400 is returned.
...@@ -528,8 +681,10 @@ POST /projects/fork/:id ...@@ -528,8 +681,10 @@ POST /projects/fork/:id
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of the project to be forked | Attribute | Type | Required | Description |
- `namespace` (optional) - The ID or path of the namespace that the project will be forked to | --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID or NAMESPACE/PROJECT_NAME of the project |
| `namespace` | integer/string | yes | The ID or path of the namespace that the project will be forked to |
### Star a project ### Star a project
...@@ -540,9 +695,11 @@ Stars a given project. Returns status code `201` and the project on success and ...@@ -540,9 +695,11 @@ Stars a given project. Returns status code `201` and the project on success and
POST /projects/:id/star POST /projects/:id/star
``` ```
Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME | | `id` | integer/string | yes | The ID or NAMESPACE/PROJECT_NAME of the project |
```bash ```bash
curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/5/star" curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/5/star"
...@@ -610,7 +767,7 @@ DELETE /projects/:id/star ...@@ -610,7 +767,7 @@ DELETE /projects/:id/star
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME | | `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
```bash ```bash
curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/5/star" curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/5/star"
...@@ -682,7 +839,7 @@ POST /projects/:id/archive ...@@ -682,7 +839,7 @@ POST /projects/:id/archive
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME | | `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
```bash ```bash
curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/archive" curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/archive"
...@@ -770,7 +927,7 @@ POST /projects/:id/unarchive ...@@ -770,7 +927,7 @@ POST /projects/:id/unarchive
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME | | `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
```bash ```bash
curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/unarchive" curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/unarchive"
...@@ -853,7 +1010,9 @@ DELETE /projects/:id ...@@ -853,7 +1010,9 @@ DELETE /projects/:id
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of the project to be forked | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
## Uploads ## Uploads
...@@ -867,8 +1026,10 @@ POST /projects/:id/uploads ...@@ -867,8 +1026,10 @@ POST /projects/:id/uploads
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of the project to be forked | Attribute | Type | Required | Description |
- `file` (required) - The file to be uploaded | --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
| `file` | string | yes | The file to be uploaded |
```json ```json
{ {
...@@ -896,10 +1057,12 @@ POST /projects/:id/share ...@@ -896,10 +1057,12 @@ POST /projects/:id/share
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of the project to be forked | Attribute | Type | Required | Description |
- `group_id` (required) - The ID of a group | --------- | ---- | -------- | ----------- |
- `group_access` (required) - Level of permissions for sharing | `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
- `expires_at` - Share expiration date in ISO 8601 format: 2016-09-26 | `group_id` | integer | yes | The ID of the group to share with |
| `group_access` | integer | yes | The permissions level to grant the group |
| `expires_at` | string | no | Share expiration date in ISO 8601 format: 2016-09-26 |
## Hooks ## Hooks
...@@ -916,7 +1079,9 @@ GET /projects/:id/hooks ...@@ -916,7 +1079,9 @@ GET /projects/:id/hooks
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of a project | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
### Get project hook ### Get project hook
...@@ -928,8 +1093,10 @@ GET /projects/:id/hooks/:hook_id ...@@ -928,8 +1093,10 @@ GET /projects/:id/hooks/:hook_id
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of a project | Attribute | Type | Required | Description |
- `hook_id` (required) - The ID of a project hook | --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
| `hook_id` | integer | yes | The ID of a project hook |
```json ```json
{ {
...@@ -959,17 +1126,19 @@ POST /projects/:id/hooks ...@@ -959,17 +1126,19 @@ POST /projects/:id/hooks
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of a project | Attribute | Type | Required | Description |
- `url` (required) - The hook URL | --------- | ---- | -------- | ----------- |
- `push_events` - Trigger hook on push events | `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
- `issues_events` - Trigger hook on issues events | `url` | string | yes | The hook URL |
- `merge_requests_events` - Trigger hook on merge_requests events | `push_events` | boolean | no | Trigger hook on push events |
- `tag_push_events` - Trigger hook on push_tag events | `issues_events` | boolean | no | Trigger hook on issues events |
- `note_events` - Trigger hook on note events | `merge_requests_events` | boolean | no | Trigger hook on merge requests events |
- `build_events` - Trigger hook on build events | `tag_push_events` | boolean | no | Trigger hook on tag push events |
- `pipeline_events` - Trigger hook on pipeline events | `note_events` | boolean | no | Trigger hook on note events |
- `wiki_page_events` - Trigger hook on wiki page events | `build_events` | boolean | no | Trigger hook on build events |
- `enable_ssl_verification` - Do SSL verification when triggering the hook | `pipeline_events` | boolean | no | Trigger hook on pipeline events |
| `wiki_events` | boolean | no | Trigger hook on wiki events |
| `enable_ssl_verification` | boolean | no | Do SSL verification when triggering the hook |
### Edit project hook ### Edit project hook
...@@ -981,18 +1150,20 @@ PUT /projects/:id/hooks/:hook_id ...@@ -981,18 +1150,20 @@ PUT /projects/:id/hooks/:hook_id
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of a project | Attribute | Type | Required | Description |
- `hook_id` (required) - The ID of a project hook | --------- | ---- | -------- | ----------- |
- `url` (required) - The hook URL | `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
- `push_events` - Trigger hook on push events | `hook_id` | integer | yes | The ID of the project hook |
- `issues_events` - Trigger hook on issues events | `url` | string | yes | The hook URL |
- `merge_requests_events` - Trigger hook on merge_requests events | `push_events` | boolean | no | Trigger hook on push events |
- `tag_push_events` - Trigger hook on push_tag events | `issues_events` | boolean | no | Trigger hook on issues events |
- `note_events` - Trigger hook on note events | `merge_requests_events` | boolean | no | Trigger hook on merge requests events |
- `build_events` - Trigger hook on build events | `tag_push_events` | boolean | no | Trigger hook on tag push events |
- `pipeline_events` - Trigger hook on pipeline events | `note_events` | boolean | no | Trigger hook on note events |
- `wiki_page_events` - Trigger hook on wiki page events | `build_events` | boolean | no | Trigger hook on build events |
- `enable_ssl_verification` - Do SSL verification when triggering the hook | `pipeline_events` | boolean | no | Trigger hook on pipeline events |
| `wiki_events` | boolean | no | Trigger hook on wiki events |
| `enable_ssl_verification` | boolean | no | Do SSL verification when triggering the hook |
### Delete project hook ### Delete project hook
...@@ -1005,8 +1176,10 @@ DELETE /projects/:id/hooks/:hook_id ...@@ -1005,8 +1176,10 @@ DELETE /projects/:id/hooks/:hook_id
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of a project | Attribute | Type | Required | Description |
- `hook_id` (required) - The ID of hook to delete | --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
| `hook_id` | integer | yes | The ID of the project hook |
Note the JSON response differs if the hook is available or not. If the project hook Note the JSON response differs if the hook is available or not. If the project hook
is available before it is returned in the JSON response or an empty response is returned. is available before it is returned in the JSON response or an empty response is returned.
...@@ -1025,7 +1198,9 @@ GET /projects/:id/repository/branches ...@@ -1025,7 +1198,9 @@ GET /projects/:id/repository/branches
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of a project | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
```json ```json
[ [
...@@ -1080,10 +1255,12 @@ GET /projects/:id/repository/branches/:branch ...@@ -1080,10 +1255,12 @@ GET /projects/:id/repository/branches/:branch
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of a project | Attribute | Type | Required | Description |
- `branch` (required) - The name of the branch. | --------- | ---- | -------- | ----------- |
- `developers_can_push` - Flag if developers can push to the branch. | `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
- `developers_can_merge` - Flag if developers can merge to the branch. | `branch` | string | yes | The name of the branch |
| `developers_can_push` | boolean | no | Flag if developers can push to the branch |
| `developers_can_merge` | boolean | no | Flag if developers can merge to the branch |
### Protect single branch ### Protect single branch
...@@ -1095,8 +1272,10 @@ PUT /projects/:id/repository/branches/:branch/protect ...@@ -1095,8 +1272,10 @@ PUT /projects/:id/repository/branches/:branch/protect
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of a project | Attribute | Type | Required | Description |
- `branch` (required) - The name of the branch. | --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
| `branch` | string | yes | The name of the branch |
### Unprotect single branch ### Unprotect single branch
...@@ -1108,8 +1287,10 @@ PUT /projects/:id/repository/branches/:branch/unprotect ...@@ -1108,8 +1287,10 @@ PUT /projects/:id/repository/branches/:branch/unprotect
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of a project | Attribute | Type | Required | Description |
- `branch` (required) - The name of the branch. | --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
| `branch` | string | yes | The name of the branch |
## Admin fork relation ## Admin fork relation
...@@ -1123,8 +1304,10 @@ POST /projects/:id/fork/:forked_from_id ...@@ -1123,8 +1304,10 @@ POST /projects/:id/fork/:forked_from_id
Parameters: Parameters:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of the project to be forked | Attribute | Type | Required | Description |
- `forked_from_id:` (required) - The ID of the project that was forked from | --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
| `forked_from_id` | ID | yes | The ID of the project that was forked from |
### Delete an existing forked from relationship ### Delete an existing forked from relationship
...@@ -1134,7 +1317,9 @@ DELETE /projects/:id/fork ...@@ -1134,7 +1317,9 @@ DELETE /projects/:id/fork
Parameter: Parameter:
- `id` (required) - The ID or NAMESPACE/PROJECT_NAME of the project to be forked | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID of the project or NAMESPACE/PROJECT_NAME |
## Search for projects by name ## Search for projects by name
...@@ -1146,8 +1331,10 @@ GET /projects/search/:query ...@@ -1146,8 +1331,10 @@ GET /projects/search/:query
Parameters: Parameters:
- `query` (required) - A string contained in the project name | Attribute | Type | Required | Description |
- `per_page` (optional) - number of projects to return per page | --------- | ---- | -------- | ----------- |
- `page` (optional) - the page to retrieve | `query` (required) - A string contained in the project name
- `order_by` (optional) - Return requests ordered by `id`, `name`, `created_at` or `last_activity_at` fields | `per_page` (optional) - number of projects to return per page
- `sort` (optional) - Return requests sorted in `asc` or `desc` order | `page` (optional) - the page to retrieve
| `order_by` (optional) - Return requests ordered by `id`, `name`, `created_at` or `last_activity_at` fields
| `sort` | string | no | Return requests sorted in `asc` or `desc` order |
...@@ -22,14 +22,25 @@ module API ...@@ -22,14 +22,25 @@ module API
# Example Request: # Example Request:
# GET /projects # GET /projects
get do get do
@projects = current_user.authorized_projects projects = current_user.authorized_projects
@projects = filter_projects(@projects) projects = filter_projects(projects)
@projects = paginate @projects projects = paginate projects
if params[:simple] entity = params[:simple] ? Entities::BasicProjectDetails : Entities::ProjectWithAccess
present @projects, with: Entities::BasicProjectDetails, user: current_user
else present projects, with: entity, user: current_user
present @projects, with: Entities::ProjectWithAccess, user: current_user end
end
# Get a list of visible projects for authenticated user
#
# Example Request:
# GET /projects/visible
get '/visible' do
projects = ProjectsFinder.new.execute(current_user)
projects = filter_projects(projects)
projects = paginate projects
entity = params[:simple] ? Entities::BasicProjectDetails : Entities::ProjectWithAccess
present projects, with: entity, user: current_user
end end
# Get an owned projects list for authenticated user # Get an owned projects list for authenticated user
...@@ -37,10 +48,10 @@ module API ...@@ -37,10 +48,10 @@ module API
# Example Request: # Example Request:
# GET /projects/owned # GET /projects/owned
get '/owned' do get '/owned' do
@projects = current_user.owned_projects projects = current_user.owned_projects
@projects = filter_projects(@projects) projects = filter_projects(projects)
@projects = paginate @projects projects = paginate projects
present @projects, with: Entities::ProjectWithAccess, user: current_user present projects, with: Entities::ProjectWithAccess, user: current_user
end end
# Gets starred project for the authenticated user # Gets starred project for the authenticated user
...@@ -48,10 +59,10 @@ module API ...@@ -48,10 +59,10 @@ module API
# Example Request: # Example Request:
# GET /projects/starred # GET /projects/starred
get '/starred' do get '/starred' do
@projects = current_user.viewable_starred_projects projects = current_user.viewable_starred_projects
@projects = filter_projects(@projects) projects = filter_projects(projects)
@projects = paginate @projects projects = paginate projects
present @projects, with: Entities::Project, user: current_user present projects, with: Entities::Project, user: current_user
end end
# Get all projects for admin user # Get all projects for admin user
...@@ -60,10 +71,10 @@ module API ...@@ -60,10 +71,10 @@ module API
# GET /projects/all # GET /projects/all
get '/all' do get '/all' do
authenticated_as_admin! authenticated_as_admin!
@projects = Project.all projects = Project.all
@projects = filter_projects(@projects) projects = filter_projects(projects)
@projects = paginate @projects projects = paginate projects
present @projects, with: Entities::ProjectWithAccess, user: current_user present projects, with: Entities::ProjectWithAccess, user: current_user
end end
# Get a single project # Get a single project
......
...@@ -175,6 +175,36 @@ describe API::API, api: true do ...@@ -175,6 +175,36 @@ describe API::API, api: true do
end end
end end
describe 'GET /projects/visible' do
let(:public_project) { create(:project, :public) }
before do
public_project
project
project2
project3
project4
end
it 'returns the projects viewable by the user' do
get api('/projects/visible', user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.map { |project| project['id'] }).
to contain_exactly(public_project.id, project.id, project2.id, project3.id)
end
it 'shows only public projects when the user only has access to those' do
get api('/projects/visible', user2)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.map { |project| project['id'] }).
to contain_exactly(public_project.id)
end
end
describe 'GET /projects/starred' do describe 'GET /projects/starred' do
let(:public_project) { create(:project, :public) } let(:public_project) { create(:project, :public) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment