0eea8c8857
Some important things to note: - commands are removed from noteable.description / note.note - commands are translated to params so that they are treated as normal params in noteable Creation services - the logic is not in the models but in the Creation services, which is the right place for advanced logic that has nothing to do with what models should be responsible of! - UI/JS needs to be updated to handle notes which consist of commands only - the `/merge` command is not handled yet Other improvements: - Don't process commands in commit notes and display a flash is note is only commands - Add autocomplete for slash commands - Add description and params to slash command DSL methods - Ensure replying by email with a commands-only note works - Use :subscription_event instead of calling noteable.subscribe - Support :todo_event in IssuableBaseService Signed-off-by: Rémy Coutable <remy@rymai.me>
61 lines
1.5 KiB
Ruby
61 lines
1.5 KiB
Ruby
module Gitlab
|
|
module Email
|
|
module Handler
|
|
class BaseHandler
|
|
attr_reader :mail, :mail_key
|
|
|
|
def initialize(mail, mail_key)
|
|
@mail = mail
|
|
@mail_key = mail_key
|
|
end
|
|
|
|
def message
|
|
@message ||= process_message
|
|
end
|
|
|
|
def author
|
|
raise NotImplementedError
|
|
end
|
|
|
|
def project
|
|
raise NotImplementedError
|
|
end
|
|
|
|
private
|
|
|
|
def validate_permission!(permission)
|
|
raise UserNotFoundError unless author
|
|
raise UserBlockedError if author.blocked?
|
|
raise ProjectNotFound unless author.can?(:read_project, project)
|
|
raise UserNotAuthorizedError unless author.can?(permission, project)
|
|
end
|
|
|
|
def process_message
|
|
message = ReplyParser.new(mail).execute.strip
|
|
add_attachments(message)
|
|
end
|
|
|
|
def add_attachments(reply)
|
|
attachments = Email::AttachmentUploader.new(mail).execute(project)
|
|
|
|
reply + attachments.map do |link|
|
|
"\n\n#{link[:markdown]}"
|
|
end.join
|
|
end
|
|
|
|
def verify_record!(record:, invalid_exception:, record_name:)
|
|
return if record.persisted?
|
|
return if record.errors.key?(:commands_only)
|
|
|
|
error_title = "The #{record_name} could not be created for the following reasons:"
|
|
|
|
msg = error_title + record.errors.full_messages.map do |error|
|
|
"\n\n- #{error}"
|
|
end.join
|
|
|
|
raise invalid_exception, msg
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|