diff options
Diffstat (limited to 'lib/gitlab/chat_commands/command.rb')
-rw-r--r-- | lib/gitlab/chat_commands/command.rb | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/lib/gitlab/chat_commands/command.rb b/lib/gitlab/chat_commands/command.rb index 43144975901..5f131703d40 100644 --- a/lib/gitlab/chat_commands/command.rb +++ b/lib/gitlab/chat_commands/command.rb @@ -7,10 +7,14 @@ module Gitlab ].freeze def execute - klass, match = fetch_klass - - if klass - present klass.new(project, current_user, params).execute(match) + command, match = match_command + + if command + if command.allowed?(project, current_user) + present command.new(project, current_user, params).execute(match) + else + access_denied + end else help(help_messages) end @@ -18,7 +22,7 @@ module Gitlab private - def fetch_klass + def match_command match = nil service = available_commands.find do |klass| match = klass.match(command) @@ -28,9 +32,7 @@ module Gitlab end def help_messages - available_commands.map do |klass| - klass.help_message - end + available_commands.map(&:help_message) end def available_commands @@ -43,13 +45,17 @@ module Gitlab params[:text] end - def present(resource) - Mattermost::Presenter.present(resource) - end - def help(messages) Mattermost::Presenter.help(messages, params[:command]) end + + def access_denied + Mattermost::Presenter.access_denied + end + + def present(resource) + Mattermost::Presenter.present(resource) + end end end end |