diff --git a/lib/travis/api/v3/access_control/user.rb b/lib/travis/api/v3/access_control/user.rb index 3376ffb9..b0b93f15 100644 --- a/lib/travis/api/v3/access_control/user.rb +++ b/lib/travis/api/v3/access_control/user.rb @@ -29,6 +29,10 @@ module Travis::API::V3 organization.members.include? user end + def user_writable?(user) + user == self.user + end + def repository_writable?(repository) permission?(:push, repository) end diff --git a/lib/travis/api/v3/permissions/user.rb b/lib/travis/api/v3/permissions/user.rb new file mode 100644 index 00000000..6aaf5af2 --- /dev/null +++ b/lib/travis/api/v3/permissions/user.rb @@ -0,0 +1,9 @@ +require 'travis/api/v3/permissions/generic' + +module Travis::API::V3 + class Permissions::User < Permissions::Generic + def sync? + write? + end + end +end diff --git a/spec/v3/services/owner/find_spec.rb b/spec/v3/services/owner/find_spec.rb index 53336475..66d3feca 100644 --- a/spec/v3/services/owner/find_spec.rb +++ b/spec/v3/services/owner/find_spec.rb @@ -151,15 +151,16 @@ describe Travis::API::V3::Services::Owner::Find do before { get("/v3/owner/example-user") } example { expect(last_response).to be_ok } example { expect(JSON.load(body)).to be == { - "@type" => "user", - "@href" => "/v3/user/#{user.id}", - "id" => user.id, - "login" => "example-user", - "name" => nil, - "github_id" => nil, - "avatar_url" => nil, - "is_syncing" => nil, - "synced_at" => nil + "@type" => "user", + "@href" => "/v3/user/#{user.id}", + "@permissions" => {"read"=>true, "sync"=>false}, + "id" => user.id, + "login" => "example-user", + "name" => nil, + "github_id" => nil, + "avatar_url" => nil, + "is_syncing" => nil, + "synced_at" => nil }} end @@ -167,15 +168,16 @@ describe Travis::API::V3::Services::Owner::Find do before { get("/v3/owner/example-USER") } example { expect(last_response).to be_ok } example { expect(JSON.load(body)).to be == { - "@type" => "user", - "@href" => "/v3/user/#{user.id}", - "id" => user.id, - "login" => "example-user", - "name" => nil, - "github_id" => nil, - "avatar_url" => nil, - "is_syncing" => nil, - "synced_at" => nil + "@type" => "user", + "@href" => "/v3/user/#{user.id}", + "@permissions" => {"read"=>true, "sync"=>false}, + "id" => user.id, + "login" => "example-user", + "name" => nil, + "github_id" => nil, + "avatar_url" => nil, + "is_syncing" => nil, + "synced_at" => nil }} end @@ -187,15 +189,16 @@ describe Travis::API::V3::Services::Owner::Find do before { get("/v3/owner/example-user?user.id=#{other.id}") } example { expect(last_response).to be_ok } example { expect(JSON.load(body)).to be == { - "@type" => "user", - "@href" => "/v3/user/#{user.id}", - "id" => user.id, - "login" => "example-user", - "name" => nil, - "github_id" => nil, - "avatar_url" => nil, - "is_syncing" => nil, - "synced_at" => nil + "@type" => "user", + "@href" => "/v3/user/#{user.id}", + "@permissions" => {"read"=>true, "sync"=>false}, + "id" => user.id, + "login" => "example-user", + "name" => nil, + "github_id" => nil, + "avatar_url" => nil, + "is_syncing" => nil, + "synced_at" => nil }} end end diff --git a/spec/v3/services/user/current_spec.rb b/spec/v3/services/user/current_spec.rb index 443671e6..88a1c920 100644 --- a/spec/v3/services/user/current_spec.rb +++ b/spec/v3/services/user/current_spec.rb @@ -10,15 +10,16 @@ describe Travis::API::V3::Services::User::Current do before { get("/v3/user", {}, headers) } example { expect(last_response).to be_ok } example { expect(JSON.load(body)).to be == { - "@type" => "user", - "@href" => "/v3/user/#{user.id}", - "id" => user.id, - "login" => "svenfuchs", - "name" =>"Sven Fuchs", - "github_id" => user.github_id, - "avatar_url" => "https://0.gravatar.com/avatar/07fb84848e68b96b69022d333ca8a3e2", - "is_syncing" => user.is_syncing, - "synced_at" => user.synced_at + "@type" => "user", + "@href" => "/v3/user/#{user.id}", + "@permissions" => {"read"=>true, "sync"=>true}, + "id" => user.id, + "login" => "svenfuchs", + "name" =>"Sven Fuchs", + "github_id" => user.github_id, + "avatar_url" => "https://0.gravatar.com/avatar/07fb84848e68b96b69022d333ca8a3e2", + "is_syncing" => user.is_syncing, + "synced_at" => user.synced_at }} end end \ No newline at end of file diff --git a/spec/v3/services/user/find_spec.rb b/spec/v3/services/user/find_spec.rb index 30ee4800..b493bc40 100644 --- a/spec/v3/services/user/find_spec.rb +++ b/spec/v3/services/user/find_spec.rb @@ -10,15 +10,16 @@ describe Travis::API::V3::Services::User::Find do before { get("/v3/user/#{user.id}", {}, headers) } example { expect(last_response).to be_ok } example { expect(JSON.load(body)).to be == { - "@type" => "user", - "@href" => "/v3/user/#{user.id}", - "id" => user.id, - "login" => "svenfuchs", - "name" =>"Sven Fuchs", - "github_id" => user.github_id, - "avatar_url" => "https://0.gravatar.com/avatar/07fb84848e68b96b69022d333ca8a3e2", - "is_syncing" => user.is_syncing, - "synced_at" => user.synced_at + "@type" => "user", + "@href" => "/v3/user/#{user.id}", + "@permissions" => {"read"=>true, "sync"=>true}, + "id" => user.id, + "login" => "svenfuchs", + "name" =>"Sven Fuchs", + "github_id" => user.github_id, + "avatar_url" => "https://0.gravatar.com/avatar/07fb84848e68b96b69022d333ca8a3e2", + "is_syncing" => user.is_syncing, + "synced_at" => user.synced_at }} end end \ No newline at end of file