Commit 82444d712dc1db03bd3133a316a31f786fd1ad1d
Exists in
staging
and in
1 other branch
Merge branch 'master' into staging
Showing
12 changed files
with
62 additions
and
26 deletions
Show diff stats
app/api/helpers.rb
| @@ -447,12 +447,12 @@ module Api | @@ -447,12 +447,12 @@ module Api | ||
| 447 | end | 447 | end |
| 448 | 448 | ||
| 449 | def asset_with_image params | 449 | def asset_with_image params |
| 450 | - if params.has_key? :image_builder | 450 | + if !params.nil? && params.has_key?(:image_builder) |
| 451 | asset_api_params = params | 451 | asset_api_params = params |
| 452 | asset_api_params[:image_builder] = base64_to_uploadedfile(asset_api_params[:image_builder]) | 452 | asset_api_params[:image_builder] = base64_to_uploadedfile(asset_api_params[:image_builder]) |
| 453 | return asset_api_params | 453 | return asset_api_params |
| 454 | end | 454 | end |
| 455 | - params | 455 | + params |
| 456 | end | 456 | end |
| 457 | 457 | ||
| 458 | def base64_to_uploadedfile(base64_image) | 458 | def base64_to_uploadedfile(base64_image) |
app/api/v1/profiles.rb
| @@ -28,7 +28,7 @@ module Api | @@ -28,7 +28,7 @@ module Api | ||
| 28 | authenticate! | 28 | authenticate! |
| 29 | profile = environment.profiles.find_by(id: params[:id]) | 29 | profile = environment.profiles.find_by(id: params[:id]) |
| 30 | return forbidden! unless profile.allow_edit?(current_person) | 30 | return forbidden! unless profile.allow_edit?(current_person) |
| 31 | - profile.update_attributes!(params[:profile]) | 31 | + profile.update_attributes!(asset_with_image(params[:profile])) |
| 32 | present profile, :with => Entities::Profile, :current_person => current_person | 32 | present profile, :with => Entities::Profile, :current_person => current_person |
| 33 | end | 33 | end |
| 34 | 34 |
app/models/organization.rb
| @@ -20,33 +20,28 @@ class Organization < Profile | @@ -20,33 +20,28 @@ class Organization < Profile | ||
| 20 | # visible. | 20 | # visible. |
| 21 | # 4) The user is not a member of the organization but the organization is | 21 | # 4) The user is not a member of the organization but the organization is |
| 22 | # visible, public and enabled. | 22 | # visible, public and enabled. |
| 23 | - def self.listed_for_person(person) | 23 | + scope :listed_for_person, lambda { |person| |
| 24 | + | ||
| 24 | joins('LEFT JOIN "role_assignments" ON ("role_assignments"."resource_id" = "profiles"."id" | 25 | joins('LEFT JOIN "role_assignments" ON ("role_assignments"."resource_id" = "profiles"."id" |
| 25 | AND "role_assignments"."resource_type" = \'Profile\') OR ( | 26 | AND "role_assignments"."resource_type" = \'Profile\') OR ( |
| 26 | "role_assignments"."resource_id" = "profiles"."environment_id" AND | 27 | "role_assignments"."resource_id" = "profiles"."environment_id" AND |
| 27 | "role_assignments"."resource_type" = \'Environment\' )') | 28 | "role_assignments"."resource_type" = \'Environment\' )') |
| 28 | .joins('LEFT JOIN "roles" ON "role_assignments"."role_id" = "roles"."id"') | 29 | .joins('LEFT JOIN "roles" ON "role_assignments"."role_id" = "roles"."id"') |
| 29 | .where( | 30 | .where( |
| 30 | - ['( (roles.key = ? OR roles.key = ?) AND role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) | ||
| 31 | - OR | ||
| 32 | - ( ( ( role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR | ||
| 33 | - ( profiles.enabled = ? ) ) AND | ||
| 34 | - ( profiles.visible = ? ) )', | ||
| 35 | - 'profile_admin', 'environment_administrator', Profile.name, person.id, | ||
| 36 | - Profile.name, person.id, true, true] | ||
| 37 | - ).uniq | ||
| 38 | - end | ||
| 39 | - | ||
| 40 | - def self.visible_for_person(person) | ||
| 41 | - listed_for_person(person).where( | ||
| 42 | - ['( (roles.key = ? OR roles.key = ?) AND role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) | ||
| 43 | - OR | 31 | + ['( (roles.key = ? OR roles.key = ?) AND role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR ( |
| 32 | + ( ( role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR ( profiles.enabled = ?)) AND (profiles.visible = ?) )', | ||
| 33 | + 'profile_admin', 'environment_administrator', Profile.name, person.id, Profile.name, person.id, true, true] | ||
| 34 | + ).uniq | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + scope :visible_for_person, lambda { |person| | ||
| 38 | + listed_for_person(person).where( [' | ||
| 44 | ( ( role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR | 39 | ( ( role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR |
| 45 | - ( profiles.enabled = ? AND profiles.public_profile = ? ) )', | ||
| 46 | - 'profile_admin', 'environment_administrator', Profile.name, person.id, | 40 | + ( profiles.enabled = ? AND profiles.public_profile = ? ) )', |
| 47 | Profile.name, person.id, true, true] | 41 | Profile.name, person.id, true, true] |
| 48 | ) | 42 | ) |
| 49 | - end | 43 | + } |
| 44 | + | ||
| 50 | 45 | ||
| 51 | settings_items :closed, :type => :boolean, :default => false | 46 | settings_items :closed, :type => :boolean, :default => false |
| 52 | def closed? | 47 | def closed? |
plugins/community_track/views/blocks/_track.html.erb
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | <div class="lead"> | 5 | <div class="lead"> |
| 6 | <h3><%= link_to track.name, track.url %></h3> | 6 | <h3><%= link_to track.name, track.url %></h3> |
| 7 | <div class="content"> | 7 | <div class="content"> |
| 8 | - <%= track.lead %> | 8 | + <%= track.lead.html_safe %> |
| 9 | </div> | 9 | </div> |
| 10 | </div> | 10 | </div> |
| 11 | <div class="steps"> | 11 | <div class="steps"> |
plugins/community_track/views/content_viewer/_step_item.html.erb
| @@ -10,7 +10,7 @@ | @@ -10,7 +10,7 @@ | ||
| 10 | <%= status_description(step_item) %> | 10 | <%= status_description(step_item) %> |
| 11 | </div> | 11 | </div> |
| 12 | <div class="name"><span class="tool_icon button with-text icon-new icon-new<%= step_item.tool_class.icon_name if step_item.tool_class %>"></span> <%= step_item.name %></div> | 12 | <div class="name"><span class="tool_icon button with-text icon-new icon-new<%= step_item.tool_class.icon_name if step_item.tool_class %>"></span> <%= step_item.name %></div> |
| 13 | - <div class="lead"><%= step_item.body %></div> | 13 | + <div class="lead"><%= step_item.body.html_safe %></div> |
| 14 | <div class="tools"> | 14 | <div class="tools"> |
| 15 | <% if step_item.tool %> | 15 | <% if step_item.tool %> |
| 16 | <%= _('Tool: ') %> | 16 | <%= _('Tool: ') %> |
plugins/community_track/views/content_viewer/step.html.erb
| @@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
| 7 | </ul> | 7 | </ul> |
| 8 | </div> | 8 | </div> |
| 9 | <div> | 9 | <div> |
| 10 | - <%= step.body %> | 10 | + <%= step.body.html_safe %> |
| 11 | </div> | 11 | </div> |
| 12 | <% if step.allow_create?(user) && !step.tool && step.tool_class %> | 12 | <% if step.allow_create?(user) && !step.tool && step.tool_class %> |
| 13 | <h3><%= _("Tool") %></h3> | 13 | <h3><%= _("Tool") %></h3> |
plugins/community_track/views/content_viewer/track.html.erb
| @@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
| 3 | <%= form_tag({:controller => 'community_track_plugin_myprofile', :action => 'save_order', :track => track}) do %> | 3 | <%= form_tag({:controller => 'community_track_plugin_myprofile', :action => 'save_order', :track => track}) do %> |
| 4 | <div id="track"> | 4 | <div id="track"> |
| 5 | <div> | 5 | <div> |
| 6 | - <%= track.body %> | 6 | + <%= track.body.html_safe %> |
| 7 | </div> | 7 | </div> |
| 8 | 8 | ||
| 9 | <h3><%= _("Steps") %></h3> | 9 | <h3><%= _("Steps") %></h3> |
plugins/organization_ratings/views/shared/_user_rating_container.html.erb
| @@ -31,7 +31,7 @@ | @@ -31,7 +31,7 @@ | ||
| 31 | <p class="comment-body"> <%= user_rate.comment.body %> </p> | 31 | <p class="comment-body"> <%= user_rate.comment.body %> </p> |
| 32 | <% elsif user && user.is_admin? %> | 32 | <% elsif user && user.is_admin? %> |
| 33 | <% rating_task = CreateOrganizationRatingComment.with_rating(user_rate) %> | 33 | <% rating_task = CreateOrganizationRatingComment.with_rating(user_rate) %> |
| 34 | - <p class="comment-body"> <%= rating_task.body %> </p> | 34 | + <p class="comment-body"> <%= rating_task.body if rating_task.respond_to?(:body) %> </p> |
| 35 | <% end %> | 35 | <% end %> |
| 36 | </div> | 36 | </div> |
| 37 | <%= @plugins.dispatch(:organization_ratings_plugin_container_extra_fields, user_rate).collect { |content| instance_exec(&content) }.join("") %> | 37 | <%= @plugins.dispatch(:organization_ratings_plugin_container_extra_fields, user_rate).collect { |content| instance_exec(&content) }.join("") %> |
| @@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
| 1 | +require_relative '../config/environment' | ||
| 2 | +require 'rspec/rails' | ||
| 3 | + | ||
| 4 | +require_relative 'support/factories' | ||
| 5 | + | ||
| 6 | +require 'database_cleaner' | ||
| 7 | + | ||
| 8 | +RSpec.configure do |config| | ||
| 9 | + | ||
| 10 | + config.fixture_path = 'spec/fixtures' | ||
| 11 | + | ||
| 12 | + config.include Noosfero::Factory | ||
| 13 | + | ||
| 14 | + config.before(:suite) do | ||
| 15 | + DatabaseCleaner.strategy = :truncation | ||
| 16 | + DatabaseCleaner.clean_with :truncation | ||
| 17 | + end | ||
| 18 | + config.around(:each) do |example| | ||
| 19 | + DatabaseCleaner.cleaning do | ||
| 20 | + example.run | ||
| 21 | + end | ||
| 22 | + end | ||
| 23 | + | ||
| 24 | +end | ||
| 25 | + |
test/api/profiles_test.rb
| @@ -218,4 +218,18 @@ class ProfilesTest < ActiveSupport::TestCase | @@ -218,4 +218,18 @@ class ProfilesTest < ActiveSupport::TestCase | ||
| 218 | json = JSON.parse(last_response.body) | 218 | json = JSON.parse(last_response.body) |
| 219 | assert_includes json["permissions"], 'allow_post_content' | 219 | assert_includes json["permissions"], 'allow_post_content' |
| 220 | end | 220 | end |
| 221 | + | ||
| 222 | + should 'update profile image' do | ||
| 223 | + login_api | ||
| 224 | + community = fast_create(Community) | ||
| 225 | + community.add_member(person) | ||
| 226 | + base64_image = create_base64_image | ||
| 227 | + params.merge!({profile: {image_builder: base64_image}}) | ||
| 228 | + assert_nil person.image | ||
| 229 | + post "/api/v1/profiles/#{community.id}?#{params.to_query}" | ||
| 230 | + community.reload | ||
| 231 | + assert_not_nil community.image | ||
| 232 | + assert_equal community.image.filename, base64_image[:filename] | ||
| 233 | + end | ||
| 234 | + | ||
| 221 | end | 235 | end |