From 0a4c20a420745aa30f7fb7760063716aa228bff1 Mon Sep 17 00:00:00 2001 From: Luciano Prestes Cavalcanti Date: Mon, 2 Mar 2015 15:17:06 -0300 Subject: [PATCH] Create profile editor page for software community into plugin --- lib/ext/profile_editor_controller.rb | 40 ++++++++++++++++++++++++++++++++++++++++ test/functional/profile_editor_controller_test.rb | 28 ++++++++++++++++++++++++++++ views/profile_editor/edit_software_community.html.erb | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 0 deletions(-) create mode 100644 lib/ext/profile_editor_controller.rb create mode 100644 views/profile_editor/edit_software_community.html.erb diff --git a/lib/ext/profile_editor_controller.rb b/lib/ext/profile_editor_controller.rb new file mode 100644 index 0000000..1972764 --- /dev/null +++ b/lib/ext/profile_editor_controller.rb @@ -0,0 +1,40 @@ +require_dependency 'profile_editor_controller' + +class ProfileEditorController + + before_filter :redirect_to_edit_software_community, :only => [:edit] + + def edit_software_community + @profile_data = profile + @possible_domains = profile.possible_domains + + edit_community_post_actions if request.post? + end + + protected + + + def redirect_to_edit_software_community + if profile.class == Community && profile.software? + redirect_to :action => 'edit_software_community' + end + end + + def edit_community_post_actions + params[:profile_data][:fields_privacy] ||= {} if profile.person? && params[:profile_data].is_a?(Hash) + + Profile.transaction do + Image.transaction do + begin + @plugins.dispatch(:profile_editor_transaction_extras) + @profile_data.update_attributes!(params[:profile_data]) + + redirect_to :action => 'index', :profile => profile.identifier + rescue Exception => ex + profile.identifier = params[:profile] if profile.identifier.blank? + end + end + end + end + +end diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index a9a9b7c..4bc694d 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -92,6 +92,15 @@ class ProfileEditorControllerTest < ActionController::TestCase assert_equal 0, User.last.institutions.count end + should "redirect to edit_software_community on edit community of software" do + software = create_software_info("Test Software") + + post :edit, :profile => software.community.identifier + + assert_redirected_to :controller => 'profile_editor', :action => 'edit_software_community' + end + + protected def create_basic_user @@ -102,4 +111,23 @@ class ProfileEditorControllerTest < ActionController::TestCase user.person.save! user end + + def create_community name + community = fast_create(Community) + community.name = name + community.save + community + end + + def create_software_info name, finality = "", acronym = "" + community = create_community(name) + software_info = SoftwareInfo.new + software_info.community = community + software_info.finality = finality + software_info.acronym = acronym + software_info.public_software = true + software_info.save + software_info + end + end diff --git a/views/profile_editor/edit_software_community.html.erb b/views/profile_editor/edit_software_community.html.erb new file mode 100644 index 0000000..1727f0b --- /dev/null +++ b/views/profile_editor/edit_software_community.html.erb @@ -0,0 +1,88 @@ +

<%= _('Configure Community') %>

+ +<%= javascript_include_tag 'deactivate_profile' %> +<%= error_messages_for :profile_data %> + +<%= labelled_form_for :profile_data, :html => { :id => 'profile-data', :multipart => true } do |f| %> + + <% if user.has_permission?('manage_environment_templates', profile.environment) %> +
+ <%= labelled_check_box(_('This profile is a template'), 'profile_data[is_template]', true, @profile.is_template) %> +
+ <% end %> + + <%= render :partial => partial_for_class(@profile.class), :locals => { :f => f } %> + +
+

<%= _('Change picture') %>

+ <%= unchangeable_privacy_field @profile %> +
+
+ <%= f.fields_for :image_builder, @profile.image do |i| %> + <%= file_field_or_thumbnail(_('Image:'), @profile.image, i) %><%= _("Max size: %s (.jpg, .gif, .png)")% Image.max_size.to_humanreadable %> + <% end %> +
+ +

<%= _('Privacy options') %>

+ + <% if profile.person? %> +
+ <%= labelled_radio_button _('Public — show my contents to all internet users'), 'profile_data[public_profile]', true, @profile.public_profile? %> +
+
+ <%= labelled_radio_button _('Private — show my contents only to friends'), 'profile_data[public_profile]', false, !@profile.public_profile? %> +
+ <% else %> +
+ <%= labelled_radio_button _('Public — show content of this group to all internet users'), 'profile_data[public_profile]', true, @profile.public_profile? %> +
+
+ <%= labelled_radio_button _('Private — show content of this group only to members'), 'profile_data[public_profile]', false, !@profile.public_profile? %> +
+ <% end %> + + <% if environment.enabled?('allow_change_of_redirection_after_login') %> +

<%= _('Page to redirect after login') %>

+ <%= select 'profile_data', 'redirection_after_login', Environment.login_redirection_options.map{|key,value|[value,key]}, { :selected => @profile.preferred_login_redirection} %> + <% end %> + +

<%= _('Translations') %>

+ <%= labelled_check_box( + _('Automaticaly redirect the visitor to the article translated to his/her language'), + 'profile_data[redirect_l10n]', true, @profile.redirect_l10n + )%> + +

<%= _('Suggestions') %>

+ <%= labelled_check_box( + _('Send me relationship suggestions by email'), + 'profile_data[email_suggestions]', true, @profile.email_suggestions + )%> + + <%= + @plugins.dispatch(:profile_editor_extras).map do |content| + content.kind_of?(Proc) ? self.instance_exec(&content) : content + end.join("\n") + %> + + <%= select_categories(:profile_data, _('Select the categories of your interest'), 2) %> + + <% button_bar do %> + <%= submit_button('save', _('Save'), :cancel => {:action => 'index'}) %> + <%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %> + <% end %> + + <% if user && user.has_permission?('destroy_profile', profile) %> + <% button_bar(:id => 'delete-profile') do %> + <%= button(:remove, _('Delete profile'), {:action => :destroy_profile}) %> + + <% if environment.admins.include?(current_person) %> + + <% if profile.visible? %> + <%= button(:remove, _('Deactivate profile'), {:action => :deactivate_profile, :id=>profile.id}, :id=>'deactivate_profile_button', :data => {:confirm=>_("Are you sure you want to deactivate this profile?")}) %> + <% else %> + <%= button(:add, _('Activate profile'), {:action => :activate_profile, :id=>profile.id}, :data => {:confirm=>_("Are you sure you want to deactivate this profile?")}) %> + <% end %> + <% end %> + <% end %> + <% end %> +<% end %> \ No newline at end of file -- libgit2 0.21.2