Skip to content

Commit

Permalink
Add a preference to control profile visibility.
Browse files Browse the repository at this point in the history
Refs #316, but the hiding still needs to be implemented.
  • Loading branch information
gravitystorm committed Apr 17, 2014
1 parent 544bffc commit 5eac5b5
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/models/user_pref.rb
Expand Up @@ -19,12 +19,14 @@
#

class UserPref < ActiveRecord::Base
attr_accessible :involve_my_locations, :involve_my_groups, :involve_my_groups_admin, :enable_email
attr_accessible :involve_my_locations, :involve_my_groups, :involve_my_groups_admin, :enable_email, :profile_visibility

belongs_to :user

INVOLVEMENT_OPTIONS = %w(none notify subscribe)
PROFILE_OPTIONS = %w(public group)

validates :involve_my_locations, inclusion: { in: INVOLVEMENT_OPTIONS }
validates :involve_my_groups, inclusion: { in: INVOLVEMENT_OPTIONS }
validates :profile_visibility, inclusion: { in: PROFILE_OPTIONS }
end
5 changes: 5 additions & 0 deletions app/views/user/prefs/edit.html.haml
Expand Up @@ -15,4 +15,9 @@
%h2= t ".notification_types"
%p= t ".notification_types_guidance"
= f.input :enable_email
%h2= t ".profile"
%p= t ".profile_guidance_html", profile_link: link_to(t(".your_profile"), user_profile_path(current_user))
= f.input :profile_visibility,
as: :radio,
collection: UserPref::PROFILE_OPTIONS.map {|n| [t(".profile_#{n}"), n] }
= f.actions
5 changes: 5 additions & 0 deletions config/locales/en-GB.yml
Expand Up @@ -857,6 +857,11 @@
none: "No notifications"
notify: "Notify me of new issues and when new threads are started"
subscribe: "Notify me of new issues and automatically follow all new threads"
profile: "Profile visibility"
profile_guidance_html: "You can choose to restrict who gets to view %{profile_link}."
your_profile: "your profile"
profile_public: "Everyone"
profile_group: "Only members in my groups"
update:
success: "Preferences saved"
failure: "Your preferences could not be saved"
Expand Down
@@ -0,0 +1,5 @@
class AddProfileOptionsToUserPrefs < ActiveRecord::Migration
def change
add_column :user_prefs, :profile_visibility, :string, default: 'public', null: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20140326164405) do
ActiveRecord::Schema.define(:version => 20140403150540) do

create_table "deadline_messages", :force => true do |t|
t.integer "thread_id", :null => false
Expand Down Expand Up @@ -287,6 +287,7 @@
t.string "involve_my_groups", :default => "notify", :null => false
t.boolean "involve_my_groups_admin", :default => false, :null => false
t.boolean "enable_email", :default => false, :null => false
t.string "profile_visibility", :default => "public", :null => false
end

add_index "user_prefs", ["enable_email"], :name => "index_user_prefs_on_enable_email"
Expand Down
1 change: 1 addition & 0 deletions spec/models/user_pref_spec.rb
Expand Up @@ -38,6 +38,7 @@
strings = %w(
involve_my_locations
involve_my_groups
profile_visibility
)

strings.each do |attr|
Expand Down
22 changes: 22 additions & 0 deletions spec/requests/user/prefs_spec.rb
Expand Up @@ -83,4 +83,26 @@ def get_field(name)
current_user.prefs.enable_email.should be_true
end
end

describe 'profile visibility' do
let(:field) { get_field('profile_visibility') }

it 'should default to everyone' do
within('#user_pref_profile_visibility_input') do
page.should have_checked_field(I18n.t('.user.prefs.edit.profile_public'))
end
end

it 'should change to group' do
within('#user_pref_profile_visibility_input') do
page.choose(I18n.t('.user.prefs.edit.profile_group'))
end
click_on 'Save'
within('#user_pref_profile_visibility_input') do
page.should have_checked_field(I18n.t('.user.prefs.edit.profile_group'))
end
current_user.reload
current_user.prefs.profile_visibility.should eql('group')
end
end
end

0 comments on commit 5eac5b5

Please sign in to comment.