Add ability to change default asciicast visibility (public/private)
This commit is contained in:
parent
453d5c75a8
commit
c671a9ca8d
@ -120,3 +120,6 @@ kbd
|
||||
border-radius: 3px
|
||||
border: 1px solid #CCC
|
||||
margin: 0 1px
|
||||
|
||||
label.radio
|
||||
font-weight: normal
|
||||
|
@ -21,7 +21,7 @@ class UsersController < ApplicationController
|
||||
|
||||
def update
|
||||
authorize current_user
|
||||
user = User.find(current_user.id)
|
||||
@user = User.find(current_user.id)
|
||||
|
||||
if user.update_attributes(update_params)
|
||||
redirect_to profile_path(user), notice: 'Account settings saved.'
|
||||
@ -33,7 +33,7 @@ class UsersController < ApplicationController
|
||||
private
|
||||
|
||||
def update_params
|
||||
params.require(:user).permit(:username, :name, :email, :theme_name)
|
||||
params.require(:user).permit(*policy(user).permitted_attributes)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -6,6 +6,13 @@ class UserPolicy < ApplicationPolicy
|
||||
end
|
||||
end
|
||||
|
||||
def permitted_attributes
|
||||
attrs = [:username, :name, :email, :theme_name]
|
||||
attrs << :asciicasts_private_by_default if record.supporter?
|
||||
|
||||
attrs
|
||||
end
|
||||
|
||||
def update?
|
||||
record == user
|
||||
end
|
||||
|
@ -18,6 +18,10 @@ class UserEditPagePresenter
|
||||
!active_tokens.empty? || !revoked_tokens.empty?
|
||||
end
|
||||
|
||||
def show_privacy_controls?
|
||||
user.supporter?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sort(tokens)
|
||||
|
@ -7,7 +7,9 @@
|
||||
= f.input :username
|
||||
= f.input :email, required: true
|
||||
= f.input :name, label: 'Full name'
|
||||
= f.input :theme_name, label: 'Terminal theme', collection: themes_for_select, include_blank: default_user_theme_label, hint: 'Used for all recordings unless custom theme chosen for a specific recording'
|
||||
= f.input :theme_name, label: 'Terminal theme', collection: themes_for_select, include_blank: default_user_theme_label, hint: 'Applies to all your asciicasts unless custom theme chosen for a specific asciicast'
|
||||
- if page.show_privacy_controls?
|
||||
= f.input :asciicasts_private_by_default, label: 'Asciicast visibility', as: :radio_buttons, collection: [['public', false], ['private', true]], hint: 'Applies to all *new* asciicasts'
|
||||
= f.buttons do
|
||||
= f.button :submit, 'Save', class: 'btn-primary'
|
||||
= link_to 'Cancel', profile_path(current_user), class: 'btn'
|
||||
|
@ -4,6 +4,24 @@ describe UserPolicy do
|
||||
|
||||
subject { described_class }
|
||||
|
||||
describe '#permitted_attributes' do
|
||||
subject { Pundit.policy(user, user).permitted_attributes }
|
||||
|
||||
let(:user) { User.new }
|
||||
|
||||
it "includes basic form fields" do
|
||||
expect(subject).to eq([:username, :name, :email, :theme_name])
|
||||
end
|
||||
|
||||
context "when user is a supporter" do
|
||||
let(:user) { stub_model(User, supporter?: true) }
|
||||
|
||||
it "also includes asciicasts_private_by_default" do
|
||||
expect(subject).to eq([:username, :name, :email, :theme_name, :asciicasts_private_by_default])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
permissions :update? do
|
||||
it "grants access if edited user is current user" do
|
||||
user = User.new
|
||||
|
Loading…
Reference in New Issue
Block a user