forked from diaspora/diaspora
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'tag-exclusions' into diaspora-pistos-1.0.6
- Loading branch information
Showing
14 changed files
with
172 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class TagExclusionsController < ApplicationController | ||
before_filter :authenticate_user! | ||
|
||
# POST /tag_exclusions | ||
def create | ||
name_normalized = ActsAsTaggableOn::Tag.normalize(params['tag_exclusion']['name']) | ||
|
||
if name_normalized.nil? || name_normalized.empty? | ||
flash[:error] = I18n.t('tag_exclusions.create.none') | ||
else | ||
tag = ActsAsTaggableOn::Tag.find_or_create_by_name(name_normalized) | ||
tag_exclusion = current_user.tag_exclusions.new(:tag_id => tag.id) | ||
|
||
if tag_exclusion.save | ||
flash[:notice] = I18n.t('tag_exclusions.create.success', :name => name_normalized) | ||
else | ||
flash[:error] = I18n.t('tag_exclusions.create.failure', :name => name_normalized) | ||
end | ||
end | ||
|
||
redirect_to :back | ||
end | ||
|
||
# DELETE /tag_exclusions/1 | ||
def destroy | ||
@tag_exclusion = current_user.tag_exclusions.where(:id => params['id']).first | ||
success = @tag_exclusion && @tag_exclusion.destroy | ||
|
||
if params[:remote] | ||
respond_to do |format| | ||
format.all {} | ||
format.js { render 'tags/update' } # Hmm... this is probably not appropriate | ||
end | ||
else | ||
if success | ||
flash[:notice] = I18n.t('tag_exclusions.destroy.success', :name => @tag_exclusion.tag.name) | ||
else | ||
flash[:error] = I18n.t('tag_exclusions.destroy.failure', :name => @tag_exclusion.tag.name) | ||
end | ||
redirect_to filters_path | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class TagExclusion < ActiveRecord::Base | ||
belongs_to :user | ||
belongs_to :tag, :class_name => "ActsAsTaggableOn::Tag" | ||
|
||
validates_uniqueness_of :tag_id, :scope => :user_id | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
- content_for :page_title do | ||
= t('.title') | ||
|
||
#section_header | ||
%h2 | ||
= t('filters') | ||
= render 'shared/settings_nav' | ||
|
||
.span-12.prepend-5.last | ||
%h3 | ||
= t('.tag_exclusions') | ||
|
||
= form_for 'tag_exclusion', :url => tag_exclusions_path, :html => { :method => :post } do |f| | ||
= f.error_messages | ||
%p | ||
= f.text_field 'name' | ||
= f.submit t('.add'), :class => "button" | ||
|
||
- @tag_exclusions.each do |tx| | ||
= link_to "##{tx.tag.name}", tag_path(:name => tx.tag.name) | ||
\- | ||
= link_to t('.delete'), tag_exclusion_path(tx), :method => :delete | ||
%br | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class CreateTagExclusions < ActiveRecord::Migration | ||
|
||
def self.up | ||
create_table :tag_exclusions do |t| | ||
t.integer :user_id, :null => false | ||
t.integer :tag_id, :null => false | ||
t.timestamps | ||
end | ||
|
||
add_index :tag_exclusions, :tag_id | ||
add_index :tag_exclusions, :user_id | ||
add_index :tag_exclusions, [:tag_id, :user_id], :unique => true | ||
end | ||
|
||
def self.down | ||
remove_index :tag_exclusions, :column => [:tag_id, :user_id] | ||
remove_index :tag_exclusions, :column => :user_id | ||
remove_index :tag_exclusions, :column => :tag_id | ||
|
||
drop_table :tag_exclusions | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'spec_helper' | ||
|
||
describe TagExclusion do | ||
before do | ||
@tag = ActsAsTaggableOn::Tag.create(:name => "partytimeexcellent") | ||
TagExclusion.create!(:tag => @tag, :user => alice) | ||
end | ||
|
||
it 'validates uniqueness of tag_exclusion scoped through user' do | ||
TagExclusion.new(:tag => @tag, :user => alice).valid?.should be_false | ||
end | ||
|
||
it 'allows multiple tag exclusions for different users' do | ||
TagExclusion.new(:tag => @tag, :user => bob).valid?.should be_true | ||
end | ||
end |