Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/next' into fixes-jc
Browse files Browse the repository at this point in the history
  • Loading branch information
kuadrosx committed May 26, 2011
2 parents 8314eaf + d023b75 commit 6b51351
Show file tree
Hide file tree
Showing 23 changed files with 128 additions and 88 deletions.
11 changes: 5 additions & 6 deletions Gemfile.lock
Expand Up @@ -18,7 +18,7 @@ GIT

GIT
remote: git://github.com/mongoid/mongoid.git
revision: b760004d5bc473cba63dacaec5c1be49202f3e4f
revision: 3607496b0a98ac62edd27cfe63f4b054130deb72
specs:
mongoid (2.0.1)
activemodel (~> 3.0)
Expand Down Expand Up @@ -70,7 +70,7 @@ GEM
activesupport (= 3.0.6)
activesupport (3.0.6)
addressable (2.2.4)
arel (2.0.9)
arel (2.0.10)
autotest (4.4.6)
ZenTest (>= 4.4.1)
bcrypt-ruby (2.1.4)
Expand Down Expand Up @@ -113,10 +113,9 @@ GEM
faraday (0.6.1)
addressable (~> 2.2.4)
multipart-post (~> 1.1.0)
rack (< 2, >= 1.1.0)
ffaker (1.5.0)
ffi (1.0.7)
rake (>= 0.8.7)
rack (>= 1.1.0, < 2)
ffaker (1.6.0)
ffi (1.0.8)
fssm (0.2.7)
gem_plugin (0.2.3)
goalie (0.0.4)
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/groups_controller.rb
Expand Up @@ -74,8 +74,9 @@ def edit
# POST /groups.json
def create
@group = Group.new
@group.languages = params[:languages].split(',') if params[:languages]
@group.safe_update(%w[name legend description default_tags subdomain logo forum enable_latex
custom_favicon language languages theme signup_type custom_css wysiwyg_editor], params[:group])
custom_favicon language theme signup_type custom_css wysiwyg_editor], params[:group])

@group.safe_update(%w[isolate domain private], params[:group]) if current_user.admin?

Expand All @@ -101,10 +102,11 @@ def create
# PUT /groups/1
# PUT /groups/1.json
def update
@group.languages = params[:languages].split(',') if params[:languages]
@group.safe_update(%w[name legend description default_tags subdomain logo logo_info forum enable_latex
custom_favicon language languages theme reputation_rewards reputation_constrains
has_adult_content registered_only signup_type custom_css wysiwyg_editor fb_button notification_opts], params[:group])
@group.share.safe_update(%w[fb_app_id fb_secret_key fb_active starts_with ends_with enable_twitter twitter_user twitter_pattern], params[:group][:share])
@group.share.safe_update(%w[fb_app_id fb_secret_key fb_active starts_with ends_with enable_twitter twitter_user twitter_pattern], params[:group][:share]) if params[:group][:share]
@group.safe_update(%w[isolate domain private has_custom_analytics has_custom_html has_custom_js], params[:group]) #if current_user.admin?
@group.safe_update(%w[analytics_id analytics_vendor], params[:group]) if @group.has_custom_analytics
@group.custom_html.update_attributes(params[:group][:custom_html] || {}) if @group.has_custom_html
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/invitations_controller.rb
Expand Up @@ -36,9 +36,17 @@ def accept
end
end

def resend
invitation = Invitation.find(params[:id])
Jobs::Mailer.async.on_new_invitation(invitation.id).commit!
flash[:notice] = t("flash_notice", :scope => "invitations.create")
redirect_to :back
end

def revoke
invitation = Invitation.find(params[:id])
current_user.revoke_invite(invitation)
flash[:notice] = t("flash_notice", :scope => "invitations.create")
redirect_to :back
end
end
24 changes: 0 additions & 24 deletions app/controllers/middlewares/dynamic_domain.rb

This file was deleted.

8 changes: 5 additions & 3 deletions app/controllers/users_controller.rb
Expand Up @@ -69,12 +69,14 @@ def index
# render new.rhtml
def new
@user = User.new
@user.preferred_languages = current_languages.to_a
@user.timezone = AppConfig.default_timezone
end

def create
@user = User.new
@user.safe_update(%w[login email name password_confirmation password preferred_languages website
@user.preferred_languages = params[:preferred_languages].split(',') if params[:languages]
@user.safe_update(%w[login email name password_confirmation password website
language timezone identity_url bio hide_country], params[:user])
if params[:user]["birthday(1i)"]
@user.birthday = build_date(params[:user], "birthday")
Expand Down Expand Up @@ -178,8 +180,8 @@ def update
@user.password_confirmation = params[:user][:password_confirmation]
end

@user.safe_update(%w[login email name language timezone preferred_languages
notification_opts bio hide_country website avatar use_gravatar], params[:user])
@user.preferred_languages = params[:preferred_languages].split(',') if params[:languages]
@user.safe_update(%w[login email name language timezone notification_opts bio hide_country website avatar use_gravatar], params[:user])

if params[:user]["birthday(1i)"]
@user.birthday = build_date(params[:user], "birthday")
Expand Down
19 changes: 19 additions & 0 deletions app/helpers/application_helper.rb
@@ -1,5 +1,11 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def known_languages(user, group)
return group.languages unless logged_in?
languages = user.preferred_languages & group.languages
(languages.empty?)? group.languages : languages
end

def multiauth_dropdown(title)
render 'shared/login_menu', :title => title
end
Expand All @@ -14,6 +20,19 @@ def with_facebook?
end
end

def language_json
languages = []
I18n.t('languages').keys.each do |k| languages << {:caption => I18n.t("languages.#{k}"),
:value=>I18n.t("languages.#{k}"), :code => k} end
languages.to_json
end

def preferred_languages_code(entity, language_method)
entity.send(language_method).map do |code|
I18n.t("languages.#{code}")+":#{code}"
end
end

def language_desc(langs)
(langs.kind_of?(Array) ? langs : [langs]).map do |lang|
I18n.t("languages.#{lang}", :default => lang).capitalize
Expand Down
19 changes: 11 additions & 8 deletions app/models/user.rb
Expand Up @@ -560,7 +560,7 @@ def linked_in_friends

## TODO: add google contacts
def suggestions(group, limit = 5)
sample = (suggested_social_friends(limit) | suggested_tags_by_suggested_friends(group, limit) ).sample(limit)
sample = (suggested_social_friends(group, limit) | suggested_tags_by_suggested_friends(group, limit) ).sample(limit)

# if we find less suggestions than requested, complete with
# most popular users and tags
Expand Down Expand Up @@ -588,7 +588,7 @@ def suggested_tags(group, limit = 5)

#returns tags followed by self suggested friends that I may not follow
def suggested_tags_by_suggested_friends(group, limit = 5)
friends = suggested_social_friends(limit)
friends = suggested_social_friends(group, limit)
unless friends.blank?
friends.
where("membership_list.#{group.id}.preferred_tags" => {"$ne" => [], "$ne" => nil},
Expand All @@ -599,10 +599,12 @@ def suggested_tags_by_suggested_friends(group, limit = 5)
friend_preferred_tags = []
(friend.membership_list[group.id].nil?)? friend_preferred_tags = [] :
friend_preferred_tags = friend.membership_list[group.id]["preferred_tags"]
(friend_preferred_tags-self.preferred_tags_on(group)).each do |tag|
friends_tags["#{tag}"] ||= { }
friends_tags["#{tag}"]["followed_by"] ||= []
friends_tags["#{tag}"]["followed_by"] << friend
if friend_preferred_tags
(friend_preferred_tags-self.preferred_tags_on(group)).each do |tag|
friends_tags["#{tag}"] ||= { }
friends_tags["#{tag}"]["followed_by"] ||= []
friends_tags["#{tag}"]["followed_by"] << friend
end
end
end
friends_tags.to_a.sample(limit)
Expand All @@ -612,15 +614,16 @@ def suggested_tags_by_suggested_friends(group, limit = 5)

# returns user's providers friends that have an account
# on shapado but that user is not following
def suggested_social_friends(limit = 5)
def suggested_social_friends(group, limit = 5)
array_hash = []
social_connections.to_a.each do |provider|
unless external_friends_list.friends[provider].blank?
array_hash << { "#{provider}_id".to_sym => {:$in => self.social_friends_ids(provider)}}
end
end
(array_hash.blank?)? [] : User.any_of(array_hash).
where({:_id => {:$not =>
where({"membership_list.#{group.id}" => {"$ne" => [], "$ne" => nil},
:_id => {:$not =>
{:$in => self.friend_list.following_ids}}}).
limit(limit)
end
Expand Down
5 changes: 4 additions & 1 deletion app/views/admin/manage/properties/_invitations.html.haml
Expand Up @@ -4,4 +4,7 @@
= invitation.email
= form_tag revoke_invitation_path(invitation), :class => "form", :multipart => true, :method => :post do
= hidden_field_tag :source, domain_url(:custom => @group.domain, :controller => "admin/manage", :action => "invitations", :tab => @active_subtab)
= submit_tag 'revoke'
= submit_tag t('.revoke_button')
= form_tag resend_invitation_path(invitation), :class => "form", :multipart => true, :method => :post do
= hidden_field_tag :source, domain_url(:custom => @group.domain, :controller => "admin/manage", :action => "invitations", :tab => @active_subtab)
= submit_tag t('.resend_button')
11 changes: 1 addition & 10 deletions app/views/groups/_form.html.haml
Expand Up @@ -126,16 +126,7 @@
= form.select :language, AVAILABLE_LANGUAGES.collect {|lang| [ language_desc(lang), lang ] }, :selected => @group.language || 'en', :class => "select"
.field
= form.label :language, t(:languages, :scope => "activerecord.attributes.group"), :class => "label"
= link_to t('users.form.show_more_lang'), nil, :class => 'show-more-lang'

- [DEFAULT_USER_LANGUAGES, AVAILABLE_LANGUAGES-DEFAULT_USER_LANGUAGES].each_with_index do |langs, index|
-jsclass = index == 1 ? 'jshide' : ''
-langs.sort.each do |lang|
#lang_opts
.radio_option{:id=>language_desc(lang)}
= check_box_tag "group[languages][]", lang, @group.languages.include?(lang), :class => "langbox checkbox #{jsclass}"
%label.radio.langbox{:class=>jsclass}
= language_desc(lang)
= text_field_tag :languages, preferred_languages_code(@group, 'languages').join(','), :class => "text_field autocomplete_for_tags", 'data-opts'=> "{\"allowNewTags\": false, \"source\":#{language_json}}"
-else
= form.hidden_field :language, :value => (AppConfig.default_language || 'en')

15 changes: 7 additions & 8 deletions app/views/groups/_top_grouplist.html.haml
@@ -1,16 +1,15 @@
%li.group
%small
// TODO I18n
Active site:
= link_to current_group.name
= t('.active_site')
= link_to current_group.name, domain_url(:custom => current_group.domain)
%ul
-if logged_in?
-current_user.groups.only(:name).limit(10).all.each do |group|
-current_user.groups.only(:name, :domain).limit(10).all.each do |group|
%li
= link_to group.name, group_path(group)
= link_to group.name, domain_url(:custom => group.domain)
-else
-Group.where(:state => "active", :private => false).order_by([:activity_rate, :desc]).limit(10).all.each do |group|
-Group.only(:name, :domain).where(:state => "active", :private => false).order_by([:activity_rate, :desc]).limit(10).all.each do |group|
%li
= link_to group.name, group_path(group)
= link_to group.name, domain_url(:custom => group.domain)
%li
= link_to t(".request_group"), new_group_path
= link_to t("groups.new.title"), new_group_path
2 changes: 1 addition & 1 deletion app/views/pages/_form.html.haml
Expand Up @@ -30,7 +30,7 @@
.group
= f.label :language, t(:language, :scope => "activerecord.attributes.question"), :class => "label"
-lang = @page.new? ? current_user.main_language : @page.language
= f.select :language, languages_options(current_user.preferred_languages)+[[t("languages.any"), ""]], {:selected => lang}, :class => "select"
= f.select :language, languages_options(current_user.preferred_languages)+[[t("preferred_languages.any"), ""]], {:selected => lang}, :class => "select"
.description
= t(".language_tip")
-else
Expand Down
2 changes: 1 addition & 1 deletion app/views/questions/_form.html.haml
Expand Up @@ -43,7 +43,7 @@
.field
= f.label :language, t(:language, :scope => "activerecord.attributes.question"), :class => "label"
- selected = @question.new? ? current_group.language : @question.language
= f.select :language, languages_options(current_group.languages), {:selected => selected}, {:class => "select"}
= f.select :language, languages_options(known_languages(current_user, current_group)), {:selected => selected}, {:class => "select"}
%small
= t(".language_tip")
-else
Expand Down
10 changes: 2 additions & 8 deletions app/views/users/_form.html.haml
Expand Up @@ -74,14 +74,8 @@
-if AppConfig.enable_i18n
.field
= f.label :preferred_languages, t(:preferred_languages, :scope => "activerecord.attributes.user"), :class => "label"
= link_to t('.show_more_lang'), nil, :class => 'show-more-lang'
-AVAILABLE_LANGUAGES.sort.each do |lang|
- (DEFAULT_USER_LANGUAGES.include? lang)? jsclass = '' : jsclass = 'jshide'
#lang_opts
.radio_option{:id=>language_desc(lang)}
= check_box_tag "user[preferred_languages][]", lang, @user.preferred_languages.include?(lang), :class => "langbox checkbox #{jsclass}"
%label.radio.langbox{:class=>jsclass}
= language_desc(lang)
= text_field_tag :preferred_languages, preferred_languages_code(@user, 'preferred_languages').join(','), :class => "text_field autocomplete_for_tags", 'data-opts'=> "{\"allowNewTags\": false, \"source\":#{language_json}}"

-else
= hidden_field_tag "user[preferred_languages][]", (current_group.language || AppConfig.default_language)

Expand Down
2 changes: 1 addition & 1 deletion config/deploy.rb
Expand Up @@ -18,7 +18,7 @@
assets.compass
assets.package

magent.restart
#magent.restart
bluepill.restart
end
end
Expand Down
22 changes: 22 additions & 0 deletions config/initializers/patches.rb
Expand Up @@ -14,3 +14,25 @@ def lock_with_hack
alias_method :lock_without_hack, :lock
alias_method :lock, :lock_with_hack
end

# patch for Omniauth::Facebook to be able to use the group credentials
OmniAuth.config.path_prefix = "/users/auth"
module OmniAuth
module Strategies
class Facebook
def call!(env)
host = env["HTTP_HOST"].split(':').first

if (group = Group.where(:domain => host).only(:share).first) && group.share.fb_app_id.present? && group.share.fb_secret_key.present?
self.client_id = group.share.fb_app_id
self.client_secret = group.share.fb_secret_key

Rails.logger.info "Using custom keys for #{group.name} (app_id=#{self.client_id})"
end

super
end
end
end
end

2 changes: 1 addition & 1 deletion config/locales/global/en.yml
Expand Up @@ -68,7 +68,7 @@ en:
feed: Feed
post_new_questions: Post new questions to
share_on_twitter: "Twitter, Facebook and more..."
languages:
preferred_languages:
any: Any
user: My preferred languages
number:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/groups/en.yml
@@ -1,5 +1,7 @@
en:
groups:
top_grouplist:
active_site: "Active site:"
index:
title: Groups
description: This is the list of public groups that have been created. Use the search input below to filter groups. You can also %{link}.
Expand Down
7 changes: 6 additions & 1 deletion config/locales/invitations/en.yml
@@ -1,7 +1,11 @@
en:
invitations:
resend:
flash_notice: "Your invitation has been resent successfully."
revoke:
flash_notice: "Your invitation has been revoked successfully."
create:
flash_notice: Your invitations were sent successfully
flash_notice: "Your invitations were sent successfully."
accept:
welcome: Welcome
description: %{group} is an ever improving collection of questions and answers about any topic.
Expand All @@ -20,3 +24,4 @@ en:
follow_things: Follow Tags and People
follow_things_description: Questions related to these will appear on your feed.
done: 'Done!'

3 changes: 3 additions & 0 deletions config/locales/manage/en.yml
Expand Up @@ -41,6 +41,9 @@ en:
user_role: "Invite users as"
invite: Invite people
invitations: Sent invitations
invitations:
revoke_button: "Revoke"
resend_button: "Resend"
post_to_twitter:
post_to_twitter: Post activities to Twitter
send_questions_to_twitter: Send all questions to Twitter
Expand Down
4 changes: 2 additions & 2 deletions config/locales/users/en.yml
Expand Up @@ -43,9 +43,9 @@ en:
sort_by: 'Sort by:'
edit_profile: Edit profile
follow:
flash_notice: "The user %{user} was added to your friends"
flash_notice: "You are now following %{user}."
unfollow:
flash_notice: "The user %{user} was removed from your friends"
flash_notice: "You are not following %{user} anymore."
update_followed_tags:
followed:
flash_notice: "You are now following the tag %{tag}."
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -158,6 +158,7 @@
resources :invitations do
member do
post :revoke
post :resend
end
end

Expand Down

0 comments on commit 6b51351

Please sign in to comment.