Skip to content

Remove Post's publisher #484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def resources

def set_user_id(p)
if current_user.manages?(current_organization)
p.update publisher_id: current_user.id
p.reverse_merge! user_id: current_user.id
else
p.update user_id: current_user.id
Expand All @@ -109,7 +108,7 @@ def set_user_id(p)
def post_params
permitted_fields = [:description, :end_on, :global, :joinable, :permanent,
:start_on, :title, :category_id, :user_id, :is_group,
:publisher_id, :active, tag_list: []]
:active, tag_list: []]

params.fetch(resource, {}).permit(*permitted_fields).tap do |p|
set_user_id(p)
Expand Down
1 change: 0 additions & 1 deletion app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def self.inherited(child)
belongs_to :category
belongs_to :user
belongs_to :organization
belongs_to :publisher, class_name: "User", foreign_key: "publisher_id"
has_many :transfers
has_many :movements, through: :transfers
has_many :events, dependent: :destroy
Expand Down
1 change: 0 additions & 1 deletion app/views/shared/_post_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
class: "form-control",
required: true %>
</div>
<%= f.hidden_field :publisher_id, value: current_user.id %>
<% end %>
<p class="help-block">
<%= t "global.required_field" %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20190322180602_remove_publisher_id_from_posts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemovePublisherIdFromPosts < ActiveRecord::Migration
def change
remove_column :posts, :publisher_id
end
end
4 changes: 1 addition & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20190319121401) do
ActiveRecord::Schema.define(version: 20190322180602) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -147,15 +147,13 @@
t.datetime "created_at"
t.datetime "updated_at"
t.text "tags", array: true
t.integer "publisher_id"
t.integer "organization_id"
t.boolean "active", default: true
t.boolean "is_group", default: false
end

add_index "posts", ["category_id"], name: "index_posts_on_category_id", using: :btree
add_index "posts", ["organization_id"], name: "index_posts_on_organization_id", using: :btree
add_index "posts", ["publisher_id"], name: "index_posts_on_publisher_id", using: :btree
add_index "posts", ["tags"], name: "index_posts_on_tags", using: :gin
add_index "posts", ["user_id"], name: "index_posts_on_user_id", using: :btree

Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
end

it 'links to new_transfer_path for his individual offers' do
offer = Fabricate(:offer, user: user, publisher: user, organization: test_organization)
offer = Fabricate(:offer, user: user, organization: test_organization)

get "show", id: user.id
expect(response.body).to include(
Expand All @@ -176,7 +176,7 @@
end

it 'links to new_transfer_path for his individual offers' do
offer = Fabricate(:offer, user: user, publisher: user, organization: test_organization)
offer = Fabricate(:offer, user: user, organization: test_organization)

get "show", id: user.id
expect(response.body).to include(
Expand Down
1 change: 0 additions & 1 deletion spec/models/post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
describe 'Relations' do
it { is_expected.to belong_to(:category) }
it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:publisher) }
it { is_expected.to have_many(:transfers) }
it { is_expected.to have_many(:movements) }
it { is_expected.to have_many(:events) }
Expand Down