<commit_before>require 'utils/attributes_accessor'
require 'redmine_http'
require 'redmine_membership'

class RedmineUser < PresentationModel
  @@redmine_user_elements = %w[ id:int login firstname lastname mail created_on last_login api_key groups auth ]

  include AttributesAccessor

  def self.login _username, _password
    auth = {:username => _username, :password => _password}
    _u = RedmineHttp.new('users',auth).find(:current,{:query => {:include=>'memberships'}})

    if !_u.nil?
      _u['auth'] = auth
      RedmineUser.new({:data => _u})
    else
      raise Unauthorized.new
    end

  end

  def memberships
    @memberships ||= gen_memberships
  end

  def extra_hash
    {:memberships => memberships.map {|item| item.to_hash }}
  end

  def can_write? _project
    return true if Setting.admin_users.include? self.login
    _m = find_memberships_by_project _project
    return false if _m.blank?
    !_m.find{|x| x.repository_write_role?(self)}.blank?
  end

  def can_read? _project
    return true if Setting.admin_users.include? self.login

    _m = find_memberships_by_project _project
    return false if _m.blank?
    !_m.find{|x| x.repository_read_role?(self)}.blank?<commit_msg>error in model<commit_after>require 'utils/attributes_accessor'
require 'redmine_http'
require 'redmine_membership'
require 'http_exceptions'

class RedmineUser < PresentationModel
  @@redmine_user_elements = %w[ id:int login firstname lastname mail created_on last_login api_key groups auth ]

  include AttributesAccessor

  def self.login _username, _password
    auth = {:username => _username, :password => _password}
    _u = RedmineHttp.new('users',auth).find(:current,{:query => {:include=>'memberships'}})

    if !_u.nil?
      _u['auth'] = auth
      RedmineUser.new({:data => _u})
    else
      raise HttpExceptions::Unauthorized.new
    end

  end

  def memberships
    @memberships ||= gen_memberships
  end

  def extra_hash
    {:memberships => memberships.map {|item| item.to_hash }}
  end

  def can_write? _project
    return true if Setting.admin_users.include? self.login
    _m = find_memberships_by_project _project
    return false if _m.blank?
    !_m.find{|x| x.repository_write_role?(self)}.blank?
  end

  def can_read? _project
    return true if Setting.admin_users.include? self.login

    _m = find_memberships_by_project _project
    return false if _m.blank?
    !_m.find{|x| x.repository_read_role?(self)}.blank?
{'fraction_non_alphanumeric': 0.10427698574338086, 'fraction_numerical': 0.0, 'mean_word_length': 4.063917525773196, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '327335', 'n_tokens_mistral': 831, 'n_tokens_neox': 788, 'n_words': 189}