refinery / refinerycms-news

News Plugin for Refinery CMS
http://www.refinerycms.com
MIT License
121 stars 120 forks source link

weired behavior when i try to destory news #142

Closed dfang closed 10 years ago

dfang commented 10 years ago

i'm using gem 'refinerycms-news', '~> 2.1.0' and below is a DELETE request in backend:

Started DELETE "/refinery/news/items/15" for 127.0.0.1 at 2013-12-27 01:19:04 +0800
  Refinery::Role Load (0.1ms)  SELECT "refinery_roles".* FROM "refinery_roles"
Processing by Refinery::News::Admin::ItemsController#destroy as HTML
  Parameters: {"authenticity_token"=>"zUy10UGFvttSkwDFxSv5XbHdc5rTBN84e1xcTwFeR9Y=", "id"=>"15", "locale"=>:en}
  Refinery::News::Item Load (0.4ms)  SELECT "refinery_news_items".* FROM "refinery_news_items" WHERE "refinery_news_items"."slug" = '15' ORDER BY publish_date DESC LIMIT 1
  SQL (0.3ms)  SELECT DISTINCT "refinery_news_items".id, publish_date AS alias_0 FROM "refinery_news_items" LEFT OUTER JOIN "refinery_news_item_translations" ON "refinery_news_item_translations"."refinery_news_item_id" = "refinery_news_items"."id" WHERE "refinery_news_item_translations"."locale" IN ('en', 'en') AND "refinery_news_item_translations"."slug" = '15' ORDER BY publish_date DESC LIMIT 1
  Refinery::News::Item Load (0.2ms)  SELECT "refinery_news_items".* FROM "refinery_news_items" WHERE "refinery_news_items"."id" = $1 ORDER BY publish_date DESC LIMIT 1  [["id", "15"]]
  Refinery::Role Load (0.3ms)  SELECT "refinery_roles".* FROM "refinery_roles" WHERE "refinery_roles"."title" = 'Refinery' LIMIT 1
  Refinery::User Load (0.3ms)  SELECT "refinery_users".* FROM "refinery_users" INNER JOIN "refinery_roles_users" ON "refinery_users"."id" = "refinery_roles_users"."user_id" WHERE "refinery_roles_users"."role_id" = 1
  Refinery::User Load (0.4ms)  SELECT "refinery_users".* FROM "refinery_users" WHERE "refinery_users"."id" = 1 LIMIT 1
  Refinery::UserPlugin Load (0.2ms)  SELECT "refinery_user_plugins".* FROM "refinery_user_plugins" WHERE "refinery_user_plugins"."user_id" = 1 ORDER BY position ASC
  Refinery::Role Load (0.4ms)  SELECT "refinery_roles".* FROM "refinery_roles" INNER JOIN "refinery_roles_users" ON "refinery_roles"."id" = "refinery_roles_users"."role_id" WHERE "refinery_roles_users"."user_id" = 1
  Refinery::News::Item::Translation Load (0.3ms)  SELECT "refinery_news_item_translations".* FROM "refinery_news_item_translations" WHERE "refinery_news_item_translations"."refinery_news_item_id" = 15
   (0.1ms)  BEGIN
  SQL (0.2ms)  DELETE FROM "refinery_news_item_translations" WHERE "refinery_news_item_translations"."id" = $1  [["id", 21]]
  SQL (0.1ms)  DELETE FROM "refinery_news_item_translations" WHERE "refinery_news_item_translations"."id" = $1  [["id", 20]]
  Refinery::Role Load (0.4ms)  SELECT "refinery_roles".* FROM "refinery_roles" WHERE "refinery_roles"."resource_id" = 15 AND "refinery_roles"."resource_type" = 'Refinery::News::Item'
PG::UndefinedColumn: ERROR:  column refinery_roles.resource_id does not exist
LINE 1: ...T "refinery_roles".* FROM "refinery_roles"  WHERE "refinery_...
                                                             ^
: SELECT "refinery_roles".* FROM "refinery_roles"  WHERE "refinery_roles"."resource_id" = 15 AND "refinery_roles"."resource_type" = 'Refinery::News::Item'
   (0.1ms)  ROLLBACK
Completed 500 Internal Server Error in 160.6ms

when i try to destroy a news, why would refinerycms try to load refinery roles?

thanks !

ugisozols commented 10 years ago

It checks for roles to validate your access to the admin area.

Have you added any custom functionality to refinerycms-news?

dfang commented 10 years ago

yes, i added a tab to news like refinery-page-images gem did to pages backend, but i can't find the callback.

i know it is something to check permission, but i can' t locate it.

can you help? below is all callbacks for a news item:

> f = Refinery::News::Item.first
> f._destroy_callbacks
=> [#<ActiveSupport::Callbacks::Callback:0x007fec74625288
  @callback_id=346,
  @chain=
   [#<ActiveSupport::Callbacks::Callback:0x007fec74625288 ...>,
    #<ActiveSupport::Callbacks::Callback:0x007fec745ee300
     @callback_id=320,
     @chain=[#<ActiveSupport::Callbacks::Callback:0x007fec745ee300 ...>],
     @compiled_options="true",
     @filter="(has_many_dependent_for_translations)",
     @kind=:before,
     @klass=
      Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: intege
     @options={:if=>[], :unless=>[]},
     @per_key={:if=>[], :unless=>[]},
     @raw_filter="has_many_dependent_for_translations">],
  @compiled_options="true && (!halted && value != false)",
  @filter=:remove_from_index,
  @kind=:after,
  @klass=
   Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: integer,
  @options={:prepend=>true, :if=>["!halted && value != false"], :unless=>[]},
  @per_key={:if=>[], :unless=>[]},
  @raw_filter=:remove_from_index>,
 #<ActiveSupport::Callbacks::Callback:0x007fec745ee300
  @callback_id=320,
  @chain=[#<ActiveSupport::Callbacks::Callback:0x007fec745ee300 ...>],
  @compiled_options="true",
  @filter="(has_many_dependent_for_translations)",
  @kind=:before,
  @klass=
   Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: integer,
  @options={:if=>[], :unless=>[]},
  @per_key={:if=>[], :unless=>[]},
  @raw_filter="has_many_dependent_for_translations">,
 #<ActiveSupport::Callbacks::Callback:0x007fec74ec0a00
  @callback_id=464,
  @chain=
   [#<ActiveSupport::Callbacks::Callback:0x007fec74625288
     @callback_id=346,
     @chain=
      [#<ActiveSupport::Callbacks::Callback:0x007fec74625288 ...>,
       #<ActiveSupport::Callbacks::Callback:0x007fec745ee300
        @callback_id=320,
        @chain=[#<ActiveSupport::Callbacks::Callback:0x007fec745ee300 ...>],
        @compiled_options="true",
        @filter="(has_many_dependent_for_translations)",
        @kind=:before,
        @klass=
         Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: int
        @options={:if=>[], :unless=>[]},
        @per_key={:if=>[], :unless=>[]},
        @raw_filter="has_many_dependent_for_translations">],
     @compiled_options="true && (!halted && value != false)",
     @filter=:remove_from_index,
     @kind=:after,
     @klass=
      Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: intege
     @options=
      {:prepend=>true, :if=>["!halted && value != false"], :unless=>[]},
     @per_key={:if=>[], :unless=>[]},
     @raw_filter=:remove_from_index>,
    #<ActiveSupport::Callbacks::Callback:0x007fec745ee300
     @callback_id=320,
     @chain=[#<ActiveSupport::Callbacks::Callback:0x007fec745ee300 ...>],
     @compiled_options="true",
     @filter="(has_many_dependent_for_translations)",
     @kind=:before,
     @klass=
      Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: intege
     @options={:if=>[], :unless=>[]},
     @per_key={:if=>[], :unless=>[]},
     @raw_filter="has_many_dependent_for_translations">,
    #<ActiveSupport::Callbacks::Callback:0x007fec74ec0a00 ...>],
  @compiled_options="true",
  @filter="(has_many_dependent_for_roles)",
  @kind=:before,
  @klass=
   Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: integer,
  @options={:if=>[], :unless=>[]},
  @per_key={:if=>[], :unless=>[]},
  @raw_filter="has_many_dependent_for_roles">,
 #<ActiveSupport::Callbacks::Callback:0x007fec74f42168
  @callback_id=490,
  @chain=
   [#<ActiveSupport::Callbacks::Callback:0x007fec74625288
     @callback_id=346,
     @chain=
      [#<ActiveSupport::Callbacks::Callback:0x007fec74625288 ...>,
       #<ActiveSupport::Callbacks::Callback:0x007fec745ee300
        @callback_id=320,
        @chain=[#<ActiveSupport::Callbacks::Callback:0x007fec745ee300 ...>],
        @compiled_options="true",
        @filter="(has_many_dependent_for_translations)",
        @kind=:before,
        @klass=
         Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: int
        @options={:if=>[], :unless=>[]},
        @per_key={:if=>[], :unless=>[]},
        @raw_filter="has_many_dependent_for_translations">],
     @compiled_options="true && (!halted && value != false)",
     @filter=:remove_from_index,
     @kind=:after,
     @klass=
      Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: intege
     @options=
      {:prepend=>true, :if=>["!halted && value != false"], :unless=>[]},
     @per_key={:if=>[], :unless=>[]},
     @raw_filter=:remove_from_index>,
    #<ActiveSupport::Callbacks::Callback:0x007fec745ee300
     @callback_id=320,
     @chain=[#<ActiveSupport::Callbacks::Callback:0x007fec745ee300 ...>],
     @compiled_options="true",
     @filter="(has_many_dependent_for_translations)",
     @kind=:before,
     @klass=
      Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: intege
     @options={:if=>[], :unless=>[]},
     @per_key={:if=>[], :unless=>[]},
     @raw_filter="has_many_dependent_for_translations">,
    #<ActiveSupport::Callbacks::Callback:0x007fec74ec0a00
     @callback_id=464,
     @chain=
      [#<ActiveSupport::Callbacks::Callback:0x007fec74625288
        @callback_id=346,
        @chain=
         [#<ActiveSupport::Callbacks::Callback:0x007fec74625288 ...>,
          #<ActiveSupport::Callbacks::Callback:0x007fec745ee300
           @callback_id=320,
           @chain=[#<ActiveSupport::Callbacks::Callback:0x007fec745ee300 ...>],
           @compiled_options="true",
           @filter="(has_many_dependent_for_translations)",
           @kind=:before,
           @klass=
            Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id:
           @options={:if=>[], :unless=>[]},
           @per_key={:if=>[], :unless=>[]},
           @raw_filter="has_many_dependent_for_translations">],
        @compiled_options="true && (!halted && value != false)",
        @filter=:remove_from_index,
        @kind=:after,
        @klass=
         Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: int
        @options=
         {:prepend=>true, :if=>["!halted && value != false"], :unless=>[]},
        @per_key={:if=>[], :unless=>[]},
        @raw_filter=:remove_from_index>,
       #<ActiveSupport::Callbacks::Callback:0x007fec745ee300
        @callback_id=320,
        @chain=[#<ActiveSupport::Callbacks::Callback:0x007fec745ee300 ...>],
        @compiled_options="true",
        @filter="(has_many_dependent_for_translations)",
        @kind=:before,
        @klass=
         Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: int
        @options={:if=>[], :unless=>[]},
        @per_key={:if=>[], :unless=>[]},
        @raw_filter="has_many_dependent_for_translations">,
       #<ActiveSupport::Callbacks::Callback:0x007fec74ec0a00 ...>],
     @compiled_options="true",
     @filter="(has_many_dependent_for_roles)",
     @kind=:before,
     @klass=
      Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: intege
     @options={:if=>[], :unless=>[]},
     @per_key={:if=>[], :unless=>[]},
     @raw_filter="has_many_dependent_for_roles">,
    #<ActiveSupport::Callbacks::Callback:0x007fec74f42168 ...>],
  @compiled_options="true",
  @filter="(has_many_dependent_for_roles)",
  @kind=:before,
  @klass=
   Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: integer,
  @options={:if=>[], :unless=>[]},
  @per_key={:if=>[], :unless=>[]},
  @raw_filter="has_many_dependent_for_roles">,
 #<ActiveSupport::Callbacks::Callback:0x007fec7889ad70
  @callback_id=616,
  @chain=
   [#<ActiveSupport::Callbacks::Callback:0x007fec74625288
     @callback_id=346,
     @chain=
      [#<ActiveSupport::Callbacks::Callback:0x007fec74625288 ...>,
       #<ActiveSupport::Callbacks::Callback:0x007fec745ee300
        @callback_id=320,
        @chain=[#<ActiveSupport::Callbacks::Callback:0x007fec745ee300 ...>],
        @compiled_options="true",
        @filter="(has_many_dependent_for_translations)",
        @kind=:before,
        @klass=
         Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: int
        @options={:if=>[], :unless=>[]},
        @per_key={:if=>[], :unless=>[]},
        @raw_filter="has_many_dependent_for_translations">],
     @compiled_options="true && (!halted && value != false)",
     @filter=:remove_from_index,
     @kind=:after,
     @klass=
      Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: intege
     @options=
      {:prepend=>true, :if=>["!halted && value != false"], :unless=>[]},
     @per_key={:if=>[], :unless=>[]},
     @raw_filter=:remove_from_index>,
    #<ActiveSupport::Callbacks::Callback:0x007fec745ee300
     @callback_id=320,
     @chain=[#<ActiveSupport::Callbacks::Callback:0x007fec745ee300 ...>],
     @compiled_options="true",
     @filter="(has_many_dependent_for_translations)",
     @kind=:before,
     @klass=
      Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: intege
     @options={:if=>[], :unless=>[]},
     @per_key={:if=>[], :unless=>[]},
     @raw_filter="has_many_dependent_for_translations">,
    #<ActiveSupport::Callbacks::Callback:0x007fec74ec0a00
     @callback_id=464,
     @chain=
      [#<ActiveSupport::Callbacks::Callback:0x007fec74625288
        @callback_id=346,
        @chain=
         [#<ActiveSupport::Callbacks::Callback:0x007fec74625288 ...>,
          #<ActiveSupport::Callbacks::Callback:0x007fec745ee300
           @callback_id=320,
           @chain=[#<ActiveSupport::Callbacks::Callback:0x007fec745ee300 ...>],
           @compiled_options="true",
           @filter="(has_many_dependent_for_translations)",
           @kind=:before,
           @klass=
            Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id:
           @options={:if=>[], :unless=>[]},
           @per_key={:if=>[], :unless=>[]},
           @raw_filter="has_many_dependent_for_translations">],
        @compiled_options="true && (!halted && value != false)",
        @filter=:remove_from_index,
        @kind=:after,
        @klass=
         Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: int
        @options=
         {:prepend=>true, :if=>["!halted && value != false"], :unless=>[]},
        @per_key={:if=>[], :unless=>[]},
        @raw_filter=:remove_from_index>,
       #<ActiveSupport::Callbacks::Callback:0x007fec745ee300
        @callback_id=320,
        @chain=[#<ActiveSupport::Callbacks::Callback:0x007fec745ee300 ...>],
        @compiled_options="true",
        @filter="(has_many_dependent_for_translations)",
        @kind=:before,
        @klass=
         Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: int
        @options={:if=>[], :unless=>[]},
        @per_key={:if=>[], :unless=>[]},
        @raw_filter="has_many_dependent_for_translations">,
       #<ActiveSupport::Callbacks::Callback:0x007fec74ec0a00 ...>],
     @compiled_options="true",
     @filter="(has_many_dependent_for_roles)",
     @kind=:before,
     @klass=
      Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: intege
     @options={:if=>[], :unless=>[]},
     @per_key={:if=>[], :unless=>[]},
     @raw_filter="has_many_dependent_for_roles">,
    #<ActiveSupport::Callbacks::Callback:0x007fec74f42168
     @callback_id=490,
     @chain=
      [#<ActiveSupport::Callbacks::Callback:0x007fec74625288
        @callback_id=346,
        @chain=
         [#<ActiveSupport::Callbacks::Callback:0x007fec74625288 ...>,
          #<ActiveSupport::Callbacks::Callback:0x007fec745ee300
           @callback_id=320,
           @chain=[#<ActiveSupport::Callbacks::Callback:0x007fec745ee300 ...>],
           @compiled_options="true",
           @filter="(has_many_dependent_for_translations)",
           @kind=:before,
           @klass=
            Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id:
           @options={:if=>[], :unless=>[]},
           @per_key={:if=>[], :unless=>[]},
           @raw_filter="has_many_dependent_for_translations">],
        @compiled_options="true && (!halted && value != false)",
        @filter=:remove_from_index,
        @kind=:after,
        @klass=
         Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: int
        @options=
         {:prepend=>true, :if=>["!halted && value != false"], :unless=>[]},
        @per_key={:if=>[], :unless=>[]},
        @raw_filter=:remove_from_index>,
       #<ActiveSupport::Callbacks::Callback:0x007fec745ee300
        @callback_id=320,
        @chain=[#<ActiveSupport::Callbacks::Callback:0x007fec745ee300 ...>],
        @compiled_options="true",
        @filter="(has_many_dependent_for_translations)",
        @kind=:before,
        @klass=
         Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: int
        @options={:if=>[], :unless=>[]},
        @per_key={:if=>[], :unless=>[]},
        @raw_filter="has_many_dependent_for_translations">,
       #<ActiveSupport::Callbacks::Callback:0x007fec74ec0a00
        @callback_id=464,
        @chain=
         [#<ActiveSupport::Callbacks::Callback:0x007fec74625288
           @callback_id=346,
           @chain=
            [#<ActiveSupport::Callbacks::Callback:0x007fec74625288 ...>,
             #<ActiveSupport::Callbacks::Callback:0x007fec745ee300
              @callback_id=320,
              @chain=
               [#<ActiveSupport::Callbacks::Callback:0x007fec745ee300 ...>],
              @compiled_options="true",
              @filter="(has_many_dependent_for_translations)",
              @kind=:before,
              @klass=
               Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_i
              @options={:if=>[], :unless=>[]},
              @per_key={:if=>[], :unless=>[]},
              @raw_filter="has_many_dependent_for_translations">],
           @compiled_options="true && (!halted && value != false)",
           @filter=:remove_from_index,
           @kind=:after,
           @klass=
            Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id:
           @options=
            {:prepend=>true, :if=>["!halted && value != false"], :unless=>[]},
           @per_key={:if=>[], :unless=>[]},
           @raw_filter=:remove_from_index>,
          #<ActiveSupport::Callbacks::Callback:0x007fec745ee300
           @callback_id=320,
           @chain=[#<ActiveSupport::Callbacks::Callback:0x007fec745ee300 ...>],
           @compiled_options="true",
           @filter="(has_many_dependent_for_translations)",
           @kind=:before,
           @klass=
            Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id:
           @options={:if=>[], :unless=>[]},
           @per_key={:if=>[], :unless=>[]},
           @raw_filter="has_many_dependent_for_translations">,
          #<ActiveSupport::Callbacks::Callback:0x007fec74ec0a00 ...>],
        @compiled_options="true",
        @filter="(has_many_dependent_for_roles)",
        @kind=:before,
        @klass=
         Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: int
        @options={:if=>[], :unless=>[]},
        @per_key={:if=>[], :unless=>[]},
        @raw_filter="has_many_dependent_for_roles">,
       #<ActiveSupport::Callbacks::Callback:0x007fec74f42168 ...>],
     @compiled_options="true",
     @filter="(has_many_dependent_for_roles)",
     @kind=:before,
     @klass=
      Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: intege
     @options={:if=>[], :unless=>[]},
     @per_key={:if=>[], :unless=>[]},
     @raw_filter="has_many_dependent_for_roles">,
    #<ActiveSupport::Callbacks::Callback:0x007fec7889ad70 ...>],
  @compiled_options="true",
  @filter="(has_many_dependent_for_roles)",
  @kind=:before,
  @klass=
   Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: integer,
  @options={:if=>[], :unless=>[]},
  @per_key={:if=>[], :unless=>[]},
  @raw_filter="has_many_dependent_for_roles">,
 #<ActiveSupport::Callbacks::Callback:0x007fec74a12e40
  @callback_id=618,
  @chain=[...],
  @compiled_options="true",
  @filter="(has_many_dependent_for_roles)",
  @kind=:before,
  @klass=
   Refinery::News::Item(id: integer, title: string, body: text, publish_date: datetime, created_at: datetime, updated_at: datetime, image_id: integer,
  @options={:if=>[], :unless=>[]},
  @per_key={:if=>[], :unless=>[]},
  @raw_filter="has_many_dependent_for_roles">]

thanks very much !

ugisozols commented 10 years ago

Can you share the source code of your application? It would be easier to understand what's going on.

dfang commented 10 years ago

@ugisozols, sorry, i can't share all the code, maybe there's a bug in refinery-page-images, i just change destroy to delete to avoid callbacks ...

thanks !

ugisozols commented 10 years ago

Maybe there is in fact a bug in refinery-page-images but it's hard to help debug if we can't see the custom code.