Permalink
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
InCommonTAP-Examples/Sources/SIS/app/models/user.rb
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
also hack to remove stale pid file
67 lines (50 sloc)
1.97 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/ldap' | |
require 'bunny' | |
require 'json' | |
class User < ApplicationRecord | |
has_and_belongs_to_many :courses | |
def name | |
return givenname + " " + surname | |
end | |
def write_to_ldap | |
ldap_host = LDAP_CONFIG['host'] | |
ldap_port = LDAP_CONFIG['port'] | |
ldap_base = LDAP_CONFIG['base'] | |
ldap_user = LDAP_CONFIG['admin'] | |
ldap_pass = LDAP_CONFIG['pass'] | |
# create the DN for the object | |
dn = "uid="+uid+","+ldap_base | |
# create the list of attributes for the object | |
attr = { | |
:cn => fullName, | |
:objectclass => ['organizationalperson','person','top','inetOrgPerson','eduPerson'], | |
:givenName => givenname, | |
:sn => surname, | |
:uid => uid, | |
:userPassword => password | |
} | |
# connect and add the entry | |
# Babb: assuming midpoint is adding to ldap? commented out for now. | |
# TODO: remove publish_to_ldap from controller | |
###Net::LDAP.open( :host => ldap_host, :port => ldap_port, :base => ldap_base, :auth => { :method => :simple, :username => ldap_user, :password => ldap_pass }) do |ldap| | |
### ldap.add( :dn => dn, :attributes => attr) | |
###end | |
end | |
def publish_to_rabbit(action) | |
# Message payload | |
msg = {:uid => uid, :action => action} | |
# TODO: connection should be pooled and created on app start? | |
rabbit_connection = Bunny.new(ENV['RABBITMQ_URI'] || 'amqp://localhost') | |
rabbit_connection.start | |
channel = rabbit_connection.create_channel | |
# Create the queue if it does not exist | |
channel.queue("sis.user", :exclusive => false) | |
# TODO: allow user to specify exchange in config | |
exchange = channel.default_exchange | |
# Publish that something about UID changed | |
# This should cover both course enrollments and general data about them. | |
exchange.publish(msg.to_json, :routing_key => 'sis.user') | |
logger.info('Published message: ' + msg.to_json) | |
rabbit_connection.close | |
end | |
end |