# class User

### Public Instance Methods

current_organisation() click to toggle source

    # File app/models/user.rb, line 98
    def current_organisation
            if self.organisations.count > 0 then
                    return self.organisations.last
            else
                    return nil
            end
    end

filter(query) click to toggle source

    # File app/models/user.rb, line 19
    def filter(query)
      return self unless query.present?

      t = self.arel_table
      q = "%#{query}%"

      conditions = t[:title].matches(q)

      columns = %(
        grant_number identifier description principal_investigator data_contact
      )

      columns.each {|col| conditions = conditions.or(t[col].matches(q)) }

      self.where(conditions)
    end

can_super_admin?() click to toggle source

    # File app/models/user.rb, line 110
    def can_super_admin?
            admin = roles.find_by_name("admin")
            return !admin.nil?
    end

can_org_admin?() click to toggle source

    # File app/models/user.rb, line 115
    def can_org_admin?
            org_admin = roles.find_by_name("org_admin")
            return !org_admin.nil?
    end

name(use_email = true) click to toggle source

    # File app/models/user.rb, line 54
    def name(use_email = true)
            if ((firstname.nil? && surname.nil?) || (firstname.strip == "" && surname.strip == "")) && use_email then
                    return email
            else
                    name = "#{firstname} #{surname}"
                    return name.strip
            end
    end

org_type() click to toggle source

    # File app/models/user.rb, line 120
    def org_type
        org_type = organisation.organisation_type.name
                return org_type
    end

organisation() click to toggle source

    # File app/models/user.rb, line 90
    def organisation
            if self.organisations.count > 0 then
                    return self.organisations.first
            else
                    return nil
            end
    end

organisation=(new_organisation) click to toggle source

    # File app/models/user.rb, line 106
    def organisation=(new_organisation)
            organisation_id = organisation.id
    end

organisation_id() click to toggle source

    # File app/models/user.rb, line 82
    def organisation_id
            if self.organisations.count > 0 then
                    return self.organisations.first.id
            else
                    return nil
            end
    end

organisation_id=(new_organisation_id) click to toggle source

    # File app/models/user.rb, line 63
        def organisation_id=(new_organisation_id)
    if !self.user_org_roles.pluck(:organisation_id).include?(new_organisation_id.to_i) then
                if self.user_org_roles.count != 1 then
                        new_user_org_role = UserOrgRole.new
                        new_user_org_role.organisation_id = new_organisation_id
                        new_user_org_role.user_role_type = UserRoleType.find_by_name("user");
                        self.user_org_roles << new_user_org_role
                else
                        user_org_role = self.user_org_roles.first
                        user_org_role.organisation_id = new_organisation_id
            user_org_role.save
                        org_admin_role = roles.find_by_name("org_admin")
                        unless org_admin_role.nil? then
                                roles.delete(org_admin_role)
                        end
                end
    end
        end