add a specific setting for self registration refs #2660
test plan: * a fresh account should not be able to visit /register * enable self_registration in script/console for the account (see the migration) * you should now be able to visit /register * no other changes should be visible Change-Id: Ibfd6a0d23d3c3e37243ffb762e284b8907cd45cc Reviewed-on: https://gerrit.instructure.com/16713 Reviewed-by: Cody Cutrer <cody@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com> Tested-by: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
aeb2328ccf
commit
795ac516d6
|
@ -88,7 +88,7 @@ class UsersController < ApplicationController
|
|||
before_filter :require_user, :only => [:grades, :confirm_merge, :merge, :kaltura_session, :ignore_item, :ignore_stream_item, :close_notification, :mark_avatar_image, :user_dashboard, :toggle_dashboard, :masquerade, :external_tool]
|
||||
before_filter :require_registered_user, :only => [:delete_user_service, :create_user_service]
|
||||
before_filter :reject_student_view_student, :only => [:delete_user_service, :create_user_service, :confirm_merge, :merge, :user_dashboard, :masquerade]
|
||||
before_filter :require_open_registration, :only => [:new, :create]
|
||||
before_filter :require_self_registration, :only => [:new, :create]
|
||||
|
||||
def grades
|
||||
@user = User.find_by_id(params[:user_id]) if params[:user_id].present?
|
||||
|
@ -645,14 +645,6 @@ class UsersController < ApplicationController
|
|||
|
||||
def new
|
||||
return redirect_to(root_url) if @current_user
|
||||
unless @context == Account.default && @context.no_enrollments_can_create_courses?
|
||||
# TODO: generic/brandable page, so we can up it up to non-default accounts
|
||||
# also more control so we can conditionally enable features (e.g. if
|
||||
# no_enrollments_can_create_courses==false, but open reg is on, students
|
||||
# should still be able to sign up with join codes, etc. ... we should just
|
||||
# not have the teacher button/form)
|
||||
return redirect_to(root_url)
|
||||
end
|
||||
render :layout => 'bare'
|
||||
end
|
||||
|
||||
|
@ -1140,12 +1132,12 @@ class UsersController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def require_open_registration
|
||||
def require_self_registration
|
||||
get_context
|
||||
@context = @domain_root_account || Account.default unless @context.is_a?(Account)
|
||||
@context = @context.root_account
|
||||
unless @context.grants_right?(@current_user, session, :manage_user_logins) || @context.open_registration?
|
||||
flash[:error] = t('no_open_registration', "Open registration has not been enabled for this account")
|
||||
unless @context.grants_right?(@current_user, session, :manage_user_logins) || @context.self_registration?
|
||||
flash[:error] = t('no_self_registration', "Self registration has not been enabled for this account")
|
||||
respond_to do |format|
|
||||
format.html { redirect_to root_url }
|
||||
format.json { render :json => {}, :status => 403 }
|
||||
|
@ -1160,7 +1152,7 @@ class UsersController < ApplicationController
|
|||
}
|
||||
end
|
||||
|
||||
protected :require_open_registration
|
||||
protected :require_self_registration
|
||||
|
||||
def teacher_activity
|
||||
@teacher = User.find(params[:user_id])
|
||||
|
|
|
@ -164,6 +164,7 @@ class Account < ActiveRecord::Base
|
|||
# be nice to be able to see the course first if you weren't expecting the
|
||||
# invitation.
|
||||
add_setting :allow_invitation_previews, :boolean => true, :root_only => true, :default => false
|
||||
add_setting :self_registration, :boolean => true, :root_only => true, :default => false
|
||||
|
||||
def settings=(hash)
|
||||
if hash.is_a?(Hash)
|
||||
|
@ -219,6 +220,10 @@ class Account < ActiveRecord::Base
|
|||
!!settings[:open_registration] && canvas_authentication?
|
||||
end
|
||||
|
||||
def self_registration?
|
||||
!!settings[:self_registration] && canvas_authentication?
|
||||
end
|
||||
|
||||
def ip_filters=(params)
|
||||
filters = {}
|
||||
require 'ipaddr'
|
||||
|
|
|
@ -309,7 +309,7 @@ class AccountAuthorizationConfig < ActiveRecord::Base
|
|||
|
||||
def disable_open_registration_if_delegated
|
||||
if self.delegated_authentication? && self.account.open_registration?
|
||||
@account.settings = { :open_registration => false }
|
||||
@account.settings = { :open_registration => false, :self_registration => false }
|
||||
@account.save!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
<% else %>
|
||||
<% if @current_user %>
|
||||
<%= render :partial => 'confirm_enrollments' %>
|
||||
<% elsif @domain_root_account.open_registration? %>
|
||||
<% elsif @domain_root_account.self_registration? %>
|
||||
<%= render :partial => 'authenticate_or_register' %>
|
||||
<% else %>
|
||||
<%= render :partial => 'authenticate' %>
|
||||
|
|
|
@ -90,7 +90,7 @@ $(document).ready(function() {
|
|||
</div>
|
||||
<% else %>
|
||||
<% form_for :pseudonym_session, :url => login_path(:nonldap => (@domain_root_account && !@domain_root_account.ldap_authentication?).presence), :html => {:id => "login_form"} do |f| %>
|
||||
<%= link_to t("register_for_canvas", "*Need a Canvas Account?* **Click Here, It's Free!**", :wrapper => {'*' => '<i>\1</i>', '**' => '<b>\1</b>'}), Setting.get_cached("registration_link", "/register_from_website"), :id => 'register_link', :class => 'not_external' if @domain_root_account == Account.default && @domain_root_account.open_registration? && @domain_root_account.no_enrollments_can_create_courses? && !hide_fft %>
|
||||
<%= link_to t("register_for_canvas", "*Need a Canvas Account?* **Click Here, It's Free!**", :wrapper => {'*' => '<i>\1</i>', '**' => '<b>\1</b>'}), Setting.get_cached("registration_link", "/register_from_website"), :id => 'register_link', :class => 'not_external' if @domain_root_account.self_registration? && !hide_fft %>
|
||||
<h2 class="ui-helper-hidden-accessible"><%= t('log_in', 'Log In') %></h2>
|
||||
<% login_inner_dialog = yield :login_inner_dialog %>
|
||||
<%= login_inner_dialog if login_inner_dialog && !login_inner_dialog.strip.empty? %>
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
class GrandfatherDefaultAccountSelfRegistration < ActiveRecord::Migration
|
||||
# yes, predeploy, so that the setting is preserved before the new code goes live
|
||||
tag :predeploy
|
||||
|
||||
def self.up
|
||||
return unless Shard.current == Account.default.shard
|
||||
account = Account.default
|
||||
if account.no_enrollments_can_create_courses?
|
||||
account.settings[:self_registration] = true
|
||||
account.save!
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
end
|
||||
end
|
|
@ -166,15 +166,15 @@ describe UsersController do
|
|||
end
|
||||
|
||||
context "POST 'create'" do
|
||||
it "should not allow creating when open_registration is disabled and you're not an admin'" do
|
||||
it "should not allow creating when self_registration is disabled and you're not an admin'" do
|
||||
post 'create', :pseudonym => { :unique_id => 'jacob@instructure.com' }, :user => { :name => 'Jacob Fugal' }
|
||||
response.should_not be_success
|
||||
end
|
||||
|
||||
context 'open registration' do
|
||||
context 'self registration' do
|
||||
before :each do
|
||||
a = Account.default
|
||||
a.settings = { :open_registration => true, :no_enrollments_can_create_courses => true }
|
||||
a.settings = { :self_registration => true }
|
||||
a.save!
|
||||
end
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ describe "self enrollment" do
|
|||
|
||||
shared_examples_for "open registration" do
|
||||
before do
|
||||
Account.default.update_attribute(:settings, :self_enrollment => 'any', :open_registration => true)
|
||||
Account.default.update_attribute(:settings, :self_enrollment => 'any', :open_registration => true, :self_registration => true)
|
||||
course(:active_all => active_course)
|
||||
@course.update_attribute(:self_enrollment, true)
|
||||
end
|
||||
|
|
|
@ -187,7 +187,7 @@ describe "users" do
|
|||
context "registration" do
|
||||
before :each do
|
||||
a = Account.default
|
||||
a.settings = {:open_registration => true, :no_enrollments_can_create_courses => true}
|
||||
a.settings = {:self_registration => true}
|
||||
a.save!
|
||||
end
|
||||
|
||||
|
|
|
@ -20,6 +20,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')
|
||||
|
||||
describe "/shared/_login" do
|
||||
before do
|
||||
assigns[:domain_root_account] = Account.default
|
||||
end
|
||||
|
||||
it "should render" do
|
||||
course_with_student
|
||||
view_context
|
||||
|
|
Loading…
Reference in New Issue