Diff
Modified: trunk/Rakefile (3510 => 3511)
--- trunk/Rakefile 2013-04-12 13:40:19 UTC (rev 3510)
+++ trunk/Rakefile 2013-04-12 13:45:28 UTC (rev 3511)
@@ -192,6 +192,244 @@
puts doc.to_s
end
+desc 'Create initial activities'
+task "myexp:activities:create" do
+ require File.dirname(__FILE__) + '/config/environment'
+
+ activities = []
+
+ User.find(:all, :conditions => "activated_at IS NOT NULL", :include => :profile).map do |object|
+
+ activities << Activity.new(
+ :subject => object,
+ :subject_label => object.name,
+ :action ="" 'register',
+ :created_at => object.created_at)
+
+ if object.profile.updated_at && object.profile.updated_at != object.profile.created_at
+
+
+ activities << Activity.new(
+ :subject => object,
+ :subject_label => object.name,
+ :action ="" 'edit',
+ :created_at => object.profile.updated_at)
+
+ end
+ end
+
+ (Workflow.all + Blob.all + Pack.all).map do |object|
+
+ activities << Activity.new(
+ :subject => object.contributor,
+ :action ="" 'create',
+ :objekt => object,
+ :auth => object,
+ :created_at => object.created_at)
+
+ if object.updated_at && object.updated_at != object.created_at
+
+ activities << Activity.new(
+ :subject => object.contributor,
+ :action ="" 'edit',
+ :objekt => object,
+ :auth => object,
+ :created_at => object.updated_at)
+ end
+ end
+
+ workflow_versions = (WorkflowVersion.find(:all, :conditions => "version > 1")).select do |object|
+ !(object.version == 2 && object.content_blob.data == object.workflow.versions.first.content_blob.data)
+ end
+
+ workflow_versions.map do |object|
+
+ activities << Activity.new(
+ :subject => object.contributor,
+ :action ="" 'create',
+ :objekt => object,
+ :extra => object.version,
+ :auth => object.versioned_resource,
+ :created_at => object.created_at)
+
+ if object.updated_at && object.updated_at != object.created_at
+
+ activities << Activity.new(
+ :subject => object.contributor,
+ :action ="" 'edit',
+ :objekt => object,
+ :extra => object.version,
+ :auth => object.versioned_resource,
+ :created_at => object.updated_at)
+ end
+ end
+
+ (BlobVersion.find(:all, :conditions => "version > 1")).map do |object|
+
+ activities << Activity.new(
+ :subject => object.blob.contributor,
+ :action ="" 'create',
+ :objekt => object,
+ :extra => object.version,
+ :auth => object.versioned_resource,
+ :created_at => object.created_at)
+
+ if object.updated_at && object.updated_at != object.created_at
+
+ activities << Activity.new(
+ :subject => object.blob.contributor,
+ :action ="" 'edit',
+ :objekt => object,
+ :extra => object.version,
+ :auth => object.versioned_resource,
+ :created_at => object.updated_at)
+ end
+ end
+
+ activities += Comment.all.map do |comment|
+
+ Activity.new(
+ :subject => comment.user,
+ :action ="" 'create',
+ :objekt => comment,
+ :auth => comment.commentable,
+ :created_at => comment.created_at)
+ end
+
+ activities += Bookmark.all.map do |bookmark|
+
+ Activity.new(
+ :subject => bookmark.user,
+ :action ="" 'create',
+ :objekt => bookmark,
+ :auth => bookmark.bookmarkable,
+ :created_at => bookmark.created_at)
+ end
+
+ Announcement.all.each do |object|
+
+ activities << Activity.new(
+ :subject => object.user,
+ :action ="" 'create',
+ :objekt => object,
+ :created_at => object.created_at)
+
+ if object.updated_at && object.updated_at != object.created_at
+
+
+ activities << Activity.new(
+ :subject => object.user,
+ :action ="" 'edit',
+ :objekt => object,
+ :created_at => object.updated_at)
+ end
+ end
+
+ Citation.all.each do |object|
+
+ activities << Activity.new(
+ :subject => object.user,
+ :action ="" 'create',
+ :objekt => object,
+ :auth => object.workflow,
+ :created_at => object.created_at)
+
+ if object.updated_at && object.updated_at != object.created_at
+
+ activities << Activity.new(
+ :subject => object.user,
+ :action ="" 'edit',
+ :objekt => object,
+ :auth => object.workflow,
+ :created_at => object.updated_at)
+ end
+ end
+
+ Rating.all.each do |object|
+
+ activities << Activity.new(
+ :subject => object.user,
+ :action ="" 'create',
+ :objekt => object,
+ :auth => object.rateable,
+ :extra => object.rating,
+ :created_at => object.created_at)
+ end
+
+ Review.all.each do |object|
+
+ activities << Activity.new(
+ :subject => object.user,
+ :action ="" 'create',
+ :objekt => object,
+ :auth => object.reviewable,
+ :created_at => object.created_at)
+
+ if object.updated_at && object.updated_at != object.created_at
+
+ activities << Activity.new(
+ :subject => object.user,
+ :action ="" 'edit',
+ :objekt => object,
+ :auth => object.reviewable,
+ :created_at => object.updated_at)
+ end
+ end
+
+ Tagging.all.each do |object|
+
+ activities << Activity.new(
+ :subject => object.user,
+ :action ="" 'create',
+ :objekt => object,
+ :auth => object.taggable,
+ :extra => object.tag.name,
+ :created_at => object.created_at)
+ end
+
+ Network.all.each do |object|
+
+ activities << Activity.new(
+ :subject => object.owner,
+ :action ="" 'create',
+ :objekt => object,
+ :created_at => object.created_at)
+
+ if object.updated_at && object.updated_at != object.created_at
+
+ activities << Activity.new(
+ :subject => object.owner,
+ :action ="" 'edit',
+ :objekt => object,
+ :created_at => object.updated_at)
+ end
+ end
+
+ Membership.all.each do |membership|
+
+ next unless membership.accepted?
+
+ activities << Activity.new(
+ :subject => membership.user,
+ :action ="" 'join',
+ :objekt => membership.network,
+ :created_at => membership.accepted_at)
+ end
+
+ activities.sort! do |a, b|
+ if a.created_at && b.created_at
+ a.created_at <=> b.created_at
+ else
+ a.object_id <=> b.object_id
+ end
+ end
+
+ activities.each do |activity|
+ activity.save
+ end
+
+end
+
desc 'Perform spam analysis on user profiles'
task "myexp:spam:run" do
require File.dirname(__FILE__) + '/config/environment'
Modified: trunk/app/controllers/announcements_controller.rb (3510 => 3511)
--- trunk/app/controllers/announcements_controller.rb 2013-04-12 13:40:19 UTC (rev 3510)
+++ trunk/app/controllers/announcements_controller.rb 2013-04-12 13:45:28 UTC (rev 3511)
@@ -50,6 +50,7 @@
params[:announcement][:user_id] = current_user.id
@announcement = Announcement.new(params[:announcement])
if @announcement.save
+ Activity.create(:subject => current_user, :action ="" 'create', :objekt => @announcement)
flash[:notice] = 'Announcement was successfully created.'
redirect_to :action ="" 'index'
else
@@ -64,6 +65,7 @@
def update
@announcement = Announcement.find(params[:id])
if @announcement.update_attributes(params[:announcement])
+ Activity.create(:subject => current_user, :action ="" 'edit', :objekt => @announcement)
flash[:notice] = 'Announcement was successfully updated.'
redirect_to :action ="" 'show', :id => @announcement
else
Modified: trunk/app/controllers/blobs_controller.rb (3510 => 3511)
--- trunk/app/controllers/blobs_controller.rb 2013-04-12 13:40:19 UTC (rev 3510)
+++ trunk/app/controllers/blobs_controller.rb 2013-04-12 13:45:28 UTC (rev 3511)
@@ -168,6 +168,7 @@
respond_to do |format|
if @blob.save
+ Activity.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]
@@ -236,6 +237,13 @@
respond_to do |format|
if @blob.update_attributes(params[:blob])
+
+ if @blob.new_version_number
+ Activity.create(:subject => current_user, :action ="" 'create', :objekt => @blob.find_version(@blob.new_version_number), :extra => @blob.new_version_number, :auth => @blob)
+ else
+ Activity.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]
policy_err_msg = update_policy(@blob, params)
@@ -289,7 +297,9 @@
def rate
unless @blob.contributor_type == 'User' and @blob.contributor_id == current_user.id
Rating.delete_all(["rateable_type = ? AND rateable_id = ? AND user_id = ?", @blob.class.to_s, @blob.id, current_user.id])
- Rating.create(:rateable => @blob, :user => current_user, :rating => params[:rating])
+
+ rating = Rating.create(:rateable => @blob, :user => current_user, :rating => params[:rating])
+ Activity.create(:subject => current_user, :action ="" 'create', :objekt => rating, :auth => @blob, :extra => params[:rating].to_i)
respond_to do |format|
format.html do
@@ -323,7 +333,14 @@
# POST /files/1;favourite
def favourite
- @blob.bookmarks << Bookmark.create(:user => current_user, :bookmarkable => @blob) unless @blob.bookmarked_by_user?(current_user)
+
+ bookmark = Bookmark.new(:user => current_user, :bookmarkable => @blob)
+
+ success = bookmark.save unless @blob.bookmarked_by_user?(current_user)
+
+ if success
+ Activity.create(:subject => current_user, :action ="" 'create', :objekt => bookmark, :auth => @blob)
+ end
respond_to do |format|
flash[:notice] = "You have successfully added this item to your favourites."
Modified: trunk/app/controllers/citations_controller.rb (3510 => 3511)
--- trunk/app/controllers/citations_controller.rb 2013-04-12 13:40:19 UTC (rev 3510)
+++ trunk/app/controllers/citations_controller.rb 2013-04-12 13:45:28 UTC (rev 3511)
@@ -49,6 +49,8 @@
respond_to do |format|
if @citation.save
+
+ Activity.create(:subject => current_user, :action ="" 'create', :objekt => @citation, :auth => @workflow)
flash[:notice] = 'Citation was successfully created.'
format.html { redirect_to workflow_citation_url(@workflow, @citation) }
else
@@ -61,6 +63,7 @@
def update
respond_to do |format|
if @citation.update_attributes(params[:citation])
+ Activity.create(:subject => current_user, :action ="" 'edit', :objekt => @citation, :auth => @workflow)
flash[:notice] = 'Citation was successfully updated.'
format.html { redirect_to workflow_citation_url(@workflow, @citation) }
else
Modified: trunk/app/controllers/comments_controller.rb (3510 => 3511)
--- trunk/app/controllers/comments_controller.rb 2013-04-12 13:40:19 UTC (rev 3510)
+++ trunk/app/controllers/comments_controller.rb 2013-04-12 13:45:28 UTC (rev 3511)
@@ -33,9 +33,14 @@
end
if text and text.length > 0
- comment = Comment.create(:user => current_user, :comment => text)
- @context.comments << comment
- @context.solr_index if @context.respond_to?(:solr_index)
+ comment = Comment.new(:user => current_user, :comment => text, :commentable => @context)
+
+ success = comment.save
+
+ if success
+ Activity.create(:subject => current_user, :action ="" 'create', :objekt => comment, :auth => @context)
+ @context.solr_index if @context.respond_to?(:solr_index)
+ end
end
respond_to do |format|
Modified: trunk/app/controllers/friendships_controller.rb (3510 => 3511)
--- trunk/app/controllers/friendships_controller.rb 2013-04-12 13:40:19 UTC (rev 3510)
+++ trunk/app/controllers/friendships_controller.rb 2013-04-12 13:45:28 UTC (rev 3511)
@@ -40,6 +40,7 @@
respond_to do |format|
if @friendship.accept!
+ Activity.create(:subject => User.find(from_id), :action ="" 'create', :objekt => @friendship)
flash[:notice] = 'Friendship was successfully accepted.'
else
flash[:error] = "Friendship already accepted."
Modified: trunk/app/controllers/networks_controller.rb (3510 => 3511)
--- trunk/app/controllers/networks_controller.rb 2013-04-12 13:40:19 UTC (rev 3510)
+++ trunk/app/controllers/networks_controller.rb 2013-04-12 13:45:28 UTC (rev 3511)
@@ -322,6 +322,7 @@
respond_to do |format|
if @network.save
+ Activity.create(:subject => current_user, :action ="" 'create', :objekt => @network)
if params[:network][:tag_list]
@network.tags_user_id = current_user
@network.tag_list = convert_tags_to_gem_format params[:network][:tag_list]
@@ -342,6 +343,7 @@
respond_to do |format|
if @network.update_attributes(params[:network])
+ Activity.create(:subject => current_user, :action ="" 'edit', :objekt => @network)
@network.refresh_tags(convert_tags_to_gem_format(params[:network][:tag_list]), current_user) if params[:network][:tag_list]
flash[:notice] = 'Group was successfully updated.'
format.html { redirect_to network_url(@network) }
Modified: trunk/app/controllers/packs_controller.rb (3510 => 3511)
--- trunk/app/controllers/packs_controller.rb 2013-04-12 13:40:19 UTC (rev 3510)
+++ trunk/app/controllers/packs_controller.rb 2013-04-12 13:45:28 UTC (rev 3511)
@@ -203,7 +203,14 @@
# POST /packs/1;favourite
def favourite
- @pack.bookmarks << Bookmark.create(:user => current_user, :bookmarkable => @pack) unless @pack.bookmarked_by_user?(current_user)
+
+ bookmark = Bookmark.new(:user => current_user, :bookmarkable => @pack)
+
+ success = bookmark.save unless @pack.bookmarked_by_user?(current_user)
+
+ if success
+ Activity.create(:subject => current_user, :action ="" 'create', :objekt => bookmark, :auth => @pack)
+ end
respond_to do |format|
flash[:notice] = "You have successfully added this item to your favourites."
Modified: trunk/app/controllers/reviews_controller.rb (3510 => 3511)
--- trunk/app/controllers/reviews_controller.rb 2013-04-12 13:40:19 UTC (rev 3510)
+++ trunk/app/controllers/reviews_controller.rb 2013-04-12 13:45:28 UTC (rev 3511)
@@ -63,6 +63,7 @@
respond_to do |format|
if @review.save
+ Activity.create(:subject => current_user, :action ="" 'create', :objekt => @review, :auth => @reviewable, :extra => params[:rating].to_i)
update_rating(@review, params[:rating])
flash[:notice] = 'Thank you for your review!'
format.html { redirect_to workflow_review_url(@reviewable, @review) }
@@ -81,6 +82,7 @@
def update
respond_to do |format|
if @review.update_attributes(params[:review])
+ Activity.create(:subject => current_user, :action ="" 'edit', :objekt => @review, :auth => @reviewable, :extra => params[:rating].to_i)
update_rating(@review, params[:rating])
flash[:notice] = 'Review was successfully updated.'
format.html { redirect_to workflow_review_url(@reviewable, @review) }
Modified: trunk/app/controllers/users_controller.rb (3510 => 3511)
--- trunk/app/controllers/users_controller.rb 2013-04-12 13:40:19 UTC (rev 3510)
+++ trunk/app/controllers/users_controller.rb 2013-04-12 13:45:28 UTC (rev 3511)
@@ -314,6 +314,7 @@
user.errors.full_messages.each { |e| logger.error(e) }
#END DEBUG
if confirmed
+ Activity.create(:subject => user, :action ="" 'register')
self.current_user = user
self.current_user.process_pending_invitations! # look up any pending invites for this user + transfer them to relevant tables from 'pending_invitations' table
confirmed = false if !logged_in?
Modified: trunk/app/controllers/workflows_controller.rb (3510 => 3511)
--- trunk/app/controllers/workflows_controller.rb 2013-04-12 13:40:19 UTC (rev 3510)
+++ trunk/app/controllers/workflows_controller.rb 2013-04-12 13:45:28 UTC (rev 3511)
@@ -44,7 +44,14 @@
# POST /workflows/1;favourite
def favourite
- Bookmark.create(:user => current_user, :bookmarkable => @workflow) unless @workflow.bookmarked_by_user?(current_user)
+
+ bookmark = Bookmark.new(:user => current_user, :bookmarkable => @workflow)
+
+ success = bookmark.save unless @workflow.bookmarked_by_user?(current_user)
+
+ if success
+ Activity.create(:subject => current_user, :action ="" 'create', :objekt => bookmark, :auth => @workflow)
+ end
respond_to do |format|
flash[:notice] = "You have successfully added this item to your favourites."
@@ -74,7 +81,8 @@
else
Rating.delete_all(["rateable_type = ? AND rateable_id = ? AND user_id = ?", @workflow.class.to_s, @workflow.id, current_user.id])
- Rating.create(:rateable => @workflow, :user => current_user, :rating => params[:rating])
+ rating = Rating.create(:rateable => @workflow, :user => current_user, :rating => params[:rating])
+ Activity.create(:subject => current_user, :action ="" 'create', :objekt => rating, :auth => @workflow, :extra => params[:rating].to_i)
respond_to do |format|
format.html {
@@ -348,6 +356,9 @@
respond_to do |format|
if @workflow.save
+
+ Activity.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)
@workflow.reload
@@ -477,6 +488,8 @@
raise unless Rails.env == 'production'
end
+ Activity.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.'
format.html {
@@ -533,6 +546,8 @@
if @workflow.update_attributes(params[:workflow])
+ Activity.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)
@workflow.reload
@@ -596,6 +611,7 @@
respond_to do |format|
if success
+ Activity.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
Copied: trunk/app/models/activity.rb (from rev 3506, branches/events/app/models/activity.rb) (0 => 3511)
--- trunk/app/models/activity.rb (rev 0)
+++ trunk/app/models/activity.rb 2013-04-12 13:45:28 UTC (rev 3511)
@@ -0,0 +1,37 @@
+# myExperiment: app/models/activity.rb
+#
+# Copyright (c) 2012 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class Activity < ActiveRecord::Base
+
+ belongs_to :subject, :polymorphic => true
+ belongs_to :objekt, :polymorphic => true
+ belongs_to :auth, :polymorphic => true
+
+ validates_presence_of :subject
+ validates_presence_of :action
+ validates_presence_of :subject_label
+
+ before_validation do |e|
+
+ if e.subject && e.subject_label.nil?
+ e.subject_label = e.subject.label if e.subject.respond_to?(:label)
+ e.subject_label = e.subject.title if e.subject.respond_to?(:title)
+ e.subject_label = e.subject.name if e.subject.respond_to?(:name)
+ end
+
+ if e.objekt && e.objekt_label.nil?
+ e.objekt_label = e.objekt.label if e.objekt.respond_to?(:label)
+ 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: trunk/app/models/workflow_version.rb (3510 => 3511)
--- trunk/app/models/workflow_version.rb 2013-04-12 13:40:19 UTC (rev 3510)
+++ trunk/app/models/workflow_version.rb 2013-04-12 13:45:28 UTC (rev 3511)
@@ -14,6 +14,8 @@
belongs_to :content_blob, :dependent => :destroy
belongs_to :content_type
+ belongs_to :contributor, :polymorphic => true
+
validates_presence_of :content_blob
validates_presence_of :content_type
Copied: trunk/db/migrate/099_add_activities.rb (from rev 3506, branches/events/db/migrate/099_add_activities.rb) (0 => 3511)
--- trunk/db/migrate/099_add_activities.rb (rev 0)
+++ trunk/db/migrate/099_add_activities.rb 2013-04-12 13:45:28 UTC (rev 3511)
@@ -0,0 +1,32 @@
+# myExperiment: db/migrate/097_add_activities.rb
+#
+# Copyright (c) 2012 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class AddActivities < ActiveRecord::Migration
+ def self.up
+ create_table :activities do |t|
+
+ t.string :subject_type
+ t.integer :subject_id
+ t.string :subject_label
+
+ t.string :action
+
+ 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
+ end
+
+ def self.down
+ drop_table :activities
+ end
+end
Modified: trunk/db/schema.rb (3510 => 3511)
--- trunk/db/schema.rb 2013-04-12 13:40:19 UTC (rev 3510)
+++ trunk/db/schema.rb 2013-04-12 13:45:28 UTC (rev 3511)
@@ -11,6 +11,20 @@
ActiveRecord::Schema.define(:version => 20130308085716) do
+ create_table "activities", :force => true do |t|
+ t.string "subject_type"
+ t.integer "subject_id"
+ t.string "subject_label"
+ t.string "action"
+ 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
+
create_table "activity_limits", :force => true do |t|
t.string "contributor_type", :null => false
t.integer "contributor_id", :null => false
@@ -84,6 +98,27 @@
add_index "bookmarks", ["user_id"], :name => "index_bookmarks_on_user_id"
+ create_table "checksums", :id => false, :force => true do |t|
+ t.integer "id"
+ t.string "sha1"
+ end
+
+ add_index "checksums", ["id"], :name => "i1", :unique => true
+
+ create_table "checksums_new", :id => false, :force => true do |t|
+ t.integer "id"
+ t.string "sha1"
+ end
+
+ add_index "checksums_new", ["id"], :name => "i1", :unique => true
+
+ create_table "checksums_new_new", :id => false, :force => true do |t|
+ t.integer "id"
+ t.string "sha1"
+ end
+
+ add_index "checksums_new_new", ["id"], :name => "ii", :unique => true
+
create_table "citations", :force => true do |t|
t.integer "user_id"
t.integer "workflow_id"
@@ -828,6 +863,8 @@
t.integer "preview_id"
end
+ add_index "workflow_versions", ["workflow_id"], :name => "index_workflow_versions_on_workflow_id"
+
create_table "workflows", :force => true do |t|
t.integer "contributor_id"
t.string "contributor_type"
Modified: trunk/lib/rest.rb (3510 => 3511)
--- trunk/lib/rest.rb 2013-04-12 13:40:19 UTC (rev 3510)
+++ trunk/lib/rest.rb 2013-04-12 13:45:28 UTC (rev 3511)
@@ -1185,6 +1185,15 @@
success = ob.save
+ if success
+ case "#{action} #{new_version || edit_version}"
+ when "create false"; Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob, :auth => ob)
+ when "create true"; Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob.versions.last, :auth => ob)
+ when "edit false"; Activity.create(:subject => opts[:user], :action ="" 'edit', :objekt => ob, :auth => ob)
+ when "edit true"; Activity.create(:subject => opts[:user], :action ="" 'edit', :objekt => ob, :extra => ob.version, :auth => ob.workflow)
+ end
+ end
+
return rest_response(400, :object => ob) unless success
# Elements to update if we're not dealing with a workflow version
@@ -1320,7 +1329,8 @@
ob.content_blob = ContentBlob.new(:data ="" content) if content
- new_version = action == 'create' && opts[:query][:id]
+ new_version = action == 'create' && opts[:query]['id'] != nil
+ edit_version = action == 'edit' && opts[:query]['version'] != nil
if new_version
ob[:revision_comments] = revision_comment
@@ -1328,6 +1338,15 @@
success = ob.save
+ if success
+ case "#{action} #{new_version || edit_version}"
+ when "create false"; Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob, :auth => ob)
+ when "create true"; Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob.versions.last, :auth => ob)
+ when "edit false"; Activity.create(:subject => opts[:user], :action ="" 'edit', :objekt => ob, :auth => ob)
+ when "edit true"; Activity.create(:subject => opts[:user], :action ="" 'edit', :objekt => ob, :extra => ob.version, :auth => ob.blob)
+ end
+ end
+
return rest_response(400, :object => ob) unless success
if opts[:query]['version'].nil?
@@ -2078,7 +2097,16 @@
# End of curation hack
- return rest_response(400, :object => ob) unless ob.save
+ success = ob.save
+
+ if success
+ case action
+ when "create"; Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob)
+ when "edit"; Activity.create(:subject => opts[:user], :action ="" 'edit', :objekt => ob)
+ end
+ end
+
+ return rest_response(400, :object => ob) unless success
end
rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
@@ -2134,7 +2162,13 @@
ob.bookmarkable = target
end
- return rest_response(400, :object => ob) unless ob.save
+ success = ob.save
+
+ if success
+ Activity.create(:subject => current_user, :action ="" 'create', :objekt => ob)
+ end
+
+ return rest_response(400, :object => ob) unless success
end
rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
@@ -2193,7 +2227,13 @@
ob.rateable = subject
end
- return rest_response(400, :object => ob) unless ob.save
+ success = ob.save
+
+ if success
+ Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob, :auth => subject)
+ end
+
+ return rest_response(400, :object => ob) unless success
end
rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
@@ -2249,11 +2289,17 @@
ob.tag = tag if tag
if subject
- return rest_response(401, :reason => "Not authorised for the specified resource") unless Authorization.check(action, Rating, opts[:user], subject)
+ return rest_response(401, :reason => "Not authorised for the specified resource") unless Authorization.check(action, Tagging, opts[:user], subject)
ob.taggable = subject
end
- return rest_response(400, :object => ob) unless ob.save
+ success = ob.save
+
+ if success && action == "create"
+ Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob, :auth => subject)
+ end
+
+ return rest_response(400, :object => ob) unless success
end
rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
Modified: trunk/test/functional/api_controller_test.rb (3510 => 3511)
--- trunk/test/functional/api_controller_test.rb 2013-04-12 13:40:19 UTC (rev 3510)
+++ trunk/test/functional/api_controller_test.rb 2013-04-12 13:45:28 UTC (rev 3511)
@@ -19,6 +19,7 @@
def test_workflows
existing_workflows = Workflow.find(:all)
+ existing_activities = Activity.all
login_as(:john)
@@ -44,9 +45,17 @@
assert_response(:success)
extra_workflows = Workflow.find(:all) - existing_workflows
+ extra_activities = Activity.find(:all). - existing_activities
assert_equal(1, extra_workflows.length)
+ assert_equal(1, extra_activities.length)
+ new_activity = (extra_activities - existing_activities).first
+
+ assert_equal("John Smith", new_activity.subject_label);
+ assert_equal("create", new_activity.action);
+ assert_equal(title, new_activity.objekt_label);
+
@workflow_id = extra_workflows.first.id
# get the workflow
@@ -77,6 +86,8 @@
setup
login_as(:john)
+ existing_activities = Activity.all
+
rest_request(:put, 'workflow', "<?xml version='1.0'?>
<workflow>
<title>#{title2}</title>
@@ -84,6 +95,15 @@
assert_response(:success)
+ extra_activities = Activity.find(:all). - existing_activities
+ assert_equal(1, extra_activities.length)
+
+ new_activity = (extra_activities - existing_activities).first
+
+ assert_equal("John Smith", new_activity.subject_label);
+ assert_equal("edit", new_activity.action);
+ assert_equal(title2, new_activity.objekt_label);
+
# get the updated workflow
response = rest_request(:get, 'workflow', nil, "id" => @workflow_id,
@@ -100,6 +120,8 @@
# post a new version of the workflow
+ existing_activities = Activity.all
+
rest_request(:post, 'workflow', "<?xml version='1.0'?>
<workflow>
<type>Taverna 2</type>
@@ -108,6 +130,15 @@
assert_response(:success)
+ extra_activities = Activity.find(:all). - existing_activities
+ assert_equal(1, extra_activities.length)
+
+ new_activity = (extra_activities - existing_activities).first
+
+ assert_equal("John Smith", new_activity.subject_label);
+ assert_equal("create", new_activity.action);
+ assert_equal("Fetch today's xkcd comic", new_activity.objekt_label);
+
workflow = Workflow.find(@workflow_id)
assert_equal(2, workflow.versions.length)
@@ -134,6 +165,8 @@
# edit a particular version of a workflow
+ existing_activities = Activity.all
+
rest_request(:put, 'workflow', "<?xml version='1.0'?>
<workflow>
<title>Oranges</title>
@@ -141,6 +174,16 @@
assert_response(:success)
+ extra_activities = Activity.find(:all). - existing_activities
+ assert_equal(1, extra_activities.length)
+
+ new_activity = (extra_activities - existing_activities).first
+
+ assert_equal("John Smith", new_activity.subject_label);
+ assert_equal("edit", new_activity.action);
+ assert_equal("1", new_activity.extra);
+ assert_equal("Oranges", new_activity.objekt_label);
+
# Verify that only version 1 was changed
response = rest_request(:get, 'workflow', nil, "id" => @workflow_id, "version" => "1",
@@ -186,6 +229,8 @@
# post a file
+ existing_activities = Activity.all
+
rest_request(:post, 'file', "<?xml version='1.0'?>
<file>
<title>#{title}</title>
@@ -198,6 +243,14 @@
assert_response(:success)
+ new_activities = Activity.all - existing_activities
+
+ assert_equal(1, new_activities.length)
+
+ assert_equal("John Smith", new_activities.first.subject.name)
+ assert_equal("create", new_activities.first.action)
+ assert_equal(title, new_activities.first.objekt.title)
+
extra_files = Blob.find(:all) - existing_files
assert_equal(extra_files.length, 1)
@@ -235,6 +288,8 @@
setup
login_as(:john)
+ existing_activities = Activity.all
+
rest_request(:put, 'file', "<?xml version='1.0'?>
<file>
<title>#{title2}</title>
@@ -242,6 +297,13 @@
assert_response(:success)
+ new_activities = Activity.all - existing_activities
+
+ assert_equal(1, new_activities.length)
+ assert_equal("John Smith", new_activities.first.subject.name)
+ assert_equal("edit", new_activities.first.action)
+ assert_equal(title2, new_activities.first.objekt.title)
+
# get the updated file
response = rest_request(:get, 'file', nil, "id" => file.id,
@@ -254,6 +316,8 @@
# add a new version of the file
+ existing_activities = Activity.all
+
rest_request(:post, 'file', "<?xml version='1.0'?>
<file>
<title>#{title2}</title>
@@ -265,12 +329,21 @@
assert_response(:success)
+ new_activities = Activity.all - existing_activities
+
+ assert_equal(1, new_activities.length)
+ assert_equal("John Smith", new_activities.first.subject.name)
+ assert_equal("create", new_activities.first.action)
+ assert_equal(title2, new_activities.first.objekt.title)
+
file.reload
assert_equal(2, file.versions.length)
# update the first version of the file
+ existing_activities = Activity.all
+
rest_request(:put, 'file', "<?xml version='1.0'?>
<file>
<title>#{title3}</title>
@@ -278,6 +351,13 @@
assert_response(:success)
+ new_activities = Activity.all - existing_activities
+
+ assert_equal(1, new_activities.length)
+ assert_equal("John Smith", new_activities.first.subject.name)
+ assert_equal("edit", new_activities.first.action)
+ assert_equal(title3, new_activities.first.objekt.title)
+
file.reload
assert_equal(title3, file.find_version(1).title);
assert_equal(title2, file.find_version(2).title);
@@ -566,6 +646,8 @@
existing_comments = Comment.find(:all)
+ existing_activities = Activity.all
+
rest_request(:post, 'comment', "<?xml version='1.0'?>
<comment>
<comment>#{comment_text}</comment>
@@ -574,6 +656,13 @@
assert_response(:success)
+ new_activities = Activity.all - existing_activities
+
+ assert_equal(1, new_activities.length)
+ assert_equal("John Smith", new_activities.first.subject.name)
+ assert_equal("create", new_activities.first.action)
+ assert_equal("Unique tags", new_activities.first.objekt.commentable.title)
+
extra_comments = Comment.find(:all) - existing_comments
assert_equal(extra_comments.length, 1)
@@ -634,6 +723,8 @@
existing_ratings = Rating.find(:all)
+ existing_activities = Activity.all
+
rest_request(:post, 'rating', "<?xml version='1.0'?>
<rating>
<rating>4</rating>
@@ -642,6 +733,14 @@
assert_response(:success)
+ new_activities = Activity.all - existing_activities
+
+ assert_equal(1, new_activities.length)
+ assert_equal("John Smith", new_activities.first.subject.name)
+ assert_equal("create", new_activities.first.action)
+ assert_equal("Unique tags", new_activities.first.objekt.rateable.title)
+ assert_equal("Unique tags", new_activities.first.auth.title)
+
extra_ratings = Rating.find(:all) - existing_ratings
assert_equal(extra_ratings.length, 1)
@@ -710,6 +809,8 @@
existing_favourites = Bookmark.find(:all)
+ existing_activities = Activity.all
+
rest_request(:post, 'favourite', "<?xml version='1.0'?>
<favourite>
<object resource='#{workflow_url}'/>
@@ -717,6 +818,13 @@
assert_response(:success)
+ new_activities = Activity.all - existing_activities
+
+ assert_equal(1, new_activities.length)
+ assert_equal("John Smith", new_activities.first.subject.name)
+ assert_equal("create", new_activities.first.action)
+ assert_equal("Unique tags", new_activities.first.objekt.bookmarkable.title)
+
extra_favourites = Bookmark.find(:all) - existing_favourites
assert_equal(extra_favourites.length, 1)
@@ -768,6 +876,8 @@
existing_taggings = Tagging.find(:all)
+ existing_activities = Activity.all
+
rest_request(:post, 'tagging', "<?xml version='1.0'?>
<tagging>
<subject resource='#{workflow_url}'/>
@@ -776,6 +886,13 @@
assert_response(:success)
+ new_activities = Activity.all - existing_activities
+
+ assert_equal(1, new_activities.length)
+ assert_equal("John Smith", new_activities.first.subject.name)
+ assert_equal("create", new_activities.first.action)
+ assert_equal("my test tag", new_activities.first.objekt.tag.name)
+
extra_taggings = Tagging.find(:all) - existing_taggings
assert_equal(extra_taggings.length, 1)