diff options
author | Brett Walker <bwalker@gitlab.com> | 2018-10-26 15:49:16 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-10-26 15:49:16 +0300 |
commit | 7aeab58f4861144fcc1d334907cb1b465c645001 (patch) | |
tree | cc37daf4788c2f7c3d951e3fdc3164e1b7ae0fd9 /app/models/board_project_recent_visit.rb | |
parent | 9791f82b4b4f873c153e6698fbb2148b8fa5babe (diff) |
Automatically navigate to last board visited
Diffstat (limited to 'app/models/board_project_recent_visit.rb')
-rw-r--r-- | app/models/board_project_recent_visit.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/app/models/board_project_recent_visit.rb b/app/models/board_project_recent_visit.rb new file mode 100644 index 00000000000..7cffff906d8 --- /dev/null +++ b/app/models/board_project_recent_visit.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# Tracks which boards in a specific project a user has visited +class BoardProjectRecentVisit < ActiveRecord::Base + belongs_to :user + belongs_to :project + belongs_to :board + + validates :user, presence: true + validates :project, presence: true + validates :board, presence: true + + scope :by_user_project, -> (user, project) { where(user: user, project: project).order(:updated_at) } + + def self.visited!(user, board) + visit = find_or_create_by(user: user, project: board.project, board: board) + visit.touch if visit.updated_at < Time.now + rescue ActiveRecord::RecordNotUnique + retry + end + + def self.latest(user, project) + by_user_project(user, project).last + end +end |