Skip to content

Commit

Permalink
[api] drop hermes compat, it just won't work with existant mail filters
Browse files Browse the repository at this point in the history
  • Loading branch information
coolo committed Dec 5, 2013
1 parent 106abc1 commit 35f816f
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 259 deletions.
7 changes: 4 additions & 3 deletions src/api/app/mailers/event_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ def set_headers

headers['Precdence'] = 'bulk'
headers['X-Mailer'] = 'OBS Notification System'

headers['X-OBS-URL'] = ActionDispatch::Http::URL.url_for(controller: :main, action: :index, only_path: false, host: @host)
headers['Auto-Submitted'] = 'auto-generated'
end

def event(user, e)
Expand All @@ -15,10 +16,10 @@ def event(user, e)

headers(e.custom_headers)

template_name = e.class.name.gsub('Event::', '').underscore
template_name = e.template_name
mail(to: user.email,
subject: e.subject,
from: 'hermes@opensuse.org',
from: e.mail_sender,
template_name: template_name)
end

Expand Down
10 changes: 9 additions & 1 deletion src/api/app/models/event/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def subject
def custom_headers
# not to break user's filters for now
ret = {}
ret['X-hermes-msg-type'] = "OBS_#{raw_type}" if raw_type
ret['X-OBS-event-type'] = template_name # cheating
ret
end

Expand All @@ -158,6 +158,14 @@ def subscribers
def expanded_payload
payload
end

def mail_sender
'obs-email@opensuse.org'
end

def template_name
self.class.name.gsub('Event::', '').underscore
end
end

end
47 changes: 44 additions & 3 deletions src/api/app/models/event/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,39 @@ def my_message_id

def custom_headers
mid = my_message_id
super.merge({'In-Reply-To' => mid, 'References' => mid})
h = super
h['In-Reply-To'] = mid
h['References'] = mid
h['X-OBS-Request-Creator'] = payload['author']
h['X-OBS-Request-Id'] = payload['id']
h['X-OBS-Request-State'] = payload['state']

payload['actions'].each_with_index do |a, index|
if payload['actions'].length == 1 || index == 0
suffix = 'X-OBS-Request-Action'
else
suffix = "X-OBS-Request-Action-#{index}"
end

h[suffix + '-type'] = a['type']
if a['targetpackage']
h[suffix + '-target'] = "#{a['targetproject']}/#{a['targetpackage']}"
elsif a['targetproject']
h[suffix + '-target'] = a['targetproject']
end
if a['sourcepackage']
h[suffix + '-source'] = "#{a['sourceproject']}/#{a['sourcepackage']}"
elsif a['sourceproject']
h[suffix + '-source'] = a['sourceproject']
end
end

h
end

def calculate_diff(a)
return nil if a['type'] != 'submit'
raise "We need action_id" unless a['action_id']
raise 'We need action_id' unless a['action_id']
action = BsRequestAction.find a['action_id']
action.sourcediff(view: nil, withissues: 0)
end
Expand Down Expand Up @@ -48,7 +75,7 @@ def custom_headers
# we're the one they mean
base.delete('In-Reply-To')
base.delete('References')
base.merge({'Message-ID' => my_message_id})
base.merge({ 'Message-ID' => my_message_id })
end

def subject
Expand Down Expand Up @@ -99,4 +126,18 @@ def expanded_payload
payload_with_diff
end

def custom_headers
h = super
if payload['by_user']
h['X-OBS-Review-By_User'] = payload['by_user']
elsif payload['by_group']
h['X-OBS-Review-By_Group'] = payload['by_group']
elsif payload['by_package']
h['X-OBS-Review-By_Package'] = "#{payload['by_project']}/#{payload['by_package']}"
else
h['X-OBS-Review-By_Project'] = payload['by_project']
end
h
end

end
34 changes: 14 additions & 20 deletions src/api/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def get_default_admin

def find_by_login!(login)
user = find_by_login(login)
if user.nil? or user.state == User.states["deleted"]
if user.nil? or user.state == User.states['deleted']
raise NotFound.new("Couldn't find User with login = #{login}")
end
return user
Expand Down Expand Up @@ -833,7 +833,7 @@ def self.realname_for_login(person)
end

def watched_project_names
@watched_projects ||= Rails.cache.fetch(["watched_project_names", self]) do
@watched_projects ||= Rails.cache.fetch(['watched_project_names', self]) do
Project.where(id: watched_projects.pluck(:project_id)).pluck(:name).sort
end
end
Expand Down Expand Up @@ -876,27 +876,27 @@ class ErrRegisterSave < APIException

def self.register(opts)
if CONFIG['ldap_mode'] == :on
raise ErrRegisterSave.new "LDAP mode enabled, users can only be registered via LDAP"
raise ErrRegisterSave.new 'LDAP mode enabled, users can only be registered via LDAP'
end
if CONFIG['proxy_auth_mode'] == :on or CONFIG['ichain_mode'] == :on
raise ErrRegisterSave.new "Proxy authentification mode, manual registration is disabled"
raise ErrRegisterSave.new 'Proxy authentification mode, manual registration is disabled'
end

status = "confirmed"
status = 'confirmed'

unless User.current and User.current.is_admin?
opts[:note] = nil
end

if ::Configuration.first.registration == "deny"
if ::Configuration.first.registration == 'deny'
unless User.current and User.current.is_admin?
raise ErrRegisterSave.new "User registration is disabled"
raise ErrRegisterSave.new 'User registration is disabled'
end
elsif ::Configuration.first.registration == "confirmation"
status = "unconfirmed"
elsif ::Configuration.first.registration != "allow"
render_error :message => "Admin configured an unknown config option for registration",
:errorcode => "server_setup_error", :status => 500
elsif ::Configuration.first.registration == 'confirmation'
status = 'unconfirmed'
elsif ::Configuration.first.registration != 'allow'
render_error :message => 'Admin configured an unknown config option for registration',
:errorcode => 'server_setup_error', :status => 500
return
end
status = opts[:status] if User.current and User.current.is_admin?
Expand All @@ -910,20 +910,14 @@ def self.register(opts)
newuser.realname = opts[:realname]
newuser.state = User.states[status]
newuser.adminnote = opts[:note]
logger.debug("Saving...")
logger.debug('Saving...')
newuser.save

if !newuser.errors.empty?
details = newuser.errors.map{ |key, msg| "#{key}: #{msg}" }.join(", ")
details = newuser.errors.map{ |key, msg| "#{key}: #{msg}" }.join(', ')
raise ErrRegisterSave.new "Could not save the registration, details: #{details}"
end

# create subscription for submit requests
if Object.const_defined? :Hermes
h = Hermes.new
h.add_user(login, email)
h.add_request_subscription(login)
end
end

# returns the gravatar image as string or :none
Expand Down
7 changes: 5 additions & 2 deletions src/api/app/views/event_mailer/review_wanted.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
else
bystring = "by project maintainers of #{@e['by_project']}"
end -%>
Request <%= @e['id'] %> requires a review <%= bystring %>
Request <%= @e['id'] %> (by <%= @e['author'] %>) requires a review <%= bystring %>
Visit <%= url_for(controller: 'webui/request', action: :show, id: @e['id'], host: @host, only_path: false) %>

Reason:
Review reason:
<%= @e['comment'] %>

Request description:
<%= @e['description'] %>
<%= render partial: 'actions' %>
9 changes: 0 additions & 9 deletions src/api/config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@

end


#require 'hermes'
#Hermes::Config.setup do |hermesconf|
# hermesconf.dbhost = 'storage'
# hermesconf.dbuser = 'hermes'
# hermesconf.dbpass = ''
# hermesconf.dbname = 'hermes'
#end

# disabled on production for performance reasons
# CONFIG['response_schema_validation'] = true

Expand Down
Loading

0 comments on commit 35f816f

Please sign in to comment.