summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-07-25 05:12:24 -0700
committerStan Hu <stanhu@gmail.com>2018-07-25 05:12:24 -0700
commit537f87a169576544b26347b5b3a6ab22d2cbfc00 (patch)
tree58cb66cf9639ef46acc4927fef0b4e0a84269568 /app/models
parentf94b52256d1bedfe6b01ef31f0bed0615b10d918 (diff)
parentd22db4f492d5ae676bea6bc699203d2fc120fe96 (diff)
downloadgitlab-ce-537f87a169576544b26347b5b3a6ab22d2cbfc00.tar.gz
Merge branch 'master' into sh-support-bitbucket-server-import
Diffstat (limited to 'app/models')
-rw-r--r--app/models/deploy_token.rb6
-rw-r--r--app/models/project.rb2
-rw-r--r--app/models/project_services/hangouts_chat_service.rb67
-rw-r--r--app/models/project_wiki.rb2
-rw-r--r--app/models/service.rb1
5 files changed, 76 insertions, 2 deletions
diff --git a/app/models/deploy_token.rb b/app/models/deploy_token.rb
index 5082dc45368..7ab647abe93 100644
--- a/app/models/deploy_token.rb
+++ b/app/models/deploy_token.rb
@@ -27,7 +27,7 @@ class DeployToken < ActiveRecord::Base
end
def active?
- !revoked
+ !revoked && expires_at > Date.today
end
def scopes
@@ -58,6 +58,10 @@ class DeployToken < ActiveRecord::Base
write_attribute(:expires_at, value.presence || Forever.date)
end
+ def admin?
+ false
+ end
+
private
def ensure_at_least_one_scope
diff --git a/app/models/project.rb b/app/models/project.rb
index 5f582dfa5ee..325dbd0197f 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -154,6 +154,7 @@ class Project < ActiveRecord::Base
has_one :mock_monitoring_service
has_one :microsoft_teams_service
has_one :packagist_service
+ has_one :hangouts_chat_service
# TODO: replace these relations with the fork network versions
has_one :forked_project_link, foreign_key: "forked_to_project_id"
@@ -326,6 +327,7 @@ class Project < ActiveRecord::Base
scope :joined, ->(user) { where('namespace_id != ?', user.namespace_id) }
scope :starred_by, ->(user) { joins(:users_star_projects).where('users_star_projects.user_id': user.id) }
scope :visible_to_user, ->(user) { where(id: user.authorized_projects.select(:id).reorder(nil)) }
+ scope :visible_to_user_and_access_level, ->(user, access_level) { where(id: user.authorized_projects.where('project_authorizations.access_level >= ?', access_level).select(:id).reorder(nil)) }
scope :archived, -> { where(archived: true) }
scope :non_archived, -> { where(archived: false) }
scope :for_milestones, ->(ids) { joins(:milestones).where('milestones.id' => ids).distinct }
diff --git a/app/models/project_services/hangouts_chat_service.rb b/app/models/project_services/hangouts_chat_service.rb
new file mode 100644
index 00000000000..a8512c5f57c
--- /dev/null
+++ b/app/models/project_services/hangouts_chat_service.rb
@@ -0,0 +1,67 @@
+require 'hangouts_chat'
+
+class HangoutsChatService < ChatNotificationService
+ def title
+ 'Hangouts Chat'
+ end
+
+ def description
+ 'Receive event notifications in Google Hangouts Chat'
+ end
+
+ def self.to_param
+ 'hangouts_chat'
+ end
+
+ def help
+ 'This service sends notifications about projects events to Google Hangouts Chat room.<br />
+ To set up this service:
+ <ol>
+ <li><a href="https://developers.google.com/hangouts/chat/how-tos/webhooks">Set up an incoming webhook for your room</a>. All notifications will come to this room.</li>
+ <li>Paste the <strong>Webhook URL</strong> into the field below.</li>
+ <li>Select events below to enable notifications.</li>
+ </ol>'
+ end
+
+ def event_field(event)
+ end
+
+ def default_channel_placeholder
+ end
+
+ def webhook_placeholder
+ 'https://chat.googleapis.com/v1/spaces…'
+ end
+
+ def default_fields
+ [
+ { type: 'text', name: 'webhook', placeholder: "e.g. #{webhook_placeholder}" },
+ { type: 'checkbox', name: 'notify_only_broken_pipelines' },
+ { type: 'checkbox', name: 'notify_only_default_branch' }
+ ]
+ end
+
+ private
+
+ def notify(message, opts)
+ simple_text = parse_simple_text_message(message)
+ HangoutsChat::Sender.new(webhook).simple(simple_text)
+ end
+
+ def parse_simple_text_message(message)
+ header = message.pretext
+ return header if message.attachments.empty?
+
+ attachment = message.attachments.first
+ title = format_attachment_title(attachment)
+ body = attachment[:text]
+
+ [header, title, body].compact.join("\n")
+ end
+
+ def format_attachment_title(attachment)
+ return attachment[:title] unless attachment[:title_link]
+
+ "<#{attachment[:title_link]}|#{attachment[:title]}>"
+ end
+end
diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb
index 3aa56b3983f..f4b3421f04b 100644
--- a/app/models/project_wiki.rb
+++ b/app/models/project_wiki.rb
@@ -82,7 +82,7 @@ class ProjectWiki
# Returns an Array of Gitlab WikiPage instances or an
# empty Array if this Wiki has no pages.
- def pages(limit: nil)
+ def pages(limit: 0)
wiki.pages(limit: limit).map { |page| WikiPage.new(self, page, true) }
end
diff --git a/app/models/service.rb b/app/models/service.rb
index ad835293b46..cbfe0c6eedd 100644
--- a/app/models/service.rb
+++ b/app/models/service.rb
@@ -254,6 +254,7 @@ class Service < ActiveRecord::Base
emails_on_push
external_wiki
flowdock
+ hangouts_chat
hipchat
irker
jira