<commit_before>#
#   Copyright 2011 Red Hat, Inc.
#
#   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.
#

class RolesController < ApplicationController
  before_filter :require_user
  before_filter :load_roles, :only => [:show]

  def index
    clear_breadcrumbs
    save_breadcrumb(roles_path)
    load_roles
  end

  def new
    require_privilege(Privilege::PERM_SET)
    @role = Role.new
  end

  def create
    require_privilege(Privilege::PERM_SET)
    @role = Role.new(params[:role])

    # TODO: (lmartinc) Fix this and let user select the scope. Consult with sseago.
    @role.scope = BasePermissionObject.to_s if @role.scope.nil?

    if @role.save
      flash[:notice] = t"roles.flash.notice.added"
      redirect_to roles_path and return
    end

    render :action => 'new'
  end

  def show
    require_privilege(Privilege::PERM_VIEW)
    @role = Role.find(params[:id])

    @tab_captions = [t('roles.tab_captions.properties')]
    @details_tab = params[:details_tab].blank? ? 'properties' : params[:details_tab]
    save_breadcrumb(role_path(@role), @role.name)
    respond_to do |format|
      format.html
      format.js do
        if params.delete :details_pane
          render :partial => 'layouts/details_pane' and return
        end
        render :partial => @details_tab
      end
    end
  end

  def edit
    require_privilege(Privilege::PERM_SET)
    @role = Role.find(params[:id])
  end

  def update
    require_privilege(Privilege::PERM_SET)
    @role = Role.find(params[:id])

    if params[:commit] == "Reset"
      redirect_to edit_role_url(@role) and return
    end

    if @role.update_attributes(params[:role])
      flash[:notice] = t"roles.flash.notice.updated"
      redirect_to roles_url and return
    end

    render :action => 'edit'
  end

  def multi_destroy
    deleted=[]
    not_deleted=[]
    require_privilege(Privilege::PERM_SET)
    Role.find(params[:role_selected]).each do |role|
      if role.destroy
        deleted << role.name
      else
        not_deleted << role.name
      end
    end

    unless deleted.empty?
      flash[:notice] = "#{t('roles.flash.notice.more_deleted')} #{deleted.join(', ')}"
    end
    unless not_deleted.empty?
      flash[:error] = "#{t('roles.flash.error.more_not_deletedX')} #{not_deleted.join(', ')}"
    end

    redirect_to roles_url
  end

  def destroy
    require_privilege(Privilege::PERM_SET)
    Role.destroy(params[:id])
    redirect_to roles_url
  end

  protected

  def load_roles
    @roles = Role.paginate(:page => params[:page] || 1,
      :order => (sort_column(Role)+' '+ (sort_direction))
    )
  end

end
<commit_msg>require Privilege::PRIV_VIEW to view roles index<commit_after>#
#   Copyright 2011 Red Hat, Inc.
#
#   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.
#

class RolesController < ApplicationController
  before_filter :require_user
  before_filter :load_roles, :only => [:show]

  def index
    require_privilege(Privilege::PERM_VIEW)
    clear_breadcrumbs
    save_breadcrumb(roles_path)
    load_roles
  end

  def new
    require_privilege(Privilege::PERM_SET)
    @role = Role.new
  end

  def create
    require_privilege(Privilege::PERM_SET)
    @role = Role.new(params[:role])

    # TODO: (lmartinc) Fix this and let user select the scope. Consult with sseago.
    @role.scope = BasePermissionObject.to_s if @role.scope.nil?

    if @role.save
      flash[:notice] = t"roles.flash.notice.added"
      redirect_to roles_path and return
    end

    render :action => 'new'
  end

  def show
    require_privilege(Privilege::PERM_VIEW)
    @role = Role.find(params[:id])

    @tab_captions = [t('roles.tab_captions.properties')]
    @details_tab = params[:details_tab].blank? ? 'properties' : params[:details_tab]
    save_breadcrumb(role_path(@role), @role.name)
    respond_to do |format|
      format.html
      format.js do
        if params.delete :details_pane
          render :partial => 'layouts/details_pane' and return
        end
        render :partial => @details_tab
      end
    end
  end

  def edit
    require_privilege(Privilege::PERM_SET)
    @role = Role.find(params[:id])
  end

  def update
    require_privilege(Privilege::PERM_SET)
    @role = Role.find(params[:id])

    if params[:commit] == "Reset"
      redirect_to edit_role_url(@role) and return
    end

    if @role.update_attributes(params[:role])
      flash[:notice] = t"roles.flash.notice.updated"
      redirect_to roles_url and return
    end

    render :action => 'edit'
  end

  def multi_destroy
    deleted=[]
    not_deleted=[]
    require_privilege(Privilege::PERM_SET)
    Role.find(params[:role_selected]).each do |role|
      if role.destroy
        deleted << role.name
      else
        not_deleted << role.name
      end
    end

    unless deleted.empty?
      flash[:notice] = "#{t('roles.flash.notice.more_deleted')} #{deleted.join(', ')}"
    end
    unless not_deleted.empty?
      flash[:error] = "#{t('roles.flash.error.more_not_deletedX')} #{not_deleted.join(', ')}"
    end

    redirect_to roles_url
  end

  def destroy
    require_privilege(Privilege::PERM_SET)
    Role.destroy(params[:id])
    redirect_to roles_url
  end

  protected

  def load_roles
    @roles = Role.paginate(:page => params[:page] || 1,
      :order => (sort_column(Role)+' '+ (sort_direction))
    )
  end

end

{'fraction_non_alphanumeric': 0.10700236034618411, 'fraction_numerical': 0.002832415420928403, 'mean_word_length': 3.189848384970336, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6331251', 'n_tokens_mistral': 2097, 'n_tokens_neox': 2067, 'n_words': 520}