myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [3109] branches/events: added authorisation to ev


From: noreply
Subject: [myexperiment-hackers] [3109] branches/events: added authorisation to events
Date: Fri, 24 Aug 2012 22:58:01 +0000 (UTC)

Revision
3109
Author
dgc
Date
2012-08-24 22:58:01 +0000 (Fri, 24 Aug 2012)

Log Message

added authorisation to events

Modified Paths

Diff

Modified: branches/events/app/controllers/blobs_controller.rb (3108 => 3109)


--- branches/events/app/controllers/blobs_controller.rb	2012-08-24 14:52:14 UTC (rev 3108)
+++ branches/events/app/controllers/blobs_controller.rb	2012-08-24 22:58:01 UTC (rev 3109)
@@ -152,7 +152,7 @@
 
       respond_to do |format|
         if @blob.save
-          Event.create(:subject => current_user, :action ="" 'create', :objekt => @blob)
+          Event.create(:subject => current_user, :action ="" 'create', :objekt => @blob, :auth => @blob)
           if params[:blob][:tag_list]
             @blob.tags_user_id = current_user
             @blob.tag_list = convert_tags_to_gem_format params[:blob][:tag_list]
@@ -221,9 +221,9 @@
       if @blob.update_attributes(params[:blob])
 
         if @blob.new_version_number
-          Event.create(:subject => current_user, :action ="" 'create version', :objekt => @blob)
+          Event.create(:subject => current_user, :action ="" 'create', :objekt => @blob.find_version(@blob.new_version_number), :extra => @blob.new_version_number, :auth => @blob)
         else
-          Event.create(:subject => current_user, :action ="" 'edit', :objekt => @blob)
+          Event.create(:subject => current_user, :action ="" 'edit', :objekt => @blob, :auth => @blob)
         end
 
         @blob.refresh_tags(convert_tags_to_gem_format(params[:blob][:tag_list]), current_user) if params[:blob][:tag_list]
@@ -320,7 +320,7 @@
     success = bookmark.save
 
     if success
-      Event.create(:subject => current_user, :action ="" 'create', :objekt => bookmark)
+      Event.create(:subject => current_user, :action ="" 'create', :objekt => bookmark, :auth => @blob)
     end
     
     respond_to do |format|

Modified: branches/events/app/controllers/comments_controller.rb (3108 => 3109)


--- branches/events/app/controllers/comments_controller.rb	2012-08-24 14:52:14 UTC (rev 3108)
+++ branches/events/app/controllers/comments_controller.rb	2012-08-24 22:58:01 UTC (rev 3109)
@@ -38,7 +38,7 @@
       success = comment.save
 
       if success
-        Event.create(:subject => current_user, :action ="" 'create', :objekt => comment)
+        Event.create(:subject => current_user, :action ="" 'create', :objekt => comment, :auth => @context)
         @context.solr_save if @context.respond_to?(:solr_save)
       end
     end

Modified: branches/events/app/controllers/packs_controller.rb (3108 => 3109)


--- branches/events/app/controllers/packs_controller.rb	2012-08-24 14:52:14 UTC (rev 3108)
+++ branches/events/app/controllers/packs_controller.rb	2012-08-24 22:58:01 UTC (rev 3109)
@@ -198,7 +198,7 @@
     success = bookmark.save
 
     if success
-      Event.create(:subject => current_user, :action ="" 'create', :objekt => bookmark)
+      Event.create(:subject => current_user, :action ="" 'create', :objekt => bookmark, :auth => @pack)
     end
     
     respond_to do |format|

Modified: branches/events/app/controllers/workflows_controller.rb (3108 => 3109)


--- branches/events/app/controllers/workflows_controller.rb	2012-08-24 14:52:14 UTC (rev 3108)
+++ branches/events/app/controllers/workflows_controller.rb	2012-08-24 22:58:01 UTC (rev 3109)
@@ -48,7 +48,7 @@
     success = bookmark.save
 
     if success
-      Event.create(:subject => current_user, :action ="" 'create', :objekt => bookmark)
+      Event.create(:subject => current_user, :action ="" 'create', :objekt => bookmark, :auth => @workflow)
     end
     
     respond_to do |format|
@@ -351,7 +351,7 @@
     respond_to do |format|
       if @workflow.save
 
-        Event.create(:subject => current_user, :action ="" 'create', :objekt => @workflow)
+        Event.create(:subject => current_user, :action ="" 'create', :objekt => @workflow, :auth => @workflow)
 
         if params[:workflow][:tag_list]
           @workflow.refresh_tags(convert_tags_to_gem_format(params[:workflow][:tag_list]), current_user)
@@ -476,13 +476,14 @@
         # Extract workflow metadata using a Workflow object that includes the
         # newly created version.
 
+        @workflow.reload
+
         begin
-          @workflow.reload
           @workflow.extract_metadata
         rescue
         end
 
-        Event.create(:subject => current_user, :action ="" 'create version', :objekt => @workflow)
+        Event.create(:subject => current_user, :action ="" 'create', :objekt => @workflow.versions.last, :extra => @workflow.versions.last.version, :auth => @workflow)
 
         respond_to do |format|
           flash[:notice] = 'New workflow version successfully created.'
@@ -540,7 +541,7 @@
       
       if @workflow.update_attributes(params[:workflow])
 
-        Event.create(:subject => current_user, :action ="" 'edit', :objekt => @workflow)
+        Event.create(:subject => current_user, :action ="" 'edit', :objekt => @workflow, :auth => @workflow)
 
         if params[:workflow][:tag_list]
           @workflow.refresh_tags(convert_tags_to_gem_format(params[:workflow][:tag_list]), current_user)
@@ -595,7 +596,7 @@
 
     respond_to do |format|
       if success
-        Event.create(:subject => current_user, :action ="" 'edit version', :extra => version.version, :objekt => @workflow)
+        Event.create(:subject => current_user, :action ="" 'edit', :objekt => version, :extra => version.version, :auth => @workflow)
         flash[:notice] = "Workflow version #{version.version}: \"#{original_title}\" has been updated."
         format.html { redirect_to(workflow_url(@workflow) + "?version=#{params[:version]}") }
       else

Modified: branches/events/app/helpers/application_helper.rb (3108 => 3109)


--- branches/events/app/helpers/application_helper.rb	2012-08-24 14:52:14 UTC (rev 3108)
+++ branches/events/app/helpers/application_helper.rb	2012-08-24 22:58:01 UTC (rev 3109)
@@ -549,6 +549,8 @@
 
     def link_aux(thing, label)
 
+      thing = thing.versioned_resource if thing.respond_to?(:versioned_resource)
+
       case thing.class.name
         when "Bookmark"
           thing = thing.bookmarkable
@@ -557,7 +559,7 @@
       end
 
       if thing
-        link_to(thing.label, polymorphic_path(thing))
+        link_to(label, polymorphic_path(thing))
       else
         h(label)
       end
@@ -586,13 +588,28 @@
       conditions_operands << opts[:object].id
     end
 
+    if opts[:auth]
+      conditions_expr     << "auth_type = ? AND auth_id = ?"
+      conditions_operands << opts[:auth].class.name
+      conditions_operands << opts[:auth].id
+    end
+
     unless conditions_expr.empty?
       conditions_expr = conditions_expr.map do |cond| "(#{cond})" end.join(' AND ')
       conditions = [conditions_expr] + conditions_operands
     end
 
-    events = Event.find(:all, :order => 'created_at ASC', :conditions => conditions, :order => 'created_at DESC', :limit => 15)
+    visible_events = Authorization.scoped(Event,
+        :auth_type       => 'events.auth_type',
+        :auth_id         => 'events.auth_id',
+        :group           => 'events.id',
+        :authorised_user => current_user)
 
+    events = visible_events.find(:all,
+        :conditions => conditions,
+        :order      => 'created_at DESC',
+        :limit      => 15)
+
     markup = '<ol class="activity-feed">'
 
     markup << events.map do |event|
@@ -604,19 +621,20 @@
       end
 
       sentence = case action
-        when "Blob create version":     "#{subject_link(event)} uploaded a new version of #{objekt_link(event)}"
-        when "Blob create":             "#{subject_link(event)} uploaded #{objekt_link(event)}"
-        when "Blob edit version":       "#{subject_link(event)} edited version #{event.extra} of #{objekt_link(event)}"
-        when "Blob edit":               "#{subject_link(event)} edited #{objekt_link(event)}"
-        when "Blog create":             "#{subject_link(event)} created #{objekt_link(event)}"
-        when "Bookmark create":         "#{subject_link(event)} favourited #{objekt_link(event)}"
-        when "Comment create":          "#{subject_link(event)} commented on #{objekt_link(event)}"
-        when "Pack create":             "#{subject_link(event)} created #{objekt_link(event)}"
-        when "Workflow create version": "#{subject_link(event)} uploaded a new version of #{objekt_link(event)}"
-        when "Workflow create":         "#{subject_link(event)} uploaded #{objekt_link(event)}"
-        when "Workflow edit version":   "#{subject_link(event)} edited version #{event.extra} of #{objekt_link(event)}"
-        when "Workflow edit":           "#{subject_link(event)} edited #{objekt_link(event)}"
-        when "register":                "#{subject_link(event)} joined #{Conf.sitename}"
+        when "Announcement create":    "#{subject_link(event)} announced #{objekt_link(event)}"
+        when "Announcement edit":      "#{subject_link(event)} edited #{objekt_link(event)}"
+        when "Blob create":            "#{subject_link(event)} uploaded #{objekt_link(event)}"
+        when "Blob edit":              "#{subject_link(event)} edited #{objekt_link(event)}"
+        when "BlobVersion create":     "#{subject_link(event)} uploaded a new version of #{objekt_link(event)}"
+        when "BlobVersion edit":       "#{subject_link(event)} edited version #{event.extra} of #{objekt_link(event)}"
+        when "Bookmark create":        "#{subject_link(event)} favourited #{objekt_link(event)}"
+        when "Comment create":         "#{subject_link(event)} commented on #{objekt_link(event)}"
+        when "Pack create":            "#{subject_link(event)} created #{objekt_link(event)}"
+        when "Workflow create":        "#{subject_link(event)} uploaded #{objekt_link(event)}"
+        when "Workflow edit":          "#{subject_link(event)} edited #{objekt_link(event)}"
+        when "WorkflowVersion create": "#{subject_link(event)} uploaded a new version of #{objekt_link(event)}"
+        when "WorkflowVersion edit":   "#{subject_link(event)} edited version #{event.extra} of #{objekt_link(event)}"
+        when "register":               "#{subject_link(event)} joined #{Conf.sitename}"
         else "Unknown event"
       end
 

Modified: branches/events/app/models/event.rb (3108 => 3109)


--- branches/events/app/models/event.rb	2012-08-24 14:52:14 UTC (rev 3108)
+++ branches/events/app/models/event.rb	2012-08-24 22:58:01 UTC (rev 3109)
@@ -7,6 +7,7 @@
 
   belongs_to :subject, :polymorphic => true
   belongs_to :objekt,  :polymorphic => true
+  belongs_to :auth,    :polymorphic => true
 
   validates_presence_of :subject
   validates_presence_of :action
@@ -25,6 +26,12 @@
       e.objekt_label = e.objekt.title if e.objekt.respond_to?(:title)
       e.objekt_label = e.objekt.name  if e.objekt.respond_to?(:name)
     end
+
+    if e.objekt && (e.objekt_label.nil? || e.objekt_label == "") && e.auth
+      e.objekt_label = e.auth.label if e.auth.respond_to?(:label)
+      e.objekt_label = e.auth.title if e.auth.respond_to?(:title)
+      e.objekt_label = e.auth.name  if e.auth.respond_to?(:name)
+    end
   end
 end
 

Modified: branches/events/app/views/workflows/show.rhtml (3108 => 3109)


--- branches/events/app/views/workflows/show.rhtml	2012-08-24 14:52:14 UTC (rev 3108)
+++ branches/events/app/views/workflows/show.rhtml	2012-08-24 22:58:01 UTC (rev 3109)
@@ -190,7 +190,7 @@
   <div class="tabTitle">Activity</div>
   <div class="tabContent">
     <a name="activity"></a>
-    <%= activity_feed(:object => @workflow) -%>
+    <%= activity_feed(:auth => @workflow) -%>
   </div>
 </div>
 

Modified: branches/events/db/migrate/097_add_events.rb (3108 => 3109)


--- branches/events/db/migrate/097_add_events.rb	2012-08-24 14:52:14 UTC (rev 3108)
+++ branches/events/db/migrate/097_add_events.rb	2012-08-24 22:58:01 UTC (rev 3109)
@@ -17,6 +17,9 @@
       t.integer :objekt_id
       t.string  :objekt_label
 
+      t.string  :auth_type
+      t.integer :auth_id
+
       t.string  :extra
 
       t.datetime :created_at

Modified: branches/events/db/schema.rb (3108 => 3109)


--- branches/events/db/schema.rb	2012-08-24 14:52:14 UTC (rev 3108)
+++ branches/events/db/schema.rb	2012-08-24 22:58:01 UTC (rev 3109)
@@ -235,6 +235,8 @@
     t.string   "objekt_type"
     t.integer  "objekt_id"
     t.string   "objekt_label"
+    t.string   "auth_type"
+    t.integer  "auth_id"
     t.string   "extra"
     t.datetime "created_at"
   end

Modified: branches/events/test/functional/api_controller_test.rb (3108 => 3109)


--- branches/events/test/functional/api_controller_test.rb	2012-08-24 14:52:14 UTC (rev 3108)
+++ branches/events/test/functional/api_controller_test.rb	2012-08-24 22:58:01 UTC (rev 3109)
@@ -136,7 +136,7 @@
     new_event = (extra_events - existing_events).first
 
     assert_equal("John Smith", new_event.subject_label);
-    assert_equal("create version", new_event.action);
+    assert_equal("create", new_event.action);
     assert_equal("Fetch today's xkcd comic", new_event.objekt_label);
 
     workflow = Workflow.find(@workflow_id)
@@ -180,9 +180,9 @@
     new_event = (extra_events - existing_events).first
 
     assert_equal("John Smith", new_event.subject_label);
-    assert_equal("edit version", new_event.action);
-    assert_equal("1", new_event.extra);
-    assert_equal("Oranges", new_event.objekt_label);
+    assert_equal("edit",       new_event.action);
+    assert_equal("1",          new_event.extra);
+    assert_equal("Oranges",    new_event.objekt_label);
 
     # Verify that only version 1 was changed
 
@@ -332,7 +332,7 @@
 
     assert_equal(1, new_events.length)
     assert_equal("John Smith",     new_events.first.subject.name)
-    assert_equal("create version", new_events.first.action)
+    assert_equal("create",         new_events.first.action)
     assert_equal(title2,           new_events.first.objekt.title)
 
     file.reload
@@ -354,7 +354,7 @@
 
     assert_equal(1, new_events.length)
     assert_equal("John Smith",   new_events.first.subject.name)
-    assert_equal("edit version", new_events.first.action)
+    assert_equal("edit",         new_events.first.action)
     assert_equal(title3,         new_events.first.objekt.title)
 
     file.reload
@@ -658,8 +658,8 @@
     new_events = Event.all - existing_events
 
     assert_equal(1, new_events.length)
-    assert_equal("John Smith", new_events.first.subject.name)
-    assert_equal("create", new_events.first.action)
+    assert_equal("John Smith",  new_events.first.subject.name)
+    assert_equal("create",      new_events.first.action)
     assert_equal("Unique tags", new_events.first.objekt.commentable.title)
 
     extra_comments = Comment.find(:all) - existing_comments 
@@ -810,8 +810,8 @@
     new_events = Event.all - existing_events
 
     assert_equal(1, new_events.length)
-    assert_equal("John Smith", new_events.first.subject.name)
-    assert_equal("create", new_events.first.action)
+    assert_equal("John Smith",  new_events.first.subject.name)
+    assert_equal("create",      new_events.first.action)
     assert_equal("Unique tags", new_events.first.objekt.bookmarkable.title)
 
     extra_favourites = Bookmark.find(:all) - existing_favourites 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]