public_activity 1.6.3 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +26 -28
- data/Rakefile +6 -5
- data/lib/generators/public_activity/migration/migration_generator.rb +3 -1
- data/lib/generators/public_activity/migration/templates/migration.rb +12 -10
- data/lib/generators/public_activity/migration_upgrade/migration_upgrade_generator.rb +4 -1
- data/lib/generators/public_activity/migration_upgrade/templates/upgrade.rb +4 -2
- data/lib/generators/public_activity.rb +2 -0
- data/lib/public_activity/actions/creation.rb +3 -1
- data/lib/public_activity/actions/destruction.rb +2 -0
- data/lib/public_activity/actions/update.rb +2 -0
- data/lib/public_activity/activity.rb +3 -1
- data/lib/public_activity/common.rb +16 -0
- data/lib/public_activity/config.rb +2 -0
- data/lib/public_activity/models/activist.rb +3 -1
- data/lib/public_activity/models/activity.rb +3 -1
- data/lib/public_activity/models/adapter.rb +3 -1
- data/lib/public_activity/models/trackable.rb +3 -1
- data/lib/public_activity/orm/active_record/activist.rb +2 -0
- data/lib/public_activity/orm/active_record/activity.rb +29 -11
- data/lib/public_activity/orm/active_record/adapter.rb +7 -0
- data/lib/public_activity/orm/active_record/trackable.rb +2 -0
- data/lib/public_activity/orm/active_record.rb +3 -1
- data/lib/public_activity/orm/mongo_mapper/activist.rb +2 -0
- data/lib/public_activity/orm/mongo_mapper/activity.rb +2 -0
- data/lib/public_activity/orm/mongo_mapper/adapter.rb +7 -0
- data/lib/public_activity/orm/mongo_mapper/trackable.rb +2 -0
- data/lib/public_activity/orm/mongo_mapper.rb +3 -1
- data/lib/public_activity/orm/mongoid/activist.rb +2 -0
- data/lib/public_activity/orm/mongoid/activity.rb +2 -0
- data/lib/public_activity/orm/mongoid/adapter.rb +7 -0
- data/lib/public_activity/orm/mongoid/trackable.rb +2 -0
- data/lib/public_activity/orm/mongoid.rb +3 -1
- data/lib/public_activity/renderable.rb +5 -2
- data/lib/public_activity/roles/deactivatable.rb +2 -0
- data/lib/public_activity/roles/tracked.rb +2 -0
- data/lib/public_activity/testing.rb +2 -0
- data/lib/public_activity/utility/store_controller.rb +2 -0
- data/lib/public_activity/utility/view_helpers.rb +2 -0
- data/lib/public_activity/version.rb +3 -1
- data/lib/public_activity.rb +2 -0
- data/test/migrations/001_create_activities.rb +1 -1
- data/test/migrations/002_create_articles.rb +2 -3
- data/test/migrations/003_create_users.rb +2 -2
- data/test/migrations/004_add_nonstandard_to_activities.rb +2 -2
- data/test/test_activist.rb +39 -36
- data/test/test_activity.rb +39 -38
- data/test/test_common.rb +66 -48
- data/test/test_controller_integration.rb +19 -11
- data/test/test_generators.rb +7 -17
- data/test/test_helper.rb +20 -24
- data/test/test_testing.rb +13 -10
- data/test/test_tracking.rb +171 -147
- data/test/test_view_helpers.rb +8 -6
- metadata +49 -40
- data/lib/generators/public_activity/activity/activity_generator.rb +0 -17
- data/lib/generators/public_activity/activity/templates/activity.rb +0 -3
- data/test/migrations_base.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f12beefe37e1f8d3c8fbaada9d0318de0838dd8514c1b32c93d47b97d7af6d57
|
4
|
+
data.tar.gz: bf5e00de61c14049488a4fe549a9bc198367eca931e9d73c0d47dd0ba9c173f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a95d53aac261777b5b52a1a35add35acc0d93d742d4cbb3d2f4deea08ec552ade88b61cbd4447146172953b4ecda464b3ea2539ecb82d58d26c7756cdc5c52b7
|
7
|
+
data.tar.gz: 7dc0ddb8a3622c52b856f1b5a1f45124d300892559800cd62b06115bc14854d0ff84bf33b5a88a50f9f6ae7c060f298f171cb7d082f9bae3aa9696dfdcb36d5a
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,37 +1,35 @@
|
|
1
1
|
# PublicActivity [![Build Status](https://secure.travis-ci.org/chaps-io/public_activity.svg)](http://travis-ci.org/chaps-io/public_activity) [![Code Climate](https://codeclimate.com/github/chaps-io/public_activity.svg)](https://codeclimate.com/github/chaps-io/public_activity) [![Gem Version](https://badge.fury.io/rb/public_activity.svg)](http://badge.fury.io/rb/public_activity)
|
2
2
|
|
3
3
|
`public_activity` provides easy activity tracking for your **ActiveRecord**, **Mongoid 3** and **MongoMapper** models
|
4
|
-
in Rails
|
5
|
-
recorded activities to users -
|
4
|
+
in Rails 5.0+. Simply put: it records what has been changed or created and gives you the ability to present those
|
5
|
+
recorded activities to users - similarly to how GitHub does it.
|
6
6
|
|
7
|
-
##
|
7
|
+
## Rails 7
|
8
8
|
|
9
|
-
|
10
|
-
<a style="max-width: 478x" href="https://getstream.io/try-the-api/?utm_source=public-activity&utm_medium=banner&utm_campaign=github"><img src="https://i.imgur.com/q4c8wVO.png"/>
|
11
|
-
</p>
|
12
|
-
|
13
|
-
## Rails 5
|
14
|
-
|
15
|
-
**As of 1.6.0 version, public_activity also supports Rails up to 5.2.**
|
9
|
+
**As of version 2.0.0, public_activity also supports Rails up to 7.0.**
|
16
10
|
|
17
11
|
## Table of contents
|
18
12
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
13
|
+
- [Rails 7](#rails-7)
|
14
|
+
- [Table of contents](#table-of-contents)
|
15
|
+
- [Example](#example)
|
16
|
+
- [Online demo](#online-demo)
|
17
|
+
- [Screencast](#screencast)
|
18
|
+
- [Setup](#setup)
|
19
|
+
- [Gem installation](#gem-installation)
|
20
|
+
- [Database setup](#database-setup)
|
21
|
+
- [Model configuration](#model-configuration)
|
22
|
+
- [Custom activities](#custom-activities)
|
23
|
+
- [Displaying activities](#displaying-activities)
|
24
|
+
- [Layouts](#layouts)
|
25
|
+
- [Locals](#locals)
|
26
|
+
- [Activity views](#activity-views)
|
27
|
+
- [I18n](#I18n)
|
28
|
+
- [Testing](#testing)
|
29
|
+
- [Documentation](#documentation)
|
30
|
+
- [Common examples](#common-examples)
|
31
|
+
- [Help](#help)
|
32
|
+
- [License](#license)
|
35
33
|
|
36
34
|
## Example
|
37
35
|
|
@@ -197,7 +195,7 @@ For example, if you have an activity with `:key` set to `"activity.user.changed_
|
|
197
195
|
|
198
196
|
If a view file does not exist, then p_a falls back to the old behaviour and tries to translate the activity `:key` using `I18n#translate` method (see the section below).
|
199
197
|
|
200
|
-
####
|
198
|
+
#### I18n
|
201
199
|
|
202
200
|
Translations are used by the `#text` method, to which you can pass additional options in form of a hash. `#render` method uses translations when view templates have not been provided. You can render pure i18n strings by passing `{display: :i18n}` to `#render_activity` or `#render`.
|
203
201
|
|
@@ -224,7 +222,7 @@ require 'public_activity/testing'
|
|
224
222
|
PublicActivity.enabled = false
|
225
223
|
```
|
226
224
|
|
227
|
-
In your specs you can then blockwise decide
|
225
|
+
In your specs you can then blockwise decide whether to turn `public_activity` on
|
228
226
|
or off.
|
229
227
|
|
230
228
|
```ruby
|
data/Rakefile
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
2
4
|
require 'rake'
|
3
5
|
require 'yard'
|
4
6
|
require 'yard/rake/yardoc_task'
|
5
7
|
require 'rake/testtask'
|
6
8
|
|
7
|
-
task :
|
9
|
+
task default: :test
|
8
10
|
|
9
11
|
desc 'Generate documentation for the public_activity plugin.'
|
10
12
|
YARD::Rake::YardocTask.new do |doc|
|
@@ -12,7 +14,6 @@ YARD::Rake::YardocTask.new do |doc|
|
|
12
14
|
end
|
13
15
|
|
14
16
|
Rake::TestTask.new do |t|
|
15
|
-
|
16
|
-
|
17
|
+
t.libs << 'test'
|
18
|
+
t.test_files = FileList['test/test*.rb']
|
17
19
|
end
|
18
|
-
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'generators/public_activity'
|
2
4
|
require 'rails/generators/active_record'
|
3
5
|
|
@@ -7,7 +9,7 @@ module PublicActivity
|
|
7
9
|
class MigrationGenerator < ActiveRecord::Generators::Base
|
8
10
|
extend Base
|
9
11
|
|
10
|
-
argument :name, :
|
12
|
+
argument :name, type: :string, default: 'create_activities'
|
11
13
|
# Create migration in project's folder
|
12
14
|
def generate_files
|
13
15
|
migration_template 'migration.rb', "db/migrate/#{name}.rb"
|
@@ -1,21 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Migration responsible for creating a table with activities
|
2
|
-
class CreateActivities <
|
3
|
-
# Create table
|
4
|
+
class CreateActivities < ActiveRecord::Migration[5.0]
|
4
5
|
def self.up
|
5
6
|
create_table :activities do |t|
|
6
|
-
t.belongs_to :trackable, :
|
7
|
-
t.belongs_to :owner, :
|
8
|
-
t.string
|
9
|
-
t.text
|
10
|
-
t.belongs_to :recipient, :
|
7
|
+
t.belongs_to :trackable, polymorphic: true
|
8
|
+
t.belongs_to :owner, polymorphic: true
|
9
|
+
t.string :key
|
10
|
+
t.text :parameters
|
11
|
+
t.belongs_to :recipient, polymorphic: true
|
11
12
|
|
12
13
|
t.timestamps
|
13
14
|
end
|
14
15
|
|
15
|
-
add_index :activities, [
|
16
|
-
add_index :activities, [
|
17
|
-
add_index :activities, [
|
16
|
+
add_index :activities, %i[trackable_id trackable_type]
|
17
|
+
add_index :activities, %i[owner_id owner_type]
|
18
|
+
add_index :activities, %i[recipient_id recipient_type]
|
18
19
|
end
|
20
|
+
|
19
21
|
# Drop table
|
20
22
|
def self.down
|
21
23
|
drop_table :activities
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'generators/public_activity'
|
2
4
|
require 'rails/generators/active_record'
|
3
5
|
|
@@ -7,7 +9,8 @@ module PublicActivity
|
|
7
9
|
class MigrationUpgradeGenerator < ActiveRecord::Generators::Base
|
8
10
|
extend Base
|
9
11
|
|
10
|
-
argument :name, :
|
12
|
+
argument :name, type: :string, default: 'upgrade_activities'
|
13
|
+
|
11
14
|
# Create migration in project's folder
|
12
15
|
def generate_files
|
13
16
|
migration_template 'upgrade.rb', "db/migrate/#{name}.rb"
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Migration responsible for creating a table with activities
|
2
|
-
class UpgradeActivities < ActiveRecord::Migration
|
4
|
+
class UpgradeActivities < ActiveRecord::Migration[5.0]
|
3
5
|
# Create table
|
4
6
|
def self.change
|
5
7
|
change_table :activities do |t|
|
6
|
-
t.belongs_to :recipient, :
|
8
|
+
t.belongs_to :recipient, polymorphic: true
|
7
9
|
end
|
8
10
|
end
|
9
11
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PublicActivity
|
2
4
|
# Happens when creating custom activities without either action or a key.
|
3
5
|
class NoKeyProvided < Exception; end
|
@@ -257,6 +259,20 @@ module PublicActivity
|
|
257
259
|
nil
|
258
260
|
end
|
259
261
|
|
262
|
+
# Directly saves activity to database. Works the same as create_activity
|
263
|
+
# but throws validation error for each supported ORM.
|
264
|
+
#
|
265
|
+
# @see #create_activity
|
266
|
+
def create_activity!(*args)
|
267
|
+
return unless self.public_activity_enabled?
|
268
|
+
options = prepare_settings(*args)
|
269
|
+
|
270
|
+
if call_hook_safe(options[:key].split('.').last)
|
271
|
+
reset_activity_instance_options
|
272
|
+
return PublicActivity::Adapter.create_activity!(self, options)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
260
276
|
# Prepares settings used during creation of Activity record.
|
261
277
|
# params passed directly to tracked model have priority over
|
262
278
|
# settings specified in tracked() method
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PublicActivity
|
2
4
|
# Provides association for activities bound to this object by *trackable*.
|
3
5
|
module Trackable
|
@@ -6,4 +8,4 @@ module PublicActivity
|
|
6
8
|
base.extend PublicActivity::inherit_orm("Trackable")
|
7
9
|
end
|
8
10
|
end
|
9
|
-
end
|
11
|
+
end
|
@@ -1,4 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PublicActivity
|
4
|
+
|
5
|
+
if not defined? ::PG::ConnectionBad
|
6
|
+
module ::PG
|
7
|
+
class ConnectionBad < Exception; end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
if not defined? Mysql2::Error::ConnectionError
|
11
|
+
module Mysql2
|
12
|
+
module Error
|
13
|
+
class ConnectionError < Exception; end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
2
18
|
module ORM
|
3
19
|
module ActiveRecord
|
4
20
|
# The ActiveRecord model containing
|
@@ -9,20 +25,22 @@ module PublicActivity
|
|
9
25
|
self.abstract_class = true
|
10
26
|
|
11
27
|
# Define polymorphic association to the parent
|
12
|
-
belongs_to :trackable, :
|
28
|
+
belongs_to :trackable, polymorphic: true
|
13
29
|
|
14
30
|
case ::ActiveRecord::VERSION::MAJOR
|
15
|
-
when 3..4
|
16
|
-
# Define ownership to a resource responsible for this activity
|
17
|
-
belongs_to :owner, :polymorphic => true
|
18
|
-
# Define ownership to a resource targeted by this activity
|
19
|
-
belongs_to :recipient, :polymorphic => true
|
20
31
|
when 5
|
21
|
-
with_options(:
|
32
|
+
with_options(required: false) do
|
33
|
+
# Define ownership to a resource responsible for this activity
|
34
|
+
belongs_to :owner, polymorphic: true
|
35
|
+
# Define ownership to a resource targeted by this activity
|
36
|
+
belongs_to :recipient, polymorphic: true
|
37
|
+
end
|
38
|
+
when 6..7
|
39
|
+
with_options(optional: true) do
|
22
40
|
# Define ownership to a resource responsible for this activity
|
23
|
-
belongs_to :owner, :
|
41
|
+
belongs_to :owner, polymorphic: true
|
24
42
|
# Define ownership to a resource targeted by this activity
|
25
|
-
belongs_to :recipient, :
|
43
|
+
belongs_to :recipient, polymorphic: true
|
26
44
|
end
|
27
45
|
end
|
28
46
|
|
@@ -33,9 +51,9 @@ module PublicActivity
|
|
33
51
|
else
|
34
52
|
warn("[WARN] table #{name} doesn't exist. Skipping PublicActivity::Activity#parameters's serialization")
|
35
53
|
end
|
36
|
-
rescue ::ActiveRecord::NoDatabaseError
|
54
|
+
rescue ::ActiveRecord::NoDatabaseError
|
37
55
|
warn("[WARN] database doesn't exist. Skipping PublicActivity::Activity#parameters's serialization")
|
38
|
-
rescue ::PG::ConnectionBad
|
56
|
+
rescue ::PG::ConnectionBad
|
39
57
|
warn("[WARN] couldn't connect to database. Skipping PublicActivity::Activity#parameters's serialization")
|
40
58
|
rescue Mysql2::Error::ConnectionError
|
41
59
|
warn("[WARN] couldn't connect to database. Skipping PublicActivity::Activity#parameters's serialization")
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PublicActivity
|
2
4
|
module ORM
|
3
5
|
# Support for ActiveRecord for PublicActivity. Used by default and supported
|
@@ -10,6 +12,11 @@ module PublicActivity
|
|
10
12
|
def self.create_activity(trackable, options)
|
11
13
|
trackable.activities.create options
|
12
14
|
end
|
15
|
+
|
16
|
+
# Creates activity on `trackable` with `options`; throws error on validation failure
|
17
|
+
def self.create_activity!(trackable, options)
|
18
|
+
trackable.activities.create! options
|
19
|
+
end
|
13
20
|
end
|
14
21
|
end
|
15
22
|
end
|
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_record'
|
2
4
|
require_relative 'active_record/activity.rb'
|
3
5
|
require_relative 'active_record/adapter.rb'
|
4
6
|
require_relative 'active_record/activist.rb'
|
5
|
-
require_relative 'active_record/trackable.rb'
|
7
|
+
require_relative 'active_record/trackable.rb'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PublicActivity
|
2
4
|
module ORM
|
3
5
|
module MongoMapper
|
@@ -6,6 +8,11 @@ module PublicActivity
|
|
6
8
|
def self.create_activity(trackable, options)
|
7
9
|
trackable.activities.create options
|
8
10
|
end
|
11
|
+
|
12
|
+
# Creates activity on `trackable` with `options`; throws error on validation failure
|
13
|
+
def self.create_activity!(trackable, options)
|
14
|
+
trackable.activities.create! options
|
15
|
+
end
|
9
16
|
end
|
10
17
|
end
|
11
18
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PublicActivity
|
2
4
|
module ORM
|
3
5
|
module Mongoid
|
@@ -6,6 +8,11 @@ module PublicActivity
|
|
6
8
|
def self.create_activity(trackable, options)
|
7
9
|
trackable.activities.create options
|
8
10
|
end
|
11
|
+
|
12
|
+
# Creates activity on `trackable` with `options`; throws error on validation failure
|
13
|
+
def self.create_activity!(trackable, options)
|
14
|
+
trackable.activities.create! options
|
15
|
+
end
|
9
16
|
end
|
10
17
|
end
|
11
18
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PublicActivity
|
2
4
|
# Provides logic for rendering activities. Handles both i18n strings
|
3
5
|
# support and smart partials rendering (different templates per activity key).
|
@@ -10,7 +12,8 @@ module PublicActivity
|
|
10
12
|
k.unshift('activity') if k.first != 'activity'
|
11
13
|
k = k.join('.')
|
12
14
|
|
13
|
-
|
15
|
+
translate_params = parameters.merge(params) || {}
|
16
|
+
I18n.t(k, **translate_params)
|
14
17
|
end
|
15
18
|
|
16
19
|
# Renders activity from views.
|
@@ -140,7 +143,7 @@ module PublicActivity
|
|
140
143
|
def prepare_layout(root, layout)
|
141
144
|
if layout
|
142
145
|
path = layout.to_s
|
143
|
-
unless path.
|
146
|
+
unless path.start_with?(root) || path.start_with?("/")
|
144
147
|
return File.join(root, path)
|
145
148
|
end
|
146
149
|
end
|
data/lib/public_activity.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
../../lib/generators/public_activity/migration/templates/migration.rb
|