summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2018-06-18 12:02:56 +0200
committerDouwe Maan <douwe@selenight.nl>2018-06-18 12:04:51 +0200
commit07e95b0cd48192804324a3c47729b5641df54fe6 (patch)
tree9a8c01fae471f0c457b0934883d401c0297ab8e6
parent99fdbe4c230205510e1d7061e68bb1a003913d4b (diff)
downloadgitlab-ce-dm-branch-api-can-push.tar.gz
Expose whether current user can push into a branch on branches APIdm-branch-api-can-push
-rw-r--r--changelogs/unreleased/dm-branch-api-can-push.yml5
-rw-r--r--doc/api/branches.md11
-rw-r--r--lib/api/entities.rb4
-rw-r--r--spec/fixtures/api/schemas/public_api/v4/branch.json3
4 files changed, 19 insertions, 4 deletions
diff --git a/changelogs/unreleased/dm-branch-api-can-push.yml b/changelogs/unreleased/dm-branch-api-can-push.yml
new file mode 100644
index 00000000000..3be8962089b
--- /dev/null
+++ b/changelogs/unreleased/dm-branch-api-can-push.yml
@@ -0,0 +1,5 @@
+---
+title: Expose whether current user can push into a branch on branches API
+merge_request:
+author:
+type: added
diff --git a/doc/api/branches.md b/doc/api/branches.md
index 01bb30c3859..bfb21608d28 100644
--- a/doc/api/branches.md
+++ b/doc/api/branches.md
@@ -29,6 +29,7 @@ Example response:
"protected": true,
"developers_can_push": false,
"developers_can_merge": false,
+ "can_push": true,
"commit": {
"author_email": "john@example.com",
"author_name": "John Smith",
@@ -76,6 +77,7 @@ Example response:
"protected": true,
"developers_can_push": false,
"developers_can_merge": false,
+ "can_push": true,
"commit": {
"author_email": "john@example.com",
"author_name": "John Smith",
@@ -140,7 +142,8 @@ Example response:
"merged": false,
"protected": true,
"developers_can_push": true,
- "developers_can_merge": true
+ "developers_can_merge": true,
+ "can_push": true
}
```
@@ -188,7 +191,8 @@ Example response:
"merged": false,
"protected": false,
"developers_can_push": false,
- "developers_can_merge": false
+ "developers_can_merge": false,
+ "can_push": true
}
```
@@ -231,7 +235,8 @@ Example response:
"merged": false,
"protected": false,
"developers_can_push": false,
- "developers_can_merge": false
+ "developers_can_merge": false,
+ "can_push": true
}
```
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 1cc8fcb8408..bb48a86fe9e 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -349,6 +349,10 @@ module API
expose :developers_can_merge do |repo_branch, options|
options[:project].protected_branches.developers_can?(:merge, repo_branch.name)
end
+
+ expose :can_push do |repo_branch, options|
+ Gitlab::UserAccess.new(options[:current_user], project: options[:project]).can_push_to_branch?(repo_branch.name)
+ end
end
class TreeObject < Grape::Entity
diff --git a/spec/fixtures/api/schemas/public_api/v4/branch.json b/spec/fixtures/api/schemas/public_api/v4/branch.json
index a3581178974..a8891680d06 100644
--- a/spec/fixtures/api/schemas/public_api/v4/branch.json
+++ b/spec/fixtures/api/schemas/public_api/v4/branch.json
@@ -14,7 +14,8 @@
"merged": { "type": "boolean" },
"protected": { "type": "boolean" },
"developers_can_push": { "type": "boolean" },
- "developers_can_merge": { "type": "boolean" }
+ "developers_can_merge": { "type": "boolean" },
+ "can_push": { "type": "boolean" }
},
"additionalProperties": false
}