Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ gem 'foreman'
# Better logging
gem 'awesome_print'

# Tagging
gem 'acts-as-taggable-on', '~> 3.4'

gem 'faraday', '~> 0.8.1'
gem 'metamagic'

Expand Down Expand Up @@ -135,9 +138,6 @@ gem 'mongoid'
gem 'mongo'
gem 'mongoid_taggable'
gem 'bson_ext'
#Tagging
gem 'rocket_tag'
gem 'squeel', '1.0.1'
gem 'strong_parameters'
gem 'postgres_ext'
# ElasticSearch client
Expand Down
14 changes: 3 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ GEM
activesupport (3.2.21)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
acts-as-taggable-on (3.4.2)
activerecord (>= 3.2, < 5)
acts_as_commentable (2.0.1)
acts_as_follower (0.1.1)
addressable (2.3.6)
Expand Down Expand Up @@ -475,8 +477,6 @@ GEM
cliver (~> 0.3.1)
multi_json (~> 1.0)
websocket-driver (>= 0.2.0)
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.5)
poro_plus (1.0.2)
posix-spawn (0.3.9)
Expand Down Expand Up @@ -593,9 +593,6 @@ GEM
rest-client (1.7.2)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rocket_tag (0.5.6)
activerecord (>= 3.2.0)
squeel (~> 1.0.0)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
Expand Down Expand Up @@ -688,10 +685,6 @@ GEM
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
squeel (1.0.1)
activerecord (~> 3.0)
activesupport (~> 3.0)
polyamorous (~> 0.5.0)
strong_parameters (0.2.3)
actionpack (~> 3.0)
activemodel (~> 3.0)
Expand Down Expand Up @@ -763,6 +756,7 @@ PLATFORMS
ruby

DEPENDENCIES
acts-as-taggable-on (~> 3.4)
acts_as_commentable (= 2.0.1)
acts_as_follower (= 0.1.1)
airbrake
Expand Down Expand Up @@ -855,7 +849,6 @@ DEPENDENCIES
redcarpet
redis-rails (~> 3.2)
rest-client
rocket_tag
rspec-rails
rubocop
ruby-progressbar
Expand All @@ -872,7 +865,6 @@ DEPENDENCIES
slim-rails
spring
spring-commands-rspec
squeel (= 1.0.1)
stripe!
stripe-ruby-mock!
strong_parameters
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/networks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def members

def show
@protips = []
@topics = @network.tags
@topics = @network.tag_list

if (params[:sort].blank? && params[:filter].blank?) || params[:sort] == 'upvotes'
@protips = @network.most_upvoted_protips(@per_page, @page)
Expand Down Expand Up @@ -141,7 +141,7 @@ def destroy

def add_tag
tag = params[:tag]
@network.tags << tag
@network.tag_list.add(tag)

respond_to do |format|
if @network.save
Expand All @@ -155,8 +155,8 @@ def add_tag
end

def remove_tag
tag = params[:tag]
@network.tags = @network.tags.delete(tag)
tag = params[:tag]
@network.tag_list.remove(tag)

respond_to do |format|
if @network.save
Expand All @@ -171,7 +171,7 @@ def remove_tag

def update_tags
tags = params[:tags][:tags]
@network.tags = tags.split(',').map(&:strip).select { |tag| Tag.exists?(name: tag) }
@network.tag_list = tags.split(',').map(&:strip).select { |tag| Tag.exists?(name: tag) }

respond_to do |format|
if @network.save
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/opportunities_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class OpportunitiesController < ApplicationController
before_action :lookup_team, only: [:activate, :deactivate, :new, :create, :edit, :update, :visit]
before_action :lookup_opportunity, only: [:edit, :update, :activate, :deactivate, :visit]
before_action :cleanup_params_to_prevent_rocket_tag_error
before_action :cleanup_params_to_prevent_tagging_error
before_action :validate_permissions, only: [:new, :edit, :create, :update, :activate, :deactivate]
before_action :verify_payment, only: [:new, :create]
before_action :stringify_location, only: [:create, :update]
Expand Down Expand Up @@ -29,7 +29,7 @@ def edit
end

def create
opportunity_create_params = params.require(:opportunity).permit(:name, :team_id, :opportunity_type, :description, :tags, :location, :link, :salary, :apply, :remote)
opportunity_create_params = params.require(:opportunity).permit(:name, :team_id, :opportunity_type, :description, :tag_list, :location, :link, :salary, :apply, :remote)
@job = Opportunity.new(opportunity_create_params)
respond_to do |format|
if @job.save
Expand All @@ -42,7 +42,7 @@ def create
end

def update
opportunity_update_params = params.require(:opportunity).permit(:id, :name, :team_id, :opportunity_type, :description, :tags, :location, :link, :salary, :apply)
opportunity_update_params = params.require(:opportunity).permit(:id, :name, :team_id, :opportunity_type, :description, :tag_list, :location, :link, :salary, :apply)
respond_to do |format|
if @job.update_attributes(opportunity_update_params)
format.html { redirect_to teamname_path(@team.slug), notice: "#{@job.name} updated" }
Expand Down Expand Up @@ -131,10 +131,10 @@ def header_ok
end
end

def cleanup_params_to_prevent_rocket_tag_error
if params[:opportunity] && params[:opportunity][:tags]
params[:opportunity][:tags] = "#{params[:opportunity][:tags]}".split(',').map(&:strip).reject(&:empty?).join(",")
params[:opportunity][:tags] = nil if params[:opportunity][:tags].strip.blank?
def cleanup_params_to_prevent_tagging_error
if params[:opportunity] && params[:opportunity][:tag_list]
params[:opportunity][:tag_list] = "#{params[:opportunity][:tag_list]}".split(',').map(&:strip).reject(&:empty?).join(",")
params[:opportunity][:tag_list] = nil if params[:opportunity][:tag_list].strip.blank?
end
end

Expand All @@ -151,7 +151,7 @@ def all_job_locations
end

def all_job_skills
Rails.cache.fetch('job_skills', expires_in: 23.hours) { Opportunity.all.flat_map(&:tags).uniq.compact }
Rails.cache.fetch('job_skills', expires_in: 23.hours) { Opportunity.all.flat_map(&:tag_list).uniq.compact }
end

def closest_to_user(user)
Expand Down
18 changes: 9 additions & 9 deletions app/controllers/protips_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ def random
end

def new
new_params = params.permit(:topics)
new_params = params.permit(:topic_list)

prefilled_topics = (new_params[:topics] || '').split('+').collect(&:strip)
@protip = Protip.new(topics: prefilled_topics)
prefilled_topics = (new_params[:topic_list] || '').split('+').collect(&:strip)
@protip = Protip.new(topic_list: prefilled_topics)
respond_with @protip
end

Expand All @@ -165,7 +165,7 @@ def edit

def create
create_params = if params[:protip] && params[:protip].keys.present?
params.require(:protip).permit(:title, :body, :user_id, topics: [])
params.require(:protip).permit(:title, :body, :user_id, :topic_list)
else
{}
end
Expand All @@ -187,7 +187,7 @@ def create
def update
# strong_parameters will intentionally fail if a key is present but has an empty hash. :(
update_params = if params[:protip] && params[:protip].keys.present?
params.require(:protip).permit(:title, :body, :user_id, topics: [])
params.require(:protip).permit(:title, :body, :user_id, :topic_list)
else
{}
end
Expand Down Expand Up @@ -233,8 +233,8 @@ def upvote
end

def tag
tag_params = params.permit(:topics)
@protip.topics << tag_params[:topics] unless tag_params[:topics].nil?
tag_params = params.permit(:topic_list)
@protip.topic_list.add(tag_params[:topic_list]) unless tag_params[:topic_list].nil?
end

def subscribe
Expand Down Expand Up @@ -316,7 +316,7 @@ def feature
end

def delete_tag
@protip.topics.delete(CGI.unescape(params.permit(:topic)))
@protip.topic_list.remove(params.permit(:topic))
respond_to do |format|
if @protip.save
format.html { redirect_to protip_path(@protip) }
Expand Down Expand Up @@ -349,7 +349,7 @@ def by_tags
def preview
preview_params = params.require(:protip).permit(:title, :body)

preview_params.delete(:topics) if preview_params[:topics].blank?
preview_params.delete(:topic_list) if preview_params[:topic_list].blank?
protip = Protip.new(preview_params)
protip.updated_at = protip.created_at = Time.now
protip.user = current_user
Expand Down
36 changes: 16 additions & 20 deletions app/models/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Network < ActiveRecord::Base
profile_url: { type: 'string', index: 'not_analyzed' },
} } } }

attr_taggable :tags
acts_as_taggable
acts_as_followable
attr_accessor :resident_expert
has_many :network_experts, autosave: true, dependent: :destroy
Expand Down Expand Up @@ -61,7 +61,7 @@ def top_tags_not_networks
end

def top_tags_not_in_any_networks
top_tags.where('tags.name NOT IN (?)', Network.all.map(&:tags).flatten)
top_tags.where('tags.name NOT IN (?)', Network.all.map(&:tag_list).flatten)
end

def top_tags
Expand All @@ -82,21 +82,17 @@ def create_slug!
end

def tag_with_name!
unless self.tags.include? self.name
self.tags = (self.tags + [self.name, self.slug])
unless self.tag_list.include? self.name
self.tag_list = (self.tag_list + [self.name, self.slug])
end
end

def correct_tags
if self.tags_changed?
self.tags = self.tags.uniq.select { |tag| Tag.exists?(name: tag) }.reject { |tag| (tag != self.name) && Network.exists?(name: tag) }
if self.tag_list_changed?
self.tags_list = self.tag_list.uniq.select { |tag| Tag.exists?(name: tag) }.reject { |tag| (tag != self.name) && Network.exists?(name: tag) }
end
end

def tags_changed?
self.tags_tags.map(&:name) != self.tags
end

def protips_tags_with_count
self.protips.joins("inner join taggings on taggings.taggable_id = protips.id").joins('inner join tags on taggings.tag_id = tags.id').where("taggings.taggable_type = 'Protip' AND taggings.context = 'topics'").select('tags.name, count(tags.name)').group('tags.name').order('count(tags.name) DESC')
end
Expand All @@ -117,7 +113,7 @@ def assign_mayor!

candidate = self.in_line_to_the_throne.first
unless candidate.nil?
Rails.logger.debug "finding a mayor among: #{self.tags}" if ENV['DEBUG']
Rails.logger.debug "finding a mayor among: #{self.tag_list}" if ENV['DEBUG']
person_with_most_upvoted_protips_on_topic = User.find(candidate.user_id)
Rails.logger.debug "mayor for #{name} found: #{person_with_most_upvoted_protips_on_topic.username}" if ENV['DEBUG']

Expand Down Expand Up @@ -163,41 +159,41 @@ def to_public_hash
end

def protips
@protips ||= Protip.tagged_with(self.tags, on: :topics)
@protips ||= Protip.tagged_with(self.tag_list, on: :topics)
end

def upvotes
self.protips.joins("inner join likes on likes.likable_id = protips.id").where("likes.likable_type = 'Protip'").select('count(*)').count
end

def most_upvoted_protips(limit = nil, offset = 0)
Protip.search_trending_by_topic_tags("sort:upvotes desc", self.tags, offset, limit)
Protip.search_trending_by_topic_tags("sort:upvotes desc", self.tag_list, offset, limit)
end

def new_protips(limit = nil, offset = 0)
Protip.search("sort:created_at desc", self.tags, page: offset, per_page: limit)
Protip.search("sort:created_at desc", self.tag_list, page: offset, per_page: limit)
end

def featured_protips(limit = nil, offset = 0)
#self.protips.where(:featured => true)
Protip.search("featured:true", self.tags, page: offset, per_page: limit)
Protip.search("featured:true", self.tag_list, page: offset, per_page: limit)

end

def flagged_protips(limit = nil, offset = 0)
Protip.search("flagged:true", self.tags, page: offset, per_page: limit)
Protip.search("flagged:true", self.tag_list, page: offset, per_page: limit)
end

def highest_scored_protips(limit=nil, offset =0, field=:trending_score)
Protip.search("sort:#{field} desc", self.tags, page: offset, per_page: limit)
Protip.search("sort:#{field} desc", self.tag_list, page: offset, per_page: limit)
end

def mayor_protips(limit=nil, offset =0)
Protip.search_trending_by_user(self.mayor.username, nil, self.tags, offset, limit)
Protip.search_trending_by_user(self.mayor.username, nil, self.tag_list, offset, limit)
end

def expert_protips(limit=nil, offset =0)
Protip.search_trending_by_user(self.resident_expert.username, nil, self.tags, offset, limit)
Protip.search_trending_by_user(self.resident_expert.username, nil, self.tag_list, offset, limit)
end

def members(limit = -1, offset = 0)
Expand Down Expand Up @@ -226,7 +222,7 @@ def resident_expert_from_env
end

def assign_members
Skill.where(name: self.tags).select('DISTINCT(user_id)').map(&:user).each do |member|
Skill.where(name: self.tag_list).select('DISTINCT(user_id)').map(&:user).each do |member|
member.join(self)
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/models/opportunity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Opportunity < ActiveRecord::Base
include SearchModule
include OpportunityMapping

attr_taggable :tags
acts_as_taggable

OPPORTUNITY_TYPES = %w(full-time part-time contract internship)

Expand All @@ -16,7 +16,7 @@ class Opportunity < ActiveRecord::Base
validates :name, presence: true, allow_blank: false
validates :opportunity_type, inclusion: { in: OPPORTUNITY_TYPES }
validates :description, length: { minimum: 100, maximum: 2000 }
validates :tags, with: :tags_within_length
validates :tag_list, with: :tags_within_length
validates :location, presence: true, allow_blank: false
validates :location_city, presence: true, allow_blank: false, unless: lambda { location && anywhere?(location) }
validates :salary, presence: true, numericality: true, inclusion: 0..800_000, allow_blank: true
Expand Down Expand Up @@ -76,13 +76,13 @@ def self.random
end

def tags_within_length
tags_string = tags.join(',')
tags_string = tag_list.join(',')
errors.add(:skill_tags, 'are too long(Maximum is 250 characters)') if tags_string.length > 250
errors.add(:base, 'You need to specify at least one skill tag') if tags_string.length == 0
end

def update_cached_tags
self.cached_tags = tags.join(',')
self.cached_tags = tag_list.join(',')
end

def seize_by(user)
Expand Down
Loading