Skip to content
This repository has been archived by the owner on Jun 5, 2019. It is now read-only.

Commit

Permalink
Add is_admin mapping for ldap
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Dec 19, 2016
1 parent fc911b2 commit 11600ef
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/models/ldap_auth_source.rb
Expand Up @@ -33,7 +33,7 @@ class LdapAuthSource < AuthSource
validates_presence_of :host, :port, :attr_login
validates_length_of :name, :host, maximum: 60, allow_nil: true
validates_length_of :account, :account_password, :base_dn, maximum: 255, allow_nil: true
validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, maximum: 30, allow_nil: true
validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :attr_admin, maximum: 30, allow_nil: true
validates_numericality_of :port, only_integer: true

before_validation :strip_ldap_attributes
Expand Down Expand Up @@ -67,7 +67,7 @@ def auth_method_name
private

def strip_ldap_attributes
[:attr_login, :attr_firstname, :attr_lastname, :attr_mail].each do |attr|
[:attr_login, :attr_firstname, :attr_lastname, :attr_mail, :attr_admin].each do |attr|
write_attribute(attr, read_attribute(attr).strip) unless read_attribute(attr).nil?
end
end
Expand All @@ -88,6 +88,7 @@ def get_user_attributes_from_ldap_entry(entry)
firstname: LdapAuthSource.get_attr(entry, attr_firstname),
lastname: LdapAuthSource.get_attr(entry, attr_lastname),
mail: LdapAuthSource.get_attr(entry, attr_mail),
admin: !!LdapAuthSource.get_attr(entry, attr_admin),
auth_source_id: id
}
end
Expand Down
1 change: 1 addition & 0 deletions app/views/ldap_auth_sources/_form.html.erb
Expand Up @@ -53,4 +53,5 @@ See doc/COPYRIGHT.rdoc for more details.
<div class="form--field"><%= f.text_field 'attr_firstname', label: AuthSource.human_attribute_name(:firstname), size: 20 %></div>
<div class="form--field"><%= f.text_field 'attr_lastname', label: AuthSource.human_attribute_name(:lastname), size: 20 %></div>
<div class="form--field"><%= f.text_field 'attr_mail', label: AuthSource.human_attribute_name(:mail), size: 20 %></div>
<div class="form--field"><%= f.text_field 'attr_admin', label: AuthSource.human_attribute_name(:admin), size: 20 %></div>
</fieldset>
34 changes: 34 additions & 0 deletions db/migrate/20161219134700_add_attr_admin_to_ldap.rb
@@ -0,0 +1,34 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++

class AddAttrAdminToLdap < ActiveRecord::Migration[5.0]
def change
add_column :auth_sources, :attr_admin, :string
end
end

0 comments on commit 11600ef

Please sign in to comment.