Commit c1cdaf45ae654275295d99c7e56e9f796fc83680
1 parent
6eb736e0
Exists in
fix_sign_up_form
Not allow a regular person to choose raw html editor
Showing
3 changed files
with
45 additions
and
1 deletions
Show diff stats
app/helpers/profile_editor_helper.rb
... | ... | @@ -159,7 +159,7 @@ module ProfileEditorHelper |
159 | 159 | end |
160 | 160 | |
161 | 161 | def select_editor(title, object, method, options) |
162 | - labelled_form_field(title, select(object, method,[[_('TinyMCE'), Article::Editor::TINY_MCE], [_('Textile'), Article::Editor::TEXTILE], [_('Raw HTML'), Article::Editor::RAW_HTML]])) | |
162 | + labelled_form_field(title, select(object, method, current_person.available_editors.map { |k,v| [v, k] })) | |
163 | 163 | end |
164 | 164 | |
165 | 165 | end | ... | ... |
app/models/person.rb
... | ... | @@ -341,6 +341,8 @@ class Person < Profile |
341 | 341 | |
342 | 342 | validates_associated :user |
343 | 343 | |
344 | + validates :editor, inclusion: { in: lambda { |p| p.available_editors } } | |
345 | + | |
344 | 346 | def email |
345 | 347 | self.user.nil? ? nil : self.user.email |
346 | 348 | end |
... | ... | @@ -621,4 +623,13 @@ class Person < Profile |
621 | 623 | self.is_a_friend?(person) || super |
622 | 624 | end |
623 | 625 | |
626 | + def available_editors | |
627 | + available_editors = { | |
628 | + Article::Editor::TINY_MCE => _('TinyMCE'), | |
629 | + Article::Editor::TEXTILE => _('Textile') | |
630 | + } | |
631 | + available_editors.merge!({Article::Editor::RAW_HTML => _('Raw HTML')}) if self.is_admin? | |
632 | + available_editors | |
633 | + end | |
634 | + | |
624 | 635 | end | ... | ... |
test/unit/person_test.rb
... | ... | @@ -2006,4 +2006,37 @@ class PersonTest < ActiveSupport::TestCase |
2006 | 2006 | assert_equivalent [circle2], ProfileFollower.with_profile(community).with_follower(person).map(&:circle) |
2007 | 2007 | end |
2008 | 2008 | |
2009 | + should 'list available editors for a regular person' do | |
2010 | + person = Person.new | |
2011 | + person.expects(:is_admin?).returns(false) | |
2012 | + assert_equivalent [Article::Editor::TINY_MCE, Article::Editor::TEXTILE], person.available_editors.keys | |
2013 | + end | |
2014 | + | |
2015 | + should 'list available editors for an admin' do | |
2016 | + person = Person.new | |
2017 | + person.expects(:is_admin?).returns(true) | |
2018 | + assert_equivalent [Article::Editor::TINY_MCE, Article::Editor::TEXTILE, Article::Editor::RAW_HTML], person.available_editors.keys | |
2019 | + end | |
2020 | + | |
2021 | + should 'not save a person with an inexistent editor' do | |
2022 | + person = create_user('testuser').person | |
2023 | + person.editor = "bli" | |
2024 | + assert !person.save | |
2025 | + assert person.errors['editor'].present? | |
2026 | + end | |
2027 | + | |
2028 | + should 'not allow a regular person to change to raw_html editor' do | |
2029 | + person = create_user('testuser').person | |
2030 | + person.editor = Article::Editor::RAW_HTML | |
2031 | + assert !person.save | |
2032 | + assert person.errors['editor'].present? | |
2033 | + end | |
2034 | + | |
2035 | + should 'allow admin to change to raw_html editor' do | |
2036 | + person = create_user('testuser').person | |
2037 | + person.environment.add_admin(person) | |
2038 | + person.editor = Article::Editor::RAW_HTML | |
2039 | + assert person.save | |
2040 | + end | |
2041 | + | |
2009 | 2042 | end | ... | ... |