[Git][noosfero/noosfero][master] 14 commits: Allowes newsletter access on public_access_restriction plugin
Rodrigo Souto
gitlab at mg.gitlab.com
Mon Sep 24 17:11:20 BRT 2018
Rodrigo Souto pushed to branch master at Noosfero / noosfero
Commits:
171d586a by MatheusRich at 2018-09-04T12:37:05Z
Allowes newsletter access on public_access_restriction plugin
Signed-off-by: alaxalves <alaxallves at gmail.com>
- - - - -
01f8e997 by alaxalves at 2018-09-04T13:25:43Z
Adding test to ensure newsletter access to unlogged users
Signed-off-by: MatheusRich <matheusrichardt at gmail.com>
- - - - -
9a0eaccc by Alax Alves at 2018-09-08T00:08:52Z
Including profile validation for access restriction
Signed-off-by: Matheus Richard <matheusrichardt at gmail.com>
- - - - -
30feac03 by Matheus Richard at 2018-09-13T00:52:12Z
Fixes default environment plugins
- - - - -
67448e65 by Matheus Richard at 2018-09-13T13:34:20Z
Requiring Newsletter Plugin in Public Access Plugin
Signed-off-by: Alax Alves <alaxallves at gmail.com>
- - - - -
b0b7febc by MatheusRich at 2018-09-14T12:52:14Z
Allowes newsletter access on public_access_restriction plugin
Signed-off-by: alaxalves <alaxallves at gmail.com>
- - - - -
75150ef2 by alaxalves at 2018-09-14T12:52:14Z
Adding test to ensure newsletter access to unlogged users
Signed-off-by: MatheusRich <matheusrichardt at gmail.com>
- - - - -
a4f9fac4 by Alax Alves at 2018-09-14T12:52:14Z
Including profile validation for access restriction
Signed-off-by: Matheus Richard <matheusrichardt at gmail.com>
- - - - -
45875faa by Matheus Richard at 2018-09-14T12:52:14Z
Fixes default environment plugins
- - - - -
c3bcd6c3 by Matheus Richard at 2018-09-14T12:52:14Z
Adding test to Public Access Plugin
Signed-off-by: Alax Alves <alaxallves at gmail.com>
- - - - -
474c148c by Alax Alves at 2018-09-17T13:50:13Z
Merge branch 'master' of https://gitlab.com/noosfero/noosfero into newsletter-access
- - - - -
97f76600 by Alax Alves at 2018-09-17T14:14:53Z
Merge branch 'newsletter-access' of https://gitlab.com/MatheusRichard/noosfero into newsletter-access
- - - - -
7e496e72 by Rodrigo Souto at 2018-09-24T20:10:35Z
members-block: fix background test steps
- - - - -
90f9eafd by Rodrigo Souto at 2018-09-24T20:11:08Z
Merge branch 'MatheusRichard/noosfero-newsletter-access'
- - - - -
4 changed files:
- app/models/environment.rb
- features/members_block.feature
- plugins/public_access_restriction/lib/public_access_restriction_plugin.rb
- plugins/public_access_restriction/test/unit/public_access_restriction_test.rb
Changes:
=====================================
app/models/environment.rb
=====================================
@@ -344,7 +344,7 @@ class Environment < ApplicationRecord
openstreetmap.org
] + ('a' .. 'z').map{|i| "#{i}.yimg.com"}
- settings_items :enabled_plugins, :type => Array, :default => Noosfero::Plugin.available_plugin_names
+ settings_items :enabled_plugins, :type => Array, :default => Noosfero::Plugin.all
settings_items :search_hints, :type => Hash, :default => {}
=====================================
features/members_block.feature
=====================================
@@ -8,21 +8,15 @@ Feature:
| login | name |
| joaosilva | Joao Silva |
| mariasilva | Maria Silva |
- And the following communities
+
+ Scenario: a user can join in a community by members block's button
+ Given the following communities
| owner | identifier | name |
| joaosilva | sample-community | Sample Community |
And the following blocks
- | owner | type |
- | sample-community | MembersBlock |
- And I am logged in as "joaosilva"
- And I go to sample-community's control panel
- And I follow "Blocks" within "#section-design"
- And I follow "Edit" within ".members-block"
- And I check "Show join leave button"
- And I press "Save"
-
- Scenario: a user can join in a community by members block's button
- Given I am logged in as "mariasilva"
+ | owner | type | show_join_leave_button |
+ | sample-community | MembersBlock | true |
+ And I am logged in as "mariasilva"
And I go to sample-community's homepage
When I follow "Join this community" within ".members-block"
And I go to mariasilva's control panel
@@ -30,17 +24,24 @@ Feature:
Then I should see "Sample Community"
Scenario: a not logged in user can log in by members block's button
- Given I am not logged in
+ Given the following communities
+ | owner | identifier | name |
+ | joaosilva | sample-community | Sample Community |
+ And the following blocks
+ | owner | type | show_join_leave_button |
+ | sample-community | MembersBlock | true |
+ And I am not logged in
When I go to sample-community's homepage
And I follow "Join this community" within ".members-block"
Then I should see "Username / Email"
Scenario: the join-leave button do not appear if the checkbox show-join-leave-button is not checked
- And I go to sample-community's control panel
- And I follow "Blocks" within "#section-design"
- And I follow "Edit" within ".members-block"
- And I uncheck "Show join leave button"
- And I press "Save"
+ Given the following communities
+ | owner | identifier | name |
+ | joaosilva | sample-community | Sample Community |
+ And the following blocks
+ | owner | type | show_join_leave_button |
+ | sample-community | MembersBlock | false |
When I go to sample-community's homepage
Then I should not see "Join this community" within ".members-block"
And I should not see "Leave community" within ".members-block"
=====================================
plugins/public_access_restriction/lib/public_access_restriction_plugin.rb
=====================================
@@ -23,7 +23,8 @@ class PublicAccessRestrictionPlugin < Noosfero::Plugin
params['controller'] == 'national_regions' ||
params['controller'] == 'public_access_restriction_plugin_public_page' ||
linked_on_portal_news(environment, params, profile) ||
- show_newsletter(environment, profile)
+ show_newsletter?(environment, profile) ||
+ newsletter_mail?(environment, params)
)
end
@@ -67,10 +68,25 @@ class PublicAccessRestrictionPlugin < Noosfero::Plugin
where(reference_article_id: article.id).first.present?
end
- def show_newsletter environment, profile
+ def show_newsletter? environment, profile
if environment.enabled_plugins.include?("NewsletterPlugin")
newsletter = NewsletterPlugin::Newsletter.find_by(environment: environment.id)
- newsletter.blogs.find_by(profile: profile)
+ on_newsletter = params['controller'] == 'newsletter_plugin' && params['action'] == 'mailing'
+ on_newsletter_blog = false
+
+ if newsletter
+ on_newsletter_blog = newsletter.blogs.find_by(profile: profile)
+ end
+
+ on_newsletter || on_newsletter_blog
+ else
+ false
+ end
+ end
+
+ def newsletter_mail? environment, params
+ if environment.enabled_plugins.include?("NewsletterPlugin")
+ params['controller'] == 'newsletter_plugin' && params['action'] == 'mailing'
end
end
=====================================
plugins/public_access_restriction/test/unit/public_access_restriction_test.rb
=====================================
@@ -13,41 +13,51 @@ class PublicAccessRestrictionPluginTest < ActiveSupport::TestCase
should 'not block a common authenticated user' do
user = fast_create Person
profile = fast_create Community
- assert ! @plugin.should_block?(user, @env, {}, nil)
- assert ! @plugin.should_block?(user, @env, {controller:'any'}, profile)
- assert ! @plugin.should_block?(user, @env, {controller:'account'}, nil)
- assert ! @plugin.should_block?(user, @env, {controller:'home'}, nil)
+ assert_not @plugin.should_block?(user, @env, {}, nil)
+ assert_not @plugin.should_block?(user, @env, {controller:'any'}, profile)
+ assert_not @plugin.should_block?(user, @env, {controller:'account'}, nil)
+ assert_not @plugin.should_block?(user, @env, {controller:'home'}, nil)
end
- should 'block a unauthenticated user on most controllers' do
+ should 'block an unauthenticated user on most controllers' do
user = nil
profile = fast_create Community
assert @plugin.should_block?(user, @env, {controller:'some'}, nil)
assert @plugin.should_block?(user, @env, {controller:'some'}, profile)
end
- should 'not block a unauthenticated user on home controller' do
+ should 'not block an unauthenticated user on home controller' do
user = nil
- assert ! @plugin.should_block?(user, @env, {controller:'home'}, nil)
+ assert_not @plugin.should_block?(user, @env, {controller:'home'}, nil)
end
- should 'not block a unauthenticated user on portal profile' do
+ should 'not block an unauthenticated user on portal profile' do
user = nil
profile = fast_create Community
@env.stubs(:is_portal_community?).returns(profile)
- assert ! @plugin.should_block?(user, @env, {controller:'some'}, profile)
- assert ! @plugin.should_block?(user, @env, {controller:'content_viewer',
+ assert_not @plugin.should_block?(user, @env, {controller:'some'}, profile)
+ assert_not @plugin.should_block?(user, @env, {controller:'content_viewer',
action:'view_page', profile:profile.identifier, page:'some'}, nil)
end
+
+ should 'not block an unauthenticated user on newsletter' do
+ @env.enable_plugin('NewsletterPlugin')
+
+ params = { "controller" => "newsletter_plugin", "action" => "mailing" }
+ wrong_params = { "controller" => "newsletter_plugin", "action" => "other_action" }
+
+ assert @plugin.send(:newsletter_mail?, @env, params)
+ refute @plugin.send(:newsletter_mail?, @env, wrong_params)
+ end
- should 'not block a unauthenticated user on account controller' do
+ should 'not block an unauthenticated user on account controller' do
user = nil
- assert ! @plugin.should_block?(user, @env, {controller:'account'}, nil)
+ assert_not @plugin.should_block?(user, @env, {controller:'account'}, nil)
end
- should 'not block a unauthenticated user on public_access_restriction plugin public_page controller' do
+ should 'not block an unauthenticated user on public_access_restriction plugin public_page controller' do
user = nil
- assert ! @plugin.should_block?(user, @env, {controller:'public_access_restriction_plugin_public_page'}, nil)
+ assert_not @plugin.should_block?(user, @env, {controller:'public_access_restriction_plugin_public_page'}, nil)
end
should 'display public page if profile says so' do
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/35d29105592f273727a5a4f79c4fdca3f2665d81...90f9eafd8d71960d989183c631bb425566412804
--
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/35d29105592f273727a5a4f79c4fdca3f2665d81...90f9eafd8d71960d989183c631bb425566412804
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20180924/f6deb596/attachment-0001.html>
More information about the Noosfero-dev
mailing list