Commit 39a3f520965a4e58174e439f818550e12de8e14f
1 parent
732a29a0
Exists in
staging
and in
32 other branches
Adds custom_fields details to moderation tasks
Uses custom fields for create community moderation Uses custom fields for user creation moderation Signed-off-by: Alexandre Barbosa <alexandreab@live.com> Signed-off-by: Arthur Jahn <stutrzbecher@gmail.com> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
Showing
14 changed files
with
100 additions
and
5 deletions
Show diff stats
app/controllers/my_profile/tasks_controller.rb
@@ -4,6 +4,7 @@ class TasksController < MyProfileController | @@ -4,6 +4,7 @@ class TasksController < MyProfileController | ||
4 | 4 | ||
5 | protect [:perform_task, :view_tasks], :profile, :only => [:index] | 5 | protect [:perform_task, :view_tasks], :profile, :only => [:index] |
6 | protect :perform_task, :profile, :except => [:index] | 6 | protect :perform_task, :profile, :except => [:index] |
7 | + helper CustomFieldsHelper | ||
7 | 8 | ||
8 | def index | 9 | def index |
9 | @filter_type = params[:filter_type].presence | 10 | @filter_type = params[:filter_type].presence |
app/helpers/custom_fields_helper.rb
@@ -37,8 +37,15 @@ module CustomFieldsHelper | @@ -37,8 +37,15 @@ module CustomFieldsHelper | ||
37 | end | 37 | end |
38 | 38 | ||
39 | def display_custom_field_value(custom_field_value) | 39 | def display_custom_field_value(custom_field_value) |
40 | - value = profile.custom_value(custom_field_value.custom_field.name) | ||
41 | - case custom_field_value.custom_field.format | 40 | + value_for_format custom_field_value.custom_field.format, custom_field_value.value |
41 | + end | ||
42 | + | ||
43 | + def display_value_for_custom_field(custom_field, value) | ||
44 | + value_for_format custom_field.format, value | ||
45 | + end | ||
46 | + | ||
47 | + def value_for_format format, value | ||
48 | + case format | ||
42 | when 'text', 'list', 'numeric', 'date', 'string' | 49 | when 'text', 'list', 'numeric', 'date', 'string' |
43 | value | 50 | value |
44 | when 'checkbox' | 51 | when 'checkbox' |
@@ -47,6 +54,7 @@ module CustomFieldsHelper | @@ -47,6 +54,7 @@ module CustomFieldsHelper | ||
47 | url = value[/\Ahttps?:\/\//i] ? value : "http://#{value}" | 54 | url = value[/\Ahttps?:\/\//i] ? value : "http://#{value}" |
48 | link_to(value, url, :target => '_blank') | 55 | link_to(value, url, :target => '_blank') |
49 | end | 56 | end |
57 | + | ||
50 | end | 58 | end |
51 | 59 | ||
52 | private | 60 | private |
app/models/community.rb
@@ -33,7 +33,7 @@ class Community < Organization | @@ -33,7 +33,7 @@ class Community < Organization | ||
33 | community = Community.new(attributes) | 33 | community = Community.new(attributes) |
34 | community.environment = environment | 34 | community.environment = environment |
35 | if community.environment.enabled?('admin_must_approve_new_communities') | 35 | if community.environment.enabled?('admin_must_approve_new_communities') |
36 | - CreateCommunity.create!(attributes.merge(:requestor => requestor, :environment => environment).except(:custom_values)) | 36 | + CreateCommunity.create!(attributes.merge(:requestor => requestor, :environment => environment)) |
37 | else | 37 | else |
38 | community.save! | 38 | community.save! |
39 | community.add_admin(requestor) | 39 | community.add_admin(requestor) |
app/models/create_community.rb
@@ -20,6 +20,9 @@ class CreateCommunity < Task | @@ -20,6 +20,9 @@ class CreateCommunity < Task | ||
20 | attr_accessible field.to_sym | 20 | attr_accessible field.to_sym |
21 | end | 21 | end |
22 | 22 | ||
23 | + settings_items :custom_values | ||
24 | + attr_accessible :custom_values | ||
25 | + | ||
23 | def validate | 26 | def validate |
24 | self.environment.required_community_fields.each do |field| | 27 | self.environment.required_community_fields.each do |field| |
25 | if self.send(field).blank? | 28 | if self.send(field).blank? |
@@ -36,6 +39,7 @@ class CreateCommunity < Task | @@ -36,6 +39,7 @@ class CreateCommunity < Task | ||
36 | 39 | ||
37 | community.update(community_data) | 40 | community.update(community_data) |
38 | community.image = image if image | 41 | community.image = image if image |
42 | + community.custom_values = custom_values | ||
39 | community.environment = self.environment | 43 | community.environment = self.environment |
40 | community.save! | 44 | community.save! |
41 | community.add_admin(self.requestor) | 45 | community.add_admin(self.requestor) |
@@ -67,6 +71,10 @@ class CreateCommunity < Task | @@ -67,6 +71,10 @@ class CreateCommunity < Task | ||
67 | true | 71 | true |
68 | end | 72 | end |
69 | 73 | ||
74 | + def custom_fields_moderate | ||
75 | + true | ||
76 | + end | ||
77 | + | ||
70 | # tells if this request was rejected | 78 | # tells if this request was rejected |
71 | def rejected? | 79 | def rejected? |
72 | self.status == Task::Status::CANCELLED | 80 | self.status == Task::Status::CANCELLED |
app/models/custom_field.rb
1 | class CustomField < ActiveRecord::Base | 1 | class CustomField < ActiveRecord::Base |
2 | - attr_accessible :name, :default_value, :format, :extras, :customized_type, :active, :required, :signup, :environment | 2 | + attr_accessible :name, :default_value, :format, :extras, :customized_type, :active, :required, :signup, :environment, :moderation_task |
3 | serialize :customized_type | 3 | serialize :customized_type |
4 | serialize :extras | 4 | serialize :extras |
5 | has_many :custom_field_values, :dependent => :delete_all | 5 | has_many :custom_field_values, :dependent => :delete_all |
app/models/moderate_user_registration.rb
@@ -22,6 +22,10 @@ class ModerateUserRegistration < Task | @@ -22,6 +22,10 @@ class ModerateUserRegistration < Task | ||
22 | "#{name} (#{email})" | 22 | "#{name} (#{email})" |
23 | end | 23 | end |
24 | 24 | ||
25 | + def custom_fields_moderate | ||
26 | + true | ||
27 | + end | ||
28 | + | ||
25 | def perform | 29 | def perform |
26 | user=environment.users.find_by_id(user_id) | 30 | user=environment.users.find_by_id(user_id) |
27 | user.activate | 31 | user.activate |
@@ -58,4 +62,4 @@ class ModerateUserRegistration < Task | @@ -58,4 +62,4 @@ class ModerateUserRegistration < Task | ||
58 | _("User \"%{user}\" just requested to register. You have to approve or reject it through the \"Pending Validations\" section in your control panel.\n") % { :user => self.name } | 62 | _("User \"%{user}\" just requested to register. You have to approve or reject it through the \"Pending Validations\" section in your control panel.\n") % { :user => self.name } |
59 | end | 63 | end |
60 | 64 | ||
61 | -end | ||
62 | \ No newline at end of file | 65 | \ No newline at end of file |
66 | +end |
app/models/task.rb
@@ -182,6 +182,10 @@ class Task < ActiveRecord::Base | @@ -182,6 +182,10 @@ class Task < ActiveRecord::Base | ||
182 | false | 182 | false |
183 | end | 183 | end |
184 | 184 | ||
185 | + def custom_fields_moderate | ||
186 | + false | ||
187 | + end | ||
188 | + | ||
185 | def icon | 189 | def icon |
186 | {:type => :defined_image, :src => "/images/icons-app/user-minor.png", :name => requestor.name, :url => requestor.url} | 190 | {:type => :defined_image, :src => "/images/icons-app/user-minor.png", :name => requestor.name, :url => requestor.url} |
187 | end | 191 | end |
app/views/features/custom_fields/_form.html.erb
@@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
16 | <%= labelled_check_box _('Active'), "custom_fields[#{id}][active]", 1, field.active, :id => "active_checkbox", :onclick => "active_action('custom_fields[#{id}][active]','custom_fields[#{id}][required]', 'custom_fields[#{id}][signup]')" %> | 16 | <%= labelled_check_box _('Active'), "custom_fields[#{id}][active]", 1, field.active, :id => "active_checkbox", :onclick => "active_action('custom_fields[#{id}][active]','custom_fields[#{id}][required]', 'custom_fields[#{id}][signup]')" %> |
17 | <%= labelled_check_box _('Required'), "custom_fields[#{id}][required]", 1, field.required, :id => "required_checkbox", :onclick => "required_action('custom_fields[#{id}][active]','custom_fields[#{id}][required]', 'custom_fields[#{id}][signup]')" %> | 17 | <%= labelled_check_box _('Required'), "custom_fields[#{id}][required]", 1, field.required, :id => "required_checkbox", :onclick => "required_action('custom_fields[#{id}][active]','custom_fields[#{id}][required]', 'custom_fields[#{id}][signup]')" %> |
18 | <%= labelled_check_box _('Display on creation?'), "custom_fields[#{id}][signup]", 1, field.signup, :id => "signup_checkbox",:onclick => "signup_action('custom_fields[#{id}][active]','custom_fields[#{id}][required]', 'custom_fields[#{id}][signup]')" %> | 18 | <%= labelled_check_box _('Display on creation?'), "custom_fields[#{id}][signup]", 1, field.signup, :id => "signup_checkbox",:onclick => "signup_action('custom_fields[#{id}][active]','custom_fields[#{id}][required]', 'custom_fields[#{id}][signup]')" %> |
19 | + <%= labelled_check_box _('Display on moderation?'), "custom_fields[#{id}][moderation_task]", 1, field.moderation_task %> | ||
19 | </div> | 20 | </div> |
20 | 21 | ||
21 | <% if field.format == "list" %> | 22 | <% if field.format == "list" %> |
app/views/tasks/_create_community_custom_fields.html.erb
0 → 100644
@@ -0,0 +1,10 @@ | @@ -0,0 +1,10 @@ | ||
1 | +<% if task.custom_values.present? %> | ||
2 | + <% task.custom_values.each_pair do |name, value| %> | ||
3 | + <% custom_field = CustomField.where(:name =>name, :environment => task.environment).first%> | ||
4 | + <% if custom_field.moderation_task %> | ||
5 | + <div class="field-name"> | ||
6 | + <%= name +": " + display_value_for_custom_field(custom_field, value['value']) %> | ||
7 | + </div> | ||
8 | + <% end %> | ||
9 | + <% end %> | ||
10 | +<% end %> |
app/views/tasks/_moderate_user_registration_custom_fields.html.erb
0 → 100644
@@ -0,0 +1,7 @@ | @@ -0,0 +1,7 @@ | ||
1 | +<% task.requestor.custom_field_values.each do |custom_value| %> | ||
2 | + <% if custom_value.custom_field.moderation_task %> | ||
3 | + <div class="field-name"> | ||
4 | + <%= custom_value.custom_field.name + ": " + display_custom_field_value(custom_value) %> | ||
5 | + </div> | ||
6 | + <% end %> | ||
7 | +<% end %> |
app/views/tasks/_task.html.erb
@@ -51,6 +51,12 @@ | @@ -51,6 +51,12 @@ | ||
51 | </div> | 51 | </div> |
52 | 52 | ||
53 | <%= fields_for "tasks[#{task.id}][task]", task do |f| %> | 53 | <%= fields_for "tasks[#{task.id}][task]", task do |f| %> |
54 | + <% if task.custom_fields_moderate %> | ||
55 | + <div id="custom-field-information-<%=task.id%>" style="display: none"> | ||
56 | + <%= render :partial => task.class.name.underscore+'_custom_fields', :locals => {:task => task} %> | ||
57 | + </div> | ||
58 | + <% end %> | ||
59 | + | ||
54 | <% if task.accept_details %> | 60 | <% if task.accept_details %> |
55 | <div id="on-accept-information-<%=task.id%>" style="display: none"> | 61 | <div id="on-accept-information-<%=task.id%>" style="display: none"> |
56 | <%= render :partial => partial_for_class(task.class, nil, :accept_details), :locals => {:task => task, :f => f} %> | 62 | <%= render :partial => partial_for_class(task.class, nil, :accept_details), :locals => {:task => task, :f => f} %> |
db/migrate/20160324132518_add_moderation_task_to_custom_field.rb
0 → 100644
public/javascripts/tasks.js
@@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
5 | $('#on-accept-information-' + task_id).show('fast'); | 5 | $('#on-accept-information-' + task_id).show('fast'); |
6 | $('#on-reject-information-' + task_id).hide('fast'); | 6 | $('#on-reject-information-' + task_id).hide('fast'); |
7 | $('#on-skip-information-' + task_id).hide('fast'); | 7 | $('#on-skip-information-' + task_id).hide('fast'); |
8 | + $('#custom-field-information-' + task_id).show('fast'); | ||
8 | }) | 9 | }) |
9 | 10 | ||
10 | $("input.task_reject_radio").click(function(){ | 11 | $("input.task_reject_radio").click(function(){ |
@@ -12,6 +13,7 @@ | @@ -12,6 +13,7 @@ | ||
12 | $('#on-accept-information-' + task_id).hide('fast'); | 13 | $('#on-accept-information-' + task_id).hide('fast'); |
13 | $('#on-reject-information-' + task_id).show('fast'); | 14 | $('#on-reject-information-' + task_id).show('fast'); |
14 | $('#on-skip-information-' + task_id).hide('fast'); | 15 | $('#on-skip-information-' + task_id).hide('fast'); |
16 | + $('#custom-field-information-' + task_id).show('fast'); | ||
15 | }) | 17 | }) |
16 | 18 | ||
17 | $("input.task_skip_radio").click(function(){ | 19 | $("input.task_skip_radio").click(function(){ |
@@ -19,6 +21,7 @@ | @@ -19,6 +21,7 @@ | ||
19 | $('#on-accept-information-' + task_id).hide('fast'); | 21 | $('#on-accept-information-' + task_id).hide('fast'); |
20 | $('#on-reject-information-' + task_id).hide('fast'); | 22 | $('#on-reject-information-' + task_id).hide('fast'); |
21 | $('#on-skip-information-' + task_id).show('fast'); | 23 | $('#on-skip-information-' + task_id).show('fast'); |
24 | + $('#custom-field-information-' + task_id).hide('fast'); | ||
22 | }) | 25 | }) |
23 | 26 | ||
24 | // There is probably an elegant way to do this... | 27 | // There is probably an elegant way to do this... |
test/functional/tasks_controller_test.rb
@@ -670,4 +670,38 @@ class TasksControllerTest < ActionController::TestCase | @@ -670,4 +670,38 @@ class TasksControllerTest < ActionController::TestCase | ||
670 | assert_equal profile, t.reload.closed_by | 670 | assert_equal profile, t.reload.closed_by |
671 | end | 671 | end |
672 | 672 | ||
673 | + should 'list custom field details in moderation user tasks when moderation_tasks is true' do | ||
674 | + person_custom_field = CustomField.create(:name => "great_field", :format=>"string", :default_value => "value for person", :customized_type=>"Person", :active => true, :environment => Environment.default, :moderation_task => true, :required => true) | ||
675 | + p1 = create_user("great_person").person | ||
676 | + p1.custom_values = {"great_field" => "new_value!"} | ||
677 | + p1.save! | ||
678 | + p1.reload | ||
679 | + admin = create_user("admin").person | ||
680 | + Environment.default.add_admin(admin) | ||
681 | + @controller.stubs(:profile).returns(admin) | ||
682 | + login_as "admin" | ||
683 | + | ||
684 | + ModerateUserRegistration.create!(:requestor => p1, :name => "great_person", :email => "alo@alo.alo", :target => Environment.default) | ||
685 | + | ||
686 | + get :index | ||
687 | + | ||
688 | + assert_tag :tag=> 'div', :attributes => { :class => 'field-name' }, :content => /great_field: new_value!/ | ||
689 | + end | ||
690 | + | ||
691 | + should 'list custom field details in moderation of community creation tasks when moderation_tasks is true' do | ||
692 | + community_custom_field = CustomField.create(:name => "great_field", :format=>"string", :default_value => "value for community", :customized_type=>"Community", :active => true, :environment => Environment.default, :moderation_task => true, :required => true) | ||
693 | + p1 = create_user("great_person").person | ||
694 | + p1.save! | ||
695 | + admin = create_user("admin").person | ||
696 | + Environment.default.add_admin(admin) | ||
697 | + @controller.stubs(:profile).returns(admin) | ||
698 | + login_as "admin" | ||
699 | + | ||
700 | + CreateCommunity.create!(:requestor => p1, :name => "great_community", :target => Environment.default, :custom_values => {"great_field" => {"value" => "new value for community!"}}) | ||
701 | + | ||
702 | + get :index | ||
703 | + | ||
704 | + assert_tag :tag=> 'div', :attributes => { :class => 'field-name' }, :content => /great_field: new value for community!/ | ||
705 | + end | ||
706 | + | ||
673 | end | 707 | end |