mirror of https://github.com/mastodon/mastodon
First draft of Collection update API (#37110)
parent
9cf52fb976
commit
5a7a4fff11
@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CollectionPolicy < ApplicationPolicy
|
||||
def index?
|
||||
true
|
||||
end
|
||||
|
||||
def show?
|
||||
true
|
||||
end
|
||||
|
||||
def create?
|
||||
user_signed_in?
|
||||
end
|
||||
|
||||
def update?
|
||||
owner?
|
||||
end
|
||||
|
||||
def destroy?
|
||||
owner?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def owner?
|
||||
current_account == record.account
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,43 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe CollectionPolicy do
|
||||
let(:policy) { described_class }
|
||||
let(:collection) { Fabricate(:collection) }
|
||||
let(:owner) { collection.account }
|
||||
let(:other_user) { Fabricate(:account) }
|
||||
|
||||
permissions :index? do
|
||||
it 'permits everyone to index' do
|
||||
expect(policy).to permit(nil, Collection)
|
||||
expect(policy).to permit(owner, Collection)
|
||||
end
|
||||
end
|
||||
|
||||
permissions :show? do
|
||||
it 'permits everyone to show' do
|
||||
expect(policy).to permit(nil, collection)
|
||||
expect(policy).to permit(owner, collection)
|
||||
expect(policy).to permit(other_user, collection)
|
||||
end
|
||||
end
|
||||
|
||||
permissions :create? do
|
||||
it 'permits any user' do
|
||||
expect(policy).to_not permit(nil, Collection)
|
||||
|
||||
expect(policy).to permit(owner, Collection)
|
||||
expect(policy).to permit(other_user, Collection)
|
||||
end
|
||||
end
|
||||
|
||||
permissions :update?, :destroy? do
|
||||
it 'only permits the owner' do
|
||||
expect(policy).to_not permit(nil, collection)
|
||||
expect(policy).to_not permit(other_user, collection)
|
||||
|
||||
expect(policy).to permit(owner, collection)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue