diff --git a/app/controllers/v1/quickpost_messages_controller.rb b/app/controllers/v1/quickpost_messages_controller.rb deleted file mode 100644 index d679a2ce..00000000 --- a/app/controllers/v1/quickpost_messages_controller.rb +++ /dev/null @@ -1,2 +0,0 @@ -class V1::QuickpostMessagesController < V1::ApplicationController -end diff --git a/app/jobs/user_archive_job.rb b/app/jobs/user_archive_job.rb index 06b27632..68fbe04d 100644 --- a/app/jobs/user_archive_job.rb +++ b/app/jobs/user_archive_job.rb @@ -61,7 +61,6 @@ def keep_entities # rubocop:disable Metrics/MethodLength PhotoAlbum, PhotoTag, Poll, - QuickpostMessage, Form::Form, Form::Response, Forum::Post, diff --git a/app/models/quickpost_message.rb b/app/models/quickpost_message.rb deleted file mode 100644 index 4afe4785..00000000 --- a/app/models/quickpost_message.rb +++ /dev/null @@ -1,14 +0,0 @@ -class QuickpostMessage < ApplicationRecord - belongs_to :author, class_name: 'User' - - validates :message, presence: true, length: { minimum: 1, maximum: 500 } - - after_create :publish_to_message_bus - - private - - def publish_to_message_bus - attributes = { id:, author_id: author.id, message:, created_at: } - MessageBus.publish('/quickpost_messages', attributes.to_json, group_ids: [0]) - end -end diff --git a/app/policies/quickpost_message_policy.rb b/app/policies/quickpost_message_policy.rb deleted file mode 100644 index 2e0e2290..00000000 --- a/app/policies/quickpost_message_policy.rb +++ /dev/null @@ -1,2 +0,0 @@ -class QuickpostMessagePolicy < ApplicationPolicy -end diff --git a/app/resources/v1/quickpost_message_resource.rb b/app/resources/v1/quickpost_message_resource.rb deleted file mode 100644 index 6e1412c7..00000000 --- a/app/resources/v1/quickpost_message_resource.rb +++ /dev/null @@ -1,17 +0,0 @@ -class V1::QuickpostMessageResource < V1::ApplicationResource - attributes :message - - has_one :author, always_include_linkage_data: true - - before_create do - @model.author_id = current_user.id - end - - def self.creatable_fields(_context) - [:message] - end - - def self.searchable_fields - %i[message] - end -end diff --git a/config/routes.rb b/config/routes.rb index d0299850..03c964d5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -73,7 +73,6 @@ end get 'users/me/nextcloud', to: 'users#nextcloud' - jsonapi_resources :quickpost_messages jsonapi_resources :vacancies namespace :debit do diff --git a/db/migrate/20241113091607_remove_quickpost.rb b/db/migrate/20241113091607_remove_quickpost.rb new file mode 100644 index 00000000..db94291c --- /dev/null +++ b/db/migrate/20241113091607_remove_quickpost.rb @@ -0,0 +1,10 @@ +class RemoveQuickpost < ActiveRecord::Migration[7.0] + def change + drop_table :quickpost_messages + + Permission.find_by(name: 'quickpost_message.create')&.destroy + Permission.find_by(name: 'quickpost_message.read')&.destroy + Permission.find_by(name: 'quickpost_message.update')&.destroy + Permission.find_by(name: 'quickpost_message.destroy')&.destroy + end +end diff --git a/db/schema.rb b/db/schema.rb index 6c71396d..3c73c96e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_10_27_103012) do +ActiveRecord::Schema[7.0].define(version: 2024_11_13_091607) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -474,18 +474,7 @@ t.index ["author_id"], name: "index_polls_on_author_id" t.index ["form_id"], name: "index_polls_on_form_id" end - - create_table "quickpost_messages", id: :serial, force: :cascade do |t| - t.integer "author_id" - t.text "message" - t.datetime "created_at", precision: nil, null: false - t.datetime "updated_at", precision: nil, null: false - t.datetime "deleted_at", precision: nil - t.datetime "datetime", precision: nil - t.index ["datetime"], name: "index_quickpost_messages_on_datetime" - t.index ["deleted_at"], name: "index_quickpost_messages_on_deleted_at" - end - +3 create_table "room_adverts", force: :cascade do |t| t.string "house_name", null: false t.string "contact", null: false diff --git a/db/seeds/content.rb b/db/seeds/content.rb index 2667adc2..d0a6f27a 100644 --- a/db/seeds/content.rb +++ b/db/seeds/content.rb @@ -45,10 +45,6 @@ end end -members.sample(80).each { |user| FactoryBot.create(:quickpost_message, author: user) } -# To ensure at least one user creating (more than) two quickpost messages -members.sample(30).each { |user| FactoryBot.create(:quickpost_message, author: user) } - members.sample(4).each do |user| FactoryBot.create(:activity, author: user) end diff --git a/db/seeds/permissions.rb b/db/seeds/permissions.rb index 2ecc1586..8a20026d 100644 --- a/db/seeds/permissions.rb +++ b/db/seeds/permissions.rb @@ -34,7 +34,6 @@ def create_permissions(permission_map) 'photo' => %i[create read update destroy], 'photo_comment' => %i[create read update destroy], 'photo_tag' => %i[create read update destroy], - 'quickpost_message' => %i[create read update destroy], 'room_advert' => %i[create read update destroy], 'stored_mail' => %i[read destroy], 'forum/category' => %i[create read update destroy], @@ -76,7 +75,6 @@ def create_permissions(permission_map) 'photo' => %i[create read], 'photo_comment' => %i[create read], 'photo_tag' => %i[create read], - 'quickpost_message' => %i[create read], 'room_advert' => %i[create read], 'forum/category' => %i[read], 'forum/thread' => %i[create read], @@ -111,7 +109,6 @@ def create_permissions(permission_map) 'photo' => %i[read], 'photo_comment' => %i[create read], 'photo_tag' => %i[create read], - 'quickpost_message' => %i[create read], 'room_advert' => %i[], 'forum/category' => %i[read], 'forum/thread' => %i[create read], diff --git a/spec/factories/quickpost_messages.rb b/spec/factories/quickpost_messages.rb deleted file mode 100644 index b5bf61ef..00000000 --- a/spec/factories/quickpost_messages.rb +++ /dev/null @@ -1,6 +0,0 @@ -FactoryBot.define do - factory :quickpost_message do - message { Faker::Lorem.sentence } - association :author, factory: :user - end -end diff --git a/spec/jobs/user_archive_job_spec.rb b/spec/jobs/user_archive_job_spec.rb index 9eb639df..a4d8abaf 100644 --- a/spec/jobs/user_archive_job_spec.rb +++ b/spec/jobs/user_archive_job_spec.rb @@ -17,7 +17,6 @@ create(:photo, uploader: user) create(:photo_album, author: user) create(:poll, author: user) - create(:quickpost_message, author: user) create(:response, user:) create(:form, author: user) create(:post, author: user) @@ -33,7 +32,6 @@ it { expect { job }.to change { Photo.last.uploader }.from(user).to(archive_user) } it { expect { job }.to change { PhotoAlbum.last.author }.from(user).to(archive_user) } it { expect { job }.to change { Poll.last.author }.from(user).to(archive_user) } - it { expect { job }.to change { QuickpostMessage.last.author }.from(user).to(archive_user) } it { expect { job }.to change { Form::Response.last.user }.from(user).to(archive_user) } it { expect { job }.to change { Form::Form.last.author }.from(user).to(archive_user) } it { expect { job }.to change { Forum::Post.last.author }.from(user).to(archive_user) } diff --git a/spec/models/quickpost_message_spec.rb b/spec/models/quickpost_message_spec.rb deleted file mode 100644 index ef68a501..00000000 --- a/spec/models/quickpost_message_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'rails_helper' - -RSpec.describe QuickpostMessage, type: :model do - subject(:quickpost_message) { build(:quickpost_message) } - - describe '#valid?' do - it { expect(quickpost_message.valid?).to be true } - - context 'when with an empty message' do - subject(:quickpost_message) { build(:quickpost_message, message: '') } - - it { expect(quickpost_message.valid?).to be false } - end - - context 'when with a too long message' do - subject(:quickpost_message) do - build(:quickpost_message, message: Faker::Lorem.characters(number: 501)) - end - - it { expect(quickpost_message.valid?).to be false } - end - - context 'when without a user' do - subject(:quickpost_message) { build(:quickpost_message, author: nil) } - - it { expect(quickpost_message.valid?).to be false } - end - end - - describe '#save' do - context 'when it is new' do - it do # rubocop:disable RSpec/ExampleLength - allow(MessageBus).to receive(:publish) - quickpost_message.save - expect(MessageBus).to have_received(:publish).with( - '/quickpost_messages', a_string_including(quickpost_message.author_id.to_s, - quickpost_message.message), - group_ids: [0] - ) - end - end - end -end diff --git a/spec/requests/v1/quickpost_messages_controller/create_spec.rb b/spec/requests/v1/quickpost_messages_controller/create_spec.rb deleted file mode 100644 index 0eccec31..00000000 --- a/spec/requests/v1/quickpost_messages_controller/create_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -describe V1::QuickpostMessagesController do - describe 'POST /quickpost_messages', version: 1 do - let(:record) { build_stubbed(:quickpost_message) } - let(:record_url) { '/v1/quickpost_messages' } - let(:record_permission) { 'quickpost_message.create' } - - it_behaves_like 'a creatable and permissible model' do - let(:invalid_attributes) { { message: '' } } - end - - it_behaves_like 'a creatable model with author' - end -end diff --git a/spec/requests/v1/quickpost_messages_controller/destroy_spec.rb b/spec/requests/v1/quickpost_messages_controller/destroy_spec.rb deleted file mode 100644 index 1a28dff2..00000000 --- a/spec/requests/v1/quickpost_messages_controller/destroy_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'rails_helper' - -describe V1::QuickpostMessagesController do - describe 'DELETE /quickpost_messages/:id', version: 1 do - it_behaves_like 'a destroyable and permissible model' do - let(:record) { create(:quickpost_message) } - let(:record_url) { "/v1/quickpost_messages/#{record.id}" } - let(:record_permission) { 'quickpost_message.destroy' } - end - end -end diff --git a/spec/requests/v1/quickpost_messages_controller/index_spec.rb b/spec/requests/v1/quickpost_messages_controller/index_spec.rb deleted file mode 100644 index 52cb583e..00000000 --- a/spec/requests/v1/quickpost_messages_controller/index_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -describe V1::QuickpostMessagesController do - describe 'GET /quickpost_messages', version: 1 do - let(:records) { create_list(:quickpost_message, 7) } - let(:record_url) { '/v1/quickpost_messages' } - let(:record_permission) { 'quickpost_message.read' } - - subject(:request) { get(record_url) } - - it_behaves_like 'a permissible model' - it_behaves_like 'an indexable model' - it_behaves_like 'a searchable model', %i[message] - end -end diff --git a/spec/requests/v1/quickpost_messages_controller/show_spec.rb b/spec/requests/v1/quickpost_messages_controller/show_spec.rb deleted file mode 100644 index 01ad41cb..00000000 --- a/spec/requests/v1/quickpost_messages_controller/show_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'rails_helper' - -describe V1::QuickpostMessagesController do - describe 'GET /quickpost_messages/:id', version: 1 do - it_behaves_like 'a permissible model' do - let(:record) { create(:quickpost_message) } - let(:record_url) { "/v1/quickpost_messages/#{record.id}" } - let(:record_permission) { 'quickpost_message.read' } - end - end -end