Skip to content

Commit

Permalink
chore: add patch_can_create? method
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jun 9, 2022
1 parent 0608f60 commit e371ca8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/pact_broker/api/resources/base_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ def content_type_json?
def put_can_create?
false
end

# Not a Webmachine method. This is used by security policy code to identify whether
# a PATCH to a non existing resource can create a new object.
def patch_can_create?
false
end
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/pact_broker/api/resources/deployed_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def allowed_methods
["GET", "PATCH", "OPTIONS"]
end

def patch_can_create?
false
end

def resource_exists?
!!deployed_version
end
Expand Down
4 changes: 4 additions & 0 deletions lib/pact_broker/api/resources/pact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def put_can_create?
true
end

def patch_can_create?
true
end

def is_conflict?
merge_conflict = request.patch? && resource_exists? && Pacts::Merger.conflict?(pact.json_content, pact_params.json_content)

Expand Down
5 changes: 5 additions & 0 deletions lib/pact_broker/api/resources/pacticipant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def put_can_create?
false
end

def patch_can_create?
true
end

def known_methods
super + ["PATCH"]
end
Expand All @@ -48,6 +52,7 @@ def from_json
response.body = to_json
end

# PUT or PATCH with content-type application/merge-patch+json
def from_merge_patch_json
if request.patch?
from_json
Expand Down
4 changes: 4 additions & 0 deletions lib/pact_broker/api/resources/released_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def allowed_methods
["GET", "PATCH", "OPTIONS"]
end

def patch_can_create?
false
end

def resource_exists?
!!released_version
end
Expand Down
4 changes: 4 additions & 0 deletions lib/pact_broker/api/resources/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def put_can_create?
true
end

def patch_can_create?
true
end

def resource_exists?
!!version
end
Expand Down

0 comments on commit e371ca8

Please sign in to comment.