Merge pull request #2255 from ZeiP/feature/#1955_user_tags

#1955: Migrate tags to belong to named users for enhanced privacy.
This commit is contained in:
Matt Rogers 2019-08-02 09:38:52 -05:00 committed by GitHub
commit 3ac8702a5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 130 additions and 24 deletions

View file

@ -712,9 +712,8 @@ class TodosController < ApplicationController
def tags
# TODO: limit to current_user
tags_beginning = Tag.where(Tag.arel_table[:name].matches("#{params[:term]}%"))
tags_all = Tag.where(Tag.arel_table[:name].matches("%#{params[:term]}%"))
tags_beginning = current_user.tags.where(Tag.arel_table[:name].matches("#{params[:term]}%"))
tags_all = current_user.tags.where(Tag.arel_table[:name].matches("%#{params[:term]}%"))
tags_all = tags_all - tags_beginning
respond_to do |format|

View file

@ -3,13 +3,15 @@ class Tag < ApplicationRecord
has_many :taggings
has_many :taggable, :through => :taggings
belongs_to :user
DELIMITER = ",".freeze # Controls how to split and join tagnames from strings. You may need to change the <tt>validates_format_of parameters</tt> if you change this.
JOIN_DELIMITER = ", ".freeze
# If database speed becomes an issue, you could remove these validations and
# rescue the ActiveRecord database constraint errors instead.
validates_presence_of :name
validates_uniqueness_of :name, :case_sensitive => false
validates_uniqueness_of :name, :scope => "user_id", :case_sensitive => false
before_create :before_create

View file

@ -94,6 +94,7 @@ class User < ApplicationRecord
end
end
has_many :tags, dependent: :delete_all
has_many :notes, -> { order "created_at DESC" }, dependent: :delete_all
has_one :preference, dependent: :destroy
has_many :attachments, through: :todos