Commit b4c10bc6c9162b1fa7f06af7044a79436d8a0632
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'stable' of gitlab.com:participa/noosfero into stable
Showing
9 changed files
with
74 additions
and
23 deletions
Show diff stats
app/models/community.rb
... | ... | @@ -50,16 +50,6 @@ class Community < Organization |
50 | 50 | super + FIELDS |
51 | 51 | end |
52 | 52 | |
53 | - validate :presence_of_required_fieds | |
54 | - | |
55 | - def presence_of_required_fieds | |
56 | - self.required_fields.each do |field| | |
57 | - if self.send(field).blank? | |
58 | - self.errors.add_on_blank(field) | |
59 | - end | |
60 | - end | |
61 | - end | |
62 | - | |
63 | 53 | def active_fields |
64 | 54 | environment ? environment.active_community_fields : [] |
65 | 55 | end | ... | ... |
app/models/enterprise.rb
... | ... | @@ -59,16 +59,6 @@ class Enterprise < Organization |
59 | 59 | super + FIELDS |
60 | 60 | end |
61 | 61 | |
62 | - validate :presence_of_required_fieds | |
63 | - | |
64 | - def presence_of_required_fieds | |
65 | - self.required_fields.each do |field| | |
66 | - if self.send(field).blank? | |
67 | - self.errors.add_on_blank(field) | |
68 | - end | |
69 | - end | |
70 | - end | |
71 | - | |
72 | 62 | def active_fields |
73 | 63 | environment ? environment.active_enterprise_fields : [] |
74 | 64 | end | ... | ... |
app/models/organization.rb
... | ... | @@ -30,6 +30,16 @@ class Organization < Profile |
30 | 30 | |
31 | 31 | scope :more_popular, :order => 'members_count DESC' |
32 | 32 | |
33 | + validate :presence_of_required_fieds, :unless => :is_template | |
34 | + | |
35 | + def presence_of_required_fieds | |
36 | + self.required_fields.each do |field| | |
37 | + if self.send(field).blank? | |
38 | + self.errors.add_on_blank(field) | |
39 | + end | |
40 | + end | |
41 | + end | |
42 | + | |
33 | 43 | def validation_methodology |
34 | 44 | self.validation_info ? self.validation_info.validation_methodology : nil |
35 | 45 | end | ... | ... |
app/models/person.rb
... | ... | @@ -161,7 +161,7 @@ class Person < Profile |
161 | 161 | FIELDS |
162 | 162 | end |
163 | 163 | |
164 | - validate :presence_of_required_fields | |
164 | + validate :presence_of_required_fields, :unless => :is_template | |
165 | 165 | |
166 | 166 | def presence_of_required_fields |
167 | 167 | self.required_fields.each do |field| | ... | ... |
plugins/proposals_discussion/controllers/public/proposals_discussion_plugin_public_controller.rb
... | ... | @@ -2,13 +2,14 @@ class ProposalsDiscussionPluginPublicController < ApplicationController |
2 | 2 | |
3 | 3 | needs_profile |
4 | 4 | |
5 | + before_filter :check_permission | |
6 | + | |
5 | 7 | def load_proposals |
6 | - @holder = profile.articles.find(params[:holder_id]) | |
7 | 8 | page = (params[:page] || 1).to_i |
8 | 9 | set_rand_cookie if page == 1 |
9 | 10 | order = params[:order] |
10 | 11 | |
11 | - @proposals = order_proposals(@holder.proposals.public, order) | |
12 | + @proposals = order_proposals(@holder.proposals.published, order) | |
12 | 13 | @proposals = @proposals.page(page).per_page(4) |
13 | 14 | |
14 | 15 | render :partial => 'content_viewer/proposals_list_content', :locals => {:proposals => @proposals, :holder => @holder, :page => page+1, :order => order} |
... | ... | @@ -16,6 +17,11 @@ class ProposalsDiscussionPluginPublicController < ApplicationController |
16 | 17 | |
17 | 18 | private |
18 | 19 | |
20 | + def check_permission | |
21 | + @holder = profile.articles.find(params[:holder_id]) | |
22 | + render_access_denied unless @holder.display_to?(user) | |
23 | + end | |
24 | + | |
19 | 25 | def order_proposals(proposals, order) |
20 | 26 | case order |
21 | 27 | when 'alphabetical' | ... | ... |
plugins/proposals_discussion/test/functional/proposals_discussion_plugin_public_controller_test.rb
... | ... | @@ -76,4 +76,23 @@ class ProposalsDiscussionPluginPublicControllerTest < ActionController::TestCase |
76 | 76 | assert_equal [proposal3, proposal1, proposal2], assigns(:proposals) |
77 | 77 | end |
78 | 78 | |
79 | + should 'load proposals when profile is private and the user is a member' do | |
80 | + person = create_user.person | |
81 | + login_as(person.identifier) | |
82 | + profile.add_member(person) | |
83 | + profile.update_attribute(:public_profile, false) | |
84 | + | |
85 | + proposals = 3.times.map { fast_create(ProposalsDiscussionPlugin::Proposal, :name => 'proposal title', :abstract => 'proposal abstract', :profile_id => profile.id, :parent_id => topic.id)} | |
86 | + get :load_proposals, :profile => profile.identifier, :holder_id => topic.id | |
87 | + assert_equivalent proposals, assigns(:proposals) | |
88 | + end | |
89 | + | |
90 | + should 'not load proposals when profile is private and user is not logged' do | |
91 | + logout | |
92 | + profile.update_attribute(:public_profile, false) | |
93 | + proposals = 3.times.map { fast_create(ProposalsDiscussionPlugin::Proposal, :name => 'proposal title', :abstract => 'proposal abstract', :profile_id => profile.id, :parent_id => topic.id)} | |
94 | + get :load_proposals, :profile => profile.identifier, :holder_id => topic.id | |
95 | + assert_equal nil, assigns(:proposals) | |
96 | + end | |
97 | + | |
79 | 98 | end | ... | ... |
test/unit/community_test.rb
... | ... | @@ -126,6 +126,18 @@ class CommunityTest < ActiveSupport::TestCase |
126 | 126 | assert ! community.errors[:contact_phone.to_s].present? |
127 | 127 | end |
128 | 128 | |
129 | + should 'not require fields if community is a template' do | |
130 | + e = Environment.default | |
131 | + e.expects(:required_community_fields).returns(['contact_phone']).at_least_once | |
132 | + community = build(Community, :name => 'My community', :environment => e) | |
133 | + assert ! community.valid? | |
134 | + assert community.errors[:contact_phone.to_s].present? | |
135 | + | |
136 | + community.is_template = true | |
137 | + community.valid? | |
138 | + assert ! community.errors[:contact_phone.to_s].present? | |
139 | + end | |
140 | + | |
129 | 141 | should 'return newest text articles as news' do |
130 | 142 | c = fast_create(Community, :name => 'test_com') |
131 | 143 | f = fast_create(Folder, :name => 'folder', :profile_id => c.id) | ... | ... |
test/unit/enterprise_test.rb
... | ... | @@ -310,6 +310,18 @@ class EnterpriseTest < ActiveSupport::TestCase |
310 | 310 | assert ! enterprise.errors[:contact_phone.to_s].present? |
311 | 311 | end |
312 | 312 | |
313 | + should 'not require fields if enterprise is a template' do | |
314 | + e = Environment.default | |
315 | + e.expects(:required_enterprise_fields).returns(['contact_phone']).at_least_once | |
316 | + enterprise = build(Enterprise, :environment => e) | |
317 | + assert ! enterprise.valid? | |
318 | + assert enterprise.errors[:contact_phone.to_s].present? | |
319 | + | |
320 | + enterprise.is_template = true | |
321 | + enterprise.valid? | |
322 | + assert ! enterprise.errors[:contact_phone.to_s].present? | |
323 | + end | |
324 | + | |
313 | 325 | should 'enable contact' do |
314 | 326 | enterprise = build(Enterprise, :enable_contact_us => false) |
315 | 327 | assert !enterprise.enable_contact? | ... | ... |
test/unit/person_test.rb
... | ... | @@ -513,6 +513,18 @@ class PersonTest < ActiveSupport::TestCase |
513 | 513 | assert ! person.errors[:custom_formation.to_s].present? |
514 | 514 | end |
515 | 515 | |
516 | + should 'not require fields if person is a template' do | |
517 | + e = Environment.default | |
518 | + e.expects(:required_person_fields).returns(['cell_phone']).at_least_once | |
519 | + person = build(Person, :environment => e) | |
520 | + assert ! person.valid? | |
521 | + assert person.errors[:cell_phone.to_s].present? | |
522 | + | |
523 | + person.is_template = true | |
524 | + person.valid? | |
525 | + assert ! person.errors[:cell_phone.to_s].present? | |
526 | + end | |
527 | + | |
516 | 528 | should 'identify when person is a friend' do |
517 | 529 | p1 = create_user('testuser1').person |
518 | 530 | p2 = create_user('testuser2').person | ... | ... |