<commit_before>=begin

Copyright 2012 Shared Learning Collaborative, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=end


include GeneralRealmHelper

class CustomRolesController < ApplicationController
  # GET /realms
  # GET /realms.json
  def index
    custom_role = CustomRole.find(:first)
    if custom_role != nil
      redirect_to  :action => "show", :id => custom_role.id
    else
      message = (APP_CONFIG["is_sandbox"] ? "No custom roles exist.  First create a landing zone in the Provizion Landing Zone tool." :
                                            "No custom roles exist.  First create a realm in the Realm Management tool.")
      flash.now[:notice] = message
      respond_to do |format|
        format.html # index.html.erb
      end
    end
  end


  # # GET /realms/1/
   def show
     @custom_roles = CustomRole.find(params[:id])
     @default_roles = CustomRole.defaults()
   end

  # # PUT /realms/1
   def update
     @custom_roles = CustomRole.find(params[:id])
     respond_to do |format|
       success = false
       errorMsg = ""
       begin
         @custom_roles.roles = params[:json]
         success =  @custom_roles.save()
       rescue ActiveResource::BadRequest => error
         errorMsg = error.response.body
         logger.debug("Error: #{errorMsg}")
       end

       if success
         format.json { render json: @custom_roles, status: :created, location: @custom_roles }
       else
         #errorJson = JSON.parse(errorMsg)
         flash[:error] = errorMsg
         format.json { render json: errorMsg, status: :unprocessable_entity }
       end
	
     end
   end

private

  def get_user_realm
    return session[:edOrg]
  end

end<commit_msg>[DE1908] Change message for invalid chars in custom roles<commit_after>=begin

Copyright 2012 Shared Learning Collaborative, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=end


include GeneralRealmHelper

class CustomRolesController < ApplicationController
  # GET /realms
  # GET /realms.json
  def index
    custom_role = CustomRole.find(:first)
    if custom_role != nil
      redirect_to  :action => "show", :id => custom_role.id
    else
      message = (APP_CONFIG["is_sandbox"] ? "No custom roles exist.  First create a landing zone in the Provizion Landing Zone tool." :
                                            "No custom roles exist.  First create a realm in the Realm Management tool.")
      flash.now[:notice] = message
      respond_to do |format|
        format.html # index.html.erb
      end
    end
  end


  # # GET /realms/1/
   def show
     @custom_roles = CustomRole.find(params[:id])
     @default_roles = CustomRole.defaults()
   end

  # # PUT /realms/1
   def update
     @custom_roles = CustomRole.find(params[:id])
     respond_to do |format|
       success = false
       errorMsg = ""
       begin
         @custom_roles.roles = params[:json]
         success =  @custom_roles.save()
       rescue ActiveResource::BadRequest => error
         errorMsg = error.response.body
         logger.debug("Error: #{errorMsg}")
       end

       if success
         format.json { render json: @custom_roles, status: :created, location: @custom_roles }
       else
         #errorJson = JSON.parse(errorMsg)
         if /ValidationError.*groupTitle/.match(errorMsg)
           flash[:error] = "Group name contains invalid characters."
         elsif /ValidationError.*names/.match(errorMsg)
           flash[:error] = "Role name contains invalid characters."
         else
           flash[:error] = "Changes could not be saved."
         end
         format.json { render json: errorMsg, status: :unprocessable_entity }
       end
	
     end
   end

private

  def get_user_realm
    return session[:edOrg]
  end

end
{'fraction_non_alphanumeric': 0.08104658583280153, 'fraction_numerical': 0.005105296745373325, 'mean_word_length': 2.6677067082683306, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '17670', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1286, 'n_words': 455}