diff --git a/Gemfile b/Gemfile index ef96c09..befb232 100644 --- a/Gemfile +++ b/Gemfile @@ -23,6 +23,7 @@ gem 'devise' gem 'omniauth-github' gem "octokit", "~> 4.0" gem "pundit" +gem 'public_activity' group :development, :test do gem 'pry-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 3952646..0da5764 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -147,6 +147,11 @@ GEM method_source (~> 0.9.0) pry-rails (0.3.9) pry (>= 0.10.4) + public_activity (1.6.4) + actionpack (>= 3.0.0) + activerecord (>= 3.0) + i18n (>= 0.5.0) + railties (>= 3.0.0) public_suffix (4.0.1) puma (3.12.1) pundit (2.1.0) @@ -270,6 +275,7 @@ DEPENDENCIES omniauth-github pg (>= 0.18, < 2.0) pry-rails + public_activity puma (~> 3.11) pundit rails (~> 5.2.3) @@ -286,4 +292,4 @@ RUBY VERSION ruby 2.6.0p0 BUNDLED WITH - 1.17.2 + 1.17.3 diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb new file mode 100644 index 0000000..b0081d4 --- /dev/null +++ b/app/controllers/activities_controller.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class ActivitiesController < ApplicationController + def index + @activities = PublicActivity::Activity.includes(:owner).order(created_at: :desc).limit(20) + end +end \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5dde212..b9708eb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,6 @@ class ApplicationController < ActionController::Base include Pundit + include PublicActivity::StoreController + end diff --git a/app/models/developer.rb b/app/models/developer.rb index 5467101..7b2334e 100644 --- a/app/models/developer.rb +++ b/app/models/developer.rb @@ -1,4 +1,6 @@ # frozen_string_literal: true class Developer < ApplicationRecord + include PublicActivity::Model + tracked owner: proc { |controller, _model| controller.current_user } end diff --git a/app/models/project.rb b/app/models/project.rb index 1ef799c..2c1ba79 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Project < ApplicationRecord + include PublicActivity::Model + tracked owner: proc { |controller, _model| controller.current_user } validates :name, presence: true belongs_to :user diff --git a/app/models/user.rb b/app/models/user.rb index 659f19a..45f960b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -6,9 +6,10 @@ class User < ApplicationRecord devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable, :omniauthable - + has_many :projects - + has_many :activities, as: :owner, class_name: 'PublicActivity::Activity' + validates :role, presence: true, inclusion: { in: ROLES } enum role: ROLES diff --git a/app/views/activities/index.html.erb b/app/views/activities/index.html.erb new file mode 100644 index 0000000..9ba0ecc --- /dev/null +++ b/app/views/activities/index.html.erb @@ -0,0 +1,2 @@ +

Activities:

+<%= render_activities(@activities) %> diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index 32a6a4d..75fba9a 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -14,6 +14,10 @@ + +