diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-10-10 09:05:53 +0100 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-10-10 09:05:53 +0100 |
commit | abdfe58503d26137ee0cb3cc17dcbdedcb93d57c (patch) | |
tree | 4f1132f9aa61d5ecb53ebe7fe16b531e5968b232 /app/models/concerns | |
parent | 058381b6a5a331a85389d12e032117621bab19cc (diff) | |
parent | 43b692cb4b43a476862fb6e7bf4c09edd6035077 (diff) | |
download | gitlab-ce-abdfe58503d26137ee0cb3cc17dcbdedcb93d57c.tar.gz |
Merge branch 'master' into 38869-ci-global38869-ci-global
* master: (116 commits)
Fix bad type checking to prevent 0 count badge to be shown
fix incorrect description for advanced settings section of project settings
Introduce new hook data builders for Issue and MergeRequest
Don't create todos for old issue assignees
Start adding Gitlab::HookData::IssuableBuilder
Include the changes in issuable webhook payloads
Rename the `codeclimate` job to `codequality`
Don't show an "Unsubscribe" link in snippet comment notifications
Add QA::Scenario::Gitlab::Group::Create
Removes CommitsList from global namespace
Fix wiki empty page translation namespace not being removed
Fixes mini graph in commit view
Fix link to new i18n index page
Update i18n docs
Move i18n/introduction to i18n/index
Resolve "Simple documentation update - backup to restore in restore section"
Remove AjaxLoadingSpinner and CreateLabelDropdown from global namespace
Move cycle analytics banner into a vue file
Updated Icons + Fix for Collapsed Groups Angle
Don't create fork networks for root projects that are deleted
...
Diffstat (limited to 'app/models/concerns')
-rw-r--r-- | app/models/concerns/cache_markdown_field.rb | 14 | ||||
-rw-r--r-- | app/models/concerns/discussion_on_diff.rb | 4 | ||||
-rw-r--r-- | app/models/concerns/issuable.rb | 29 | ||||
-rw-r--r-- | app/models/concerns/routable.rb | 2 | ||||
-rw-r--r-- | app/models/concerns/token_authenticatable.rb | 4 |
5 files changed, 33 insertions, 20 deletions
diff --git a/app/models/concerns/cache_markdown_field.rb b/app/models/concerns/cache_markdown_field.rb index 193e459977a..9417033d1f6 100644 --- a/app/models/concerns/cache_markdown_field.rb +++ b/app/models/concerns/cache_markdown_field.rb @@ -59,7 +59,7 @@ module CacheMarkdownField # Update every column in a row if any one is invalidated, as we only store # one version per row - def refresh_markdown_cache!(do_update: false) + def refresh_markdown_cache options = { skip_project_check: skip_project_check? } updates = cached_markdown_fields.markdown_fields.map do |markdown_field| @@ -71,8 +71,14 @@ module CacheMarkdownField updates['cached_markdown_version'] = CacheMarkdownField::CACHE_VERSION updates.each {|html_field, data| write_attribute(html_field, data) } + end + + def refresh_markdown_cache! + updates = refresh_markdown_cache + + return unless persisted? && Gitlab::Database.read_write? - update_columns(updates) if persisted? && do_update + update_columns(updates) end def cached_html_up_to_date?(markdown_field) @@ -124,8 +130,8 @@ module CacheMarkdownField end # Using before_update here conflicts with elasticsearch-model somehow - before_create :refresh_markdown_cache!, if: :invalidated_markdown_cache? - before_update :refresh_markdown_cache!, if: :invalidated_markdown_cache? + before_create :refresh_markdown_cache, if: :invalidated_markdown_cache? + before_update :refresh_markdown_cache, if: :invalidated_markdown_cache? end class_methods do diff --git a/app/models/concerns/discussion_on_diff.rb b/app/models/concerns/discussion_on_diff.rb index eee1a36ac6b..f5cbb3becad 100644 --- a/app/models/concerns/discussion_on_diff.rb +++ b/app/models/concerns/discussion_on_diff.rb @@ -28,6 +28,10 @@ module DiscussionOnDiff true end + def file_new_path + first_note.position.new_path + end + # Returns an array of at most 16 highlighted lines above a diff note def truncated_diff_lines(highlight: true) lines = highlight ? highlighted_diff_lines : diff_lines diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index fc30d008dea..27f4dedffd3 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -256,23 +256,22 @@ module Issuable participants(user).include?(user) end - def to_hook_data(user) - hook_data = { - object_kind: self.class.name.underscore, - user: user.hook_attrs, - project: project.hook_attrs, - object_attributes: hook_attrs, - labels: labels.map(&:hook_attrs), - # DEPRECATED - repository: project.hook_attrs.slice(:name, :url, :description, :homepage) - } - if self.is_a?(Issue) - hook_data[:assignees] = assignees.map(&:hook_attrs) if assignees.any? - else - hook_data[:assignee] = assignee.hook_attrs if assignee + def to_hook_data(user, old_labels: [], old_assignees: []) + changes = previous_changes + + if old_labels != labels + changes[:labels] = [old_labels.map(&:hook_attrs), labels.map(&:hook_attrs)] + end + + if old_assignees != assignees + if self.is_a?(Issue) + changes[:assignees] = [old_assignees.map(&:hook_attrs), assignees.map(&:hook_attrs)] + else + changes[:assignee] = [old_assignees&.first&.hook_attrs, assignee&.hook_attrs] + end end - hook_data + Gitlab::HookData::IssuableBuilder.new(self).build(user: user, changes: changes) end def labels_array diff --git a/app/models/concerns/routable.rb b/app/models/concerns/routable.rb index 12e93be2104..22fde2eb134 100644 --- a/app/models/concerns/routable.rb +++ b/app/models/concerns/routable.rb @@ -156,6 +156,8 @@ module Routable end def update_route + return if Gitlab::Database.read_only? + prepare_route route.save end diff --git a/app/models/concerns/token_authenticatable.rb b/app/models/concerns/token_authenticatable.rb index a7d5de48c66..ec3543f7053 100644 --- a/app/models/concerns/token_authenticatable.rb +++ b/app/models/concerns/token_authenticatable.rb @@ -43,15 +43,17 @@ module TokenAuthenticatable write_attribute(token_field, token) if token end + # Returns a token, but only saves when the database is in read & write mode define_method("ensure_#{token_field}!") do send("reset_#{token_field}!") if read_attribute(token_field).blank? # rubocop:disable GitlabSecurity/PublicSend read_attribute(token_field) end + # Resets the token, but only saves when the database is in read & write mode define_method("reset_#{token_field}!") do write_new_token(token_field) - save! + save! if Gitlab::Database.read_write? end end end |