give students full wiki privileges within groups, closes #4611

Change-Id: Ib902203c1b39bb1bc1b2d333ebd7713746326216
Reviewed-on: https://gerrit.instructure.com/3850
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Zach Wily <zach@instructure.com>
This commit is contained in:
Jon Jensen 2011-05-25 10:38:32 -06:00
parent 00f4fe6e92
commit af13294b29
5 changed files with 81 additions and 4 deletions

View File

@ -268,7 +268,8 @@ class Group < ActiveRecord::Base
can :send_messages and can :create_conferences and can :send_messages and can :create_conferences and
can :create_collaborations and can :read_roster and can :create_collaborations and can :read_roster and
can :manage_calendar and can :manage_calendar and
can :update and can :delete and can :create } can :update and can :delete and can :create and
can :manage_wiki }
given { |user| user && self.invited_users.include?(user) } given { |user| user && self.invited_users.include?(user) }
set { can :read } set { can :read }

View File

@ -223,9 +223,6 @@ class WikiPage < ActiveRecord::Base
given {|user, session| self.current_namespace(user).grants_right?(user, session, :contribute) && can_read_page?(user) } given {|user, session| self.current_namespace(user).grants_right?(user, session, :contribute) && can_read_page?(user) }
set { can :read } set { can :read }
given {|user, session| self.editing_role?(user) && !self.locked_for?(nil, user) }
set { can :read }
given {|user, session| self.editing_role?(user) && !self.locked_for?(nil, user) } given {|user, session| self.editing_role?(user) && !self.locked_for?(nil, user) }
set { can :read and can :update_content and can :create } set { can :read and can :update_content and can :create }

View File

@ -155,6 +155,15 @@ describe WikiPagesController do
assigns[:page].should_not be_new_record assigns[:page].should_not be_new_record
assigns[:page].title.should eql("Some Great Page") assigns[:page].title.should eql("Some Great Page")
end end
it "should allow users to create a page" do
group_with_user_logged_in(:active_all => true)
post 'create', :group_id => @group.id, :wiki_page => {:title => "Some Great Page"}
response.should be_redirect
assigns[:page].should_not be_nil
assigns[:page].should_not be_new_record
assigns[:page].title.should eql("Some Great Page")
end
end end
describe "PUT 'update'" do describe "PUT 'update'" do
@ -178,6 +187,21 @@ describe WikiPagesController do
assigns[:page].should_not be_nil assigns[:page].should_not be_nil
assigns[:page].title.should eql("New Name") assigns[:page].title.should eql("New Name")
end end
it "should allow users to update a page" do
group_with_user_logged_in(:active_all => true)
@group.wiki.wiki_pages.create!(:title => 'Test')
put 'update', :group_id => @group.id, :id => @group.wiki.wiki_pages.first.url, :wiki_page => {:title => "Some Great Page"}
response.should be_redirect
assigns[:page].should_not be_nil
assigns[:page].title.should eql("Some Great Page")
page = assigns[:page]
put 'update', :group_id => @group.id, :id => page.url, :wiki_page => {:title => "New Name"}
response.should be_redirect
assigns[:page].should_not be_nil
assigns[:page].title.should eql("New Name")
end
end end
describe "DELETE 'destroy'" do describe "DELETE 'destroy'" do
@ -208,6 +232,17 @@ describe WikiPagesController do
assigns[:page].should be_deleted #frozen assigns[:page].should be_deleted #frozen
@course.wiki.wiki_pages.should be_include(page) @course.wiki.wiki_pages.should be_include(page)
end end
it "should allow users to delete a page" do
group_with_user_logged_in(:active_all => true)
page = @group.wiki.wiki_pages.create(:title => "a page")
page.save!
delete 'destroy', :group_id => @group.id, :id => page.url
response.should be_redirect
assigns[:page].should eql(page)
assigns[:page].should be_deleted #frozen
@group.wiki.wiki_pages.should be_include(page)
end
end end
end end

View File

@ -152,6 +152,12 @@ Spec::Runner.configure do |config|
def group_with_user(opts={}) def group_with_user(opts={})
group(opts) group(opts)
user(opts) user(opts)
@group.participating_users << @user
end
def group_with_user_logged_in(opts={})
group_with_user(opts)
user_session(@user)
end end
def user_session(user, pseudonym=nil) def user_session(user, pseudonym=nil)

View File

@ -0,0 +1,38 @@
#
# Copyright (C) 2011 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')
describe "/wiki_pages/_wiki_right_side" do
it "should render" do
group_with_user
view_context
page = @group.wiki.wiki_pages.create(:title => "a page")
assigns[:wiki] = @group.wiki
assigns[:page] = page
assigns[:page].save!
assigns[:context] = @group
render :partial => "wiki_pages/wiki_right_side"
response.should_not be_nil
response.body.should match(/Edit this Page/)
response.body.should match(/Delete this Page/)
response.body.should match(/Create a New Page/)
end
end