Commit a411aeca2ee8586bd44e0161a642a90b05d72544
Committed by
Antonio Terceiro
1 parent
bf95a1cf
Exists in
master
and in
23 other branches
Can approve creation of communities with images
Adding explanation about moderation ActionItem1254
Showing
4 changed files
with
44 additions
and
4 deletions
Show diff stats
app/models/create_community.rb
| @@ -12,7 +12,9 @@ class CreateCommunity < Task | @@ -12,7 +12,9 @@ class CreateCommunity < Task | ||
| 12 | self[:data] ||= Hash.new | 12 | self[:data] ||= Hash.new |
| 13 | end | 13 | end |
| 14 | 14 | ||
| 15 | - DATA_FIELDS = Community.fields + ['name', 'closed', 'image_builder', 'tag_list'] | 15 | + acts_as_having_image |
| 16 | + | ||
| 17 | + DATA_FIELDS = Community.fields + ['name', 'closed', 'tag_list'] | ||
| 16 | 18 | ||
| 17 | DATA_FIELDS.each do |field| | 19 | DATA_FIELDS.each do |field| |
| 18 | # getter | 20 | # getter |
| @@ -40,6 +42,7 @@ class CreateCommunity < Task | @@ -40,6 +42,7 @@ class CreateCommunity < Task | ||
| 40 | end | 42 | end |
| 41 | 43 | ||
| 42 | community.update_attributes(community_data) | 44 | community.update_attributes(community_data) |
| 45 | + community.image = image if image | ||
| 43 | community.environment = self.environment | 46 | community.environment = self.environment |
| 44 | community.save! | 47 | community.save! |
| 45 | community.add_admin(self.requestor) | 48 | community.add_admin(self.requestor) |
app/views/memberships/new_community.rhtml
| @@ -4,6 +4,12 @@ | @@ -4,6 +4,12 @@ | ||
| 4 | 4 | ||
| 5 | <h1><%= __('Creating new community') %></h1> | 5 | <h1><%= __('Creating new community') %></h1> |
| 6 | 6 | ||
| 7 | +<% if environment.enabled?('admin_must_approve_new_communities') %> | ||
| 8 | + <div class='explanation'> | ||
| 9 | + <%= _("Your request for registering a community will be sent to %{environment} administrator and will be approved or rejected according to his methods and creteria.") % { :environment => environment.name }%> | ||
| 10 | + </div> | ||
| 11 | +<%end %> | ||
| 12 | + | ||
| 7 | <%= error_messages_for :community %> | 13 | <%= error_messages_for :community %> |
| 8 | 14 | ||
| 9 | <div> | 15 | <div> |
app/views/tasks/_create_community.rhtml
| @@ -14,17 +14,30 @@ | @@ -14,17 +14,30 @@ | ||
| 14 | <%= hidden_field_tag(:decision, 'cancel') %> | 14 | <%= hidden_field_tag(:decision, 'cancel') %> |
| 15 | <% else %> | 15 | <% else %> |
| 16 | <%= radio_button_tag(:decision, 'finish', true, | 16 | <%= radio_button_tag(:decision, 'finish', true, |
| 17 | - :id => "decision-finish-#{task.id}") %> | 17 | + :id => "decision-finish-#{task.id}", |
| 18 | + :onclick => "hide_closing_statement_area(#{task.id})") %> | ||
| 18 | <label for="<%= "decision-finish-#{task.id}" %>"><b><%= _('Approve') %></b></label> | 19 | <label for="<%= "decision-finish-#{task.id}" %>"><b><%= _('Approve') %></b></label> |
| 19 | 20 | ||
| 20 | | 21 | |
| 21 | 22 | ||
| 22 | <%= radio_button_tag(:decision, 'cancel', false, | 23 | <%= radio_button_tag(:decision, 'cancel', false, |
| 23 | - :id => "decision-cancel-#{task.id}") %> | 24 | + :id => "decision-cancel-#{task.id}", |
| 25 | + :onclick => "show_closing_statement_area(#{task.id})") %> | ||
| 24 | <label for="<%= "decision-cancel-#{task.id}" %>"><b><%= _('Reject') %></b></label> | 26 | <label for="<%= "decision-cancel-#{task.id}" %>"><b><%= _('Reject') %></b></label> |
| 25 | <% end %> | 27 | <% end %> |
| 26 | 28 | ||
| 29 | + <script type='text/javascript'> | ||
| 30 | + function show_closing_statement_area(id) { | ||
| 31 | + $('task-closing-statement-' + id).show(); | ||
| 32 | + } | ||
| 33 | + function hide_closing_statement_area(id) { | ||
| 34 | + $('task-closing-statement-' + id).hide(); | ||
| 35 | + } | ||
| 36 | + </script> | ||
| 37 | + | ||
| 38 | + <div style='display:none' id=<%= "task-closing-statement-#{task.id}" %> > | ||
| 27 | <%= labelled_form_field _('Please provide an explanation for the rejection'), f.text_area(:closing_statement, :style => 'height:200px; width:80%;') %> | 39 | <%= labelled_form_field _('Please provide an explanation for the rejection'), f.text_area(:closing_statement, :style => 'height:200px; width:80%;') %> |
| 40 | + </div> | ||
| 28 | 41 | ||
| 29 | </div> | 42 | </div> |
| 30 | 43 |
test/unit/create_community_test.rb
| @@ -10,7 +10,7 @@ class CreateCommunityTest < Test::Unit::TestCase | @@ -10,7 +10,7 @@ class CreateCommunityTest < Test::Unit::TestCase | ||
| 10 | should 'provide needed data' do | 10 | should 'provide needed data' do |
| 11 | task = CreateCommunity.new | 11 | task = CreateCommunity.new |
| 12 | 12 | ||
| 13 | - Community.fields + %w[ name closed image_builder tag_list ].each do |field| | 13 | + Community.fields + %w[ name closed tag_list ].each do |field| |
| 14 | assert task.respond_to?(field) | 14 | assert task.respond_to?(field) |
| 15 | assert task.respond_to?("#{field}=") | 15 | assert task.respond_to?("#{field}=") |
| 16 | end | 16 | end |
| @@ -65,4 +65,22 @@ class CreateCommunityTest < Test::Unit::TestCase | @@ -65,4 +65,22 @@ class CreateCommunityTest < Test::Unit::TestCase | ||
| 65 | request.stubs(:status).returns(Task::Status::CANCELLED) | 65 | request.stubs(:status).returns(Task::Status::CANCELLED) |
| 66 | assert request.rejected? | 66 | assert request.rejected? |
| 67 | end | 67 | end |
| 68 | + | ||
| 69 | + should 'create a community with image when finishing the task' do | ||
| 70 | + | ||
| 71 | + task = CreateCommunity.create!({ | ||
| 72 | + :name => 'My new community', | ||
| 73 | + :requestor => person, | ||
| 74 | + :target => Environment.default, | ||
| 75 | + :image_builder => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} | ||
| 76 | + }) | ||
| 77 | + | ||
| 78 | + assert_equal 'rails.png', task.image.filename | ||
| 79 | + assert_difference Community, :count do | ||
| 80 | + task.finish | ||
| 81 | + end | ||
| 82 | + | ||
| 83 | + assert_equal 'rails.png', Community['my-new-community'].image.filename | ||
| 84 | + end | ||
| 85 | + | ||
| 68 | end | 86 | end |