Permalink
Browse files

Implemented :translator role whereby a user is allowed access only to…

… update pages that not the default frontend locale.
  • Loading branch information...
1 parent 8da92bc commit 4beff8e899b9406208ef5ef1776788cac36f3ca8 @parndt parndt committed May 10, 2011
@@ -5,32 +5,37 @@ def login
click_button("submit_button")
end
-Given /^I am a logged in refinery user$/ do
+Given /^I am a logged in refinery user$/i do
@user ||= Factory(:refinery_user)
login
end
-Given /^I am a logged in customer$/ do
+Given /^I am a logged in refinery translator$/i do
+ @user ||= Factory(:refinery_translator)
+ login
+end
+
+Given /^I am a logged in customer$/i do
@user ||= Factory(:user)
login
end
-Given /^A Refinery user exists$/ do
+Given /^A Refinery user exists$/i do
@refinery_user ||= Factory(:refinery_user)
end
Given /^I have a user named "(.*)"$/ do |name|
Factory(:user, :username => name)
end
-Given /^I have a R|refinery user named "(.*)"$/ do |name|
+Given /^I have a refinery user named "(.*)"$/i do |name|
Factory(:refinery_user, :username => name)
end
-Given /^I have no users$/ do
+Given /^I have no users$/i do
User.delete_all
end
-Then /^I should have ([0-9]+) users?$/ do |count|
+Then /^I should have ([0-9]+) users?$/i do |count|
User.count.should == count.to_i
end
@@ -16,3 +16,11 @@
end
end
end
+
+Factory.define :refinery_translator, :parent => :user do |u|
+ u.roles { [ Role[:refinery], Role[:translator] ] }
+
+ u.after_create do |user|
+ user.plugins.create(:name => 'refinery_pages', :position => 0)
+ end
+end
@@ -11,6 +11,10 @@ class PagesController < Admin::BaseController
after_filter lambda{::Page.expire_page_caching}, :only => [:update_positions]
+ before_filter :restrict_access, :only => [:create, :update, :update_positions, :destroy], :if => proc {|c|
+ defined?(::Refinery::I18n) && ::Refinery::I18n.enabled?
+ }
+
def new
@page = Page.new
Page.default_parts.each_with_index do |page_part, index|
@@ -28,8 +32,8 @@ def globalize!
# Check whether we need to override e.g. on the pages form.
unless params[:switch_locale] || @page.nil? || @page.new_record? || @page.slugs.where({
- :locale => Refinery::I18n.current_locale}
- ).nil?
+ :locale => Refinery::I18n.current_locale
+ }).nil?
@page.slug = @page.slugs.first if @page.slug.nil? && @page.slugs.any?
Thread.current[:globalize_locale] = @page.slug.locale if @page.slug
end
@@ -50,5 +54,15 @@ def show_errors_for_reserved_slug(exception)
end
end
+ def restrict_access
+ if current_user.has_role?(:translator) && !current_user.has_role?(:superuser) &&
+ (params[:switch_locale].blank? || params[:switch_locale] == ::Refinery::I18n.default_frontend_locale.to_s)
+ flash[:error] = t('translator_access', :scope => 'admin.pages')
+ redirect_to :action => 'index' and return
+ end
+
+ return true
+ end
+
end
end
@@ -77,6 +77,7 @@ en:
reorder_pages_done: Done reordering pages
records:
no_pages_yet: There are no pages yet. Click "Add new page" to add your first page.
+ translator_access: You do not have the required permission to modify pages in this language.
activerecord:
models:
page: page
@@ -45,3 +45,4 @@ Feature: Manage Pages
Then I should see "'test' was successfully removed."
And I should have 0 pages
And I should have 0 page_parts
+
@@ -50,3 +50,7 @@
Then /^I should have (\d+) page_parts$/ do |count|
PagePart.count.should == count.to_i
end
+
+Given /^I have frontend locales "?([^\"]*)"?/ do |locales|
+ RefinerySetting.set(:i18n_translation_frontend_locales, {:value => locales.split(', '), :scoping => 'refinery'})
+end
@@ -0,0 +1,40 @@
+@refinerycms @pages @pages-translate @i18n
+Feature: Translate Pages
+ In order to make the content on my website accessible in many countries
+ As a translator
+ I want to translate manage pages
+
+ Background:
+ Given A Refinery user exists
+ And I am a logged in Refinery Translator
+ And I have pages titled Home, About
+
+ Scenario: Pages List
+ When I go to the list of pages
+ Then I should see "Home"
+ And I should see "About"
+
+ Scenario: Add page to main locale
+ When I go to the list of pages
+ And I follow "Add new page"
+ And I fill in "Title" with "Pickles are Cucumbers Soaked in Evil"
+ And I press "Save"
+ Then I should see "You do not have the required permission to modify pages in this language"
+ And I should have 2 pages
+
+ Scenario: Add page to second locale
+ Given I have frontend locales en, fr
+ When I go to the list of pages
+ And I follow "Add new page"
+ And I follow "Fr" within "#switch_locale_picker"
+ And I fill in "Title" with "Pickles sont Concombres Trempé dans le Mal"
+ And I press "Save"
+ Then I should see "'Pickles sont Concombres Trempé dans le Mal' was successfully added."
+ And I should have 3 pages
+
+ Scenario: Delete page from main locale
+ Given I only have a page titled "test"
+ When I go to the list of pages
+ And I follow "Remove this page forever"
+ Then I should see "You do not have the required permission to modify pages in this language."
+ And I should have 1 pages

0 comments on commit 4beff8e

Please sign in to comment.