Commit Graph

276 Commits

Author SHA1 Message Date
Jarka Kadlecova 0c350b7939 address comments 2017-01-25 10:10:05 +01:00
Jarka Kadlecova d6b11dafd3 Support notes without project 2017-01-18 18:38:17 -05:00
Douwe Maan 12db4cc0e7 Merge branch 'jej-note-search-uses-finder' into 'security'
Fix missing Note access checks in by moving Note#search to updated NoteFinder

Split from !2024 to partially solve https://gitlab.com/gitlab-org/gitlab-ce/issues/23867

## Which fixes are in this MR?

⚠️ - Potentially untested  
💣 - No test coverage  
🚥 - Test coverage of some sort exists (a test failed when error raised)  
🚦 - Test coverage of return value (a test failed when nil used)  
 - Permissions check tested

### Note lookup without access check

- [x]  app/finders/notes_finder.rb:13 :download_code check
- [x]  app/finders/notes_finder.rb:19 `SnippetsFinder`
- [x]  app/models/note.rb:121 [`Issue#visible_to_user`]
- [x]  lib/gitlab/project_search_results.rb:113
  - This is the only use of `app/models/note.rb:121` above, but importantly has no access checks at all. This means it leaks MR comments and snippets when those features are `team-only` in addition to the issue comments which would be fixed by `app/models/note.rb:121`.
  - It is only called from SearchController where `can?(current_user, :download_code, @project)` is checked, so commit comments are not leaked.

### Previous discussions
- [x] https://dev.gitlab.org/gitlab/gitlabhq/merge_requests/2024/diffs#b915c5267a63628b0bafd23d37792ae73ceae272_13_13 `: download_code` check on commit
- [x] https://dev.gitlab.org/gitlab/gitlabhq/merge_requests/2024/diffs#b915c5267a63628b0bafd23d37792ae73ceae272_19_19 `SnippetsFinder` should be used
  - `SnippetsFinder` should check if the snippets feature is enabled -> https://gitlab.com/gitlab-org/gitlab-ce/issues/25223

###  Acceptance criteria met?
- [x] Tests added for new code
- [x] TODO comments removed
- [x] Squashed and removed skipped tests
- [x] Changelog entry
- [ ] State Gitlab versions affected and issue severity in description
- [ ] Create technical debt issue for NotesFinder.
  - Either split into `NotesFinder::ForTarget` and `NotesFinder::Search` or consider object per notable type such as `NotesFinder::OnIssue`. For the first option could create `NotesFinder::Base` which is either inherited from or which can be included in the other two.
  - Avoid case statement anti-pattern in this finder with use of `NotesFinder::OnCommit` etc. Consider something on the finder for this? `Model.finder(user, project)`
  - Move `inc_author` to the controller, and implement `related_notes` to replace `non_diff_notes`/`mr_and_commit_notes`

See merge request !2035
2016-12-15 11:40:12 -03:00
Bob Van Landuyt 1123057ab7 Feature: delegate all open discussions to Issue
When a merge request can only be merged when all discussions are
resolved. This feature allows to easily delegate those discussions to a
new issue, while marking them as resolved in the merge request.

The user is presented with a new issue, prepared with mentions of all
unresolved discussions, including the first unresolved note of the
discussion, time and link to the note.

When the issue is created, the discussions in the merge request will get
a system note directing the user to the newly created issue.
2016-12-05 20:55:45 +01:00
Douwe Maan d8f7523368 Merge branch 'events-cache-invalidation' into 'master'
Remove caching of events data

This MR removes the caching of events data as this was deemed unnecessary while increasing load on the database. See https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6578#note_18864037 and 5371da341e for more information.

See merge request !6578
2016-11-28 03:34:12 +00:00
Douwe Maan ba5e98bb70 Backport Note#commands_changes from EE 2016-11-24 14:32:32 +08:00
Yorick Peterse 5371da341e
Remove event caching code
Flushing the events cache worked by updating a recent number of rows in
the "events" table. This has the result that on PostgreSQL a lot of dead
tuples are produced on a regular basis. This in turn means that
PostgreSQL will spend considerable amounts of time vacuuming this table.
This in turn can lead to an increase of database load.

For GitLab.com we measured the impact of not using events caching and
found no measurable increase in response timings. Meanwhile not flushing
the events cache lead to the "events" table having no more dead tuples
as now rows are only inserted into this table.

As a result of this we are hereby removing events caching as it does not
appear to help and only increases database load.

For more information see the following comment:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6578#note_18864037
2016-11-23 14:17:07 +01:00
Oswaldo Ferreira d48d879ef5 Does not raise error when Note not found when processing NewNoteWorker
- Also remove unnecessary param
2016-11-11 22:54:11 -02:00
Nick Thomas 109816c42f Use CacheMarkdownField for notes 2016-10-07 02:54:26 +01:00
Z.J. van de Weg 412ff80b7b Start Frontend work, fix routing problem 2016-09-19 19:50:40 +03:00
barthc 7687237237 prevent authored awardable thumbs votes
prevent authored awardable thumbs votes

prevent authored awardable thumbs votes
2016-08-28 18:15:55 +01:00
Stan Hu 5cb488e8a1 Fix Error 500 resulting when loading network graph
`discussion_id` may not be present when the SELECT call for notes
does not include this attribute. Don't attempt to set the discussion ID
unless the model contains the attribute.

Closes #21119, #21128
2016-08-20 09:57:20 -07:00
Douwe Maan 6a355d451e Improve performance of MR show page 2016-08-18 19:08:59 -05:00
Douwe Maan dc098fde96 Fix MR note discussion ID 2016-08-18 17:27:41 -05:00
Douwe Maan c64e977d2e Fix class method definition 2016-08-17 16:25:42 -05:00
Douwe Maan 4a13aa9f34 Store discussion_id on Note for faster discussion lookup. 2016-08-17 12:16:46 -05:00
Douwe Maan c770201061 Merge branch 'master' into diff-line-comment-vuejs 2016-08-12 17:23:19 -05:00
Yorick Peterse 77c8520e2e
Added concern for a faster "cache_key" method
This concern provides an optimized/simplified version of the "cache_key"
method. This method is about 9 times faster than the default "cache_key"
method.

The produced cache keys _are_ different from the previous ones but this
is worth the performance improvement. To showcase this I set up a
benchmark (using benchmark-ips) that compares FasterCacheKeys#cache_key
with the regular cache_key. The output of this benchmark was:

    Calculating -------------------------------------
               cache_key     4.825k i/100ms
          cache_key_fast    21.723k i/100ms
    -------------------------------------------------
               cache_key     59.422k (± 7.2%) i/s -    299.150k
          cache_key_fast    543.243k (± 9.2%) i/s -      2.694M

    Comparison:
          cache_key_fast:   543243.4 i/s
               cache_key:    59422.0 i/s - 9.14x slower

To see the impact on real code I applied these changes and benchmarked
Issue#referenced_merge_requests. For an issue referencing 10 merge
requests these changes shaved off between 40 and 60 milliseconds.
2016-08-08 16:49:22 +02:00
Douwe Maan 6d9715d877 Show existing discussion when adding new comment on line with a hidden resolved discussion 2016-07-28 19:28:56 -06:00
Douwe Maan 35ce7aae01 Use sha1 of discussion ID. 2016-07-25 22:51:26 -06:00
Douwe Maan d76d051b22 Collapse/hide resolved discussions 2016-07-25 22:46:13 -06:00
Douwe Maan 46cc034e05 Add resolved_at and resolved_by_id to DiffNote 2016-07-25 22:33:01 -06:00
Douwe Maan bfaacb7bcc Fix bug where replies to commit notes displayed in the MR discussion tab wouldn't show up on the commit page 2016-07-23 14:51:52 -06:00
Douwe Maan 79214be727 Add Discussion model to represent MR/diff discussion 2016-07-20 16:18:18 -06:00
dixpac e21492b810 Fix not normalized emoji paths
* There where path where +1 was stored as +1 not as thumbsup
  that was causing problems such as showing thumbsup icon 2 time.
  I fixed this to always normalize and store +1 as tumbsup
2016-07-14 08:51:00 +02:00
Stan Hu af3727b34a Optimize system note visibility checking by hiding notes that
have been fully redacted and contain cross-project references.

The previous implementation relied on Note#cross_reference_not_visible_for?,
which essentially tries to render all the Markdown references in a system note
and only displays the note if the user can see the referring project. But this
duplicated the work that Banzai::NotesRenderer was doing already. Instead, for
each note we render, we memoize the number of visible user references and
use it later if it is available.

Improves #19273
2016-07-11 15:09:21 -07:00
Douwe Maan 2f30d00432 Add DiffNote model 2016-07-06 18:50:59 -04:00
Douwe Maan a27462a5c6 Extract parts of LegacyDiffNote into DiffOnNote concern and move part of responsibility to other classes 2016-07-06 18:50:59 -04:00
Douwe Maan 3286dd7a1d Don't garbage collect commits that have related DB records like comments 2016-07-04 00:11:33 -04:00
James Lopez f29c30475e use has_many relationship with events 2016-07-01 15:34:10 +02:00
James Lopez 3d2a736679 fixing events for import/export 2016-06-29 10:35:26 +02:00
Yorick Peterse d470f3d195
Support for rendering/redacting multiple documents
This commit changes the way certain documents are rendered (currently
only Notes) and how documents are redacted. Previously both rendering
and redacting would run on a per document basis. The result of this was
that for every document we'd have to run countless queries just to
figure out if we could display a set of links or not.

This commit changes things around so that redacting Markdown documents
is no longer tied into the html-pipeline Gem. This in turn allows it to
redact multiple documents in a single pass, thus reducing the number of
queries needed.

In turn rendering issue/merge request notes has been adjusted to take
advantage of this new setup. Instead of rendering Markdown somewhere
deep down in a view the Markdown is rendered and redacted in the
controller (taking the current user and all that into account). This has
been done in such a way that the "markdown()" helper method can still be
used on its own.

This particular commit also paves the way for caching rendered HTML on
object level. Right now there's an accessor method Note#note_html which
is used for setting/getting the rendered HTML. Once we cache HTML on row
level we can simply change this field to be a column and call a "save"
whenever needed and we're pretty much done.
2016-06-24 11:46:39 +02:00
Paco Guzman 66ec925557 Preload notes/discussions associations (award_emoji: :user) 2016-06-23 21:04:37 +02:00
Z.J. van de Weg e7a27946ea Eager load award emoji on notes
This commit eager loads the award emoji on both the issues and the MRs.
When loading an issue with 108 comments this reduces the query count by
327 queries. On a merge request with the same amount of comments this
saves 148 queries. The large difference is not clear to me at this
point and the total query count is still huge with 387 and 1034
respectively. The biggest problem however, remains the calculation of
participants.
2016-06-23 20:59:34 +02:00
James Lopez 2a747d386d fixed merge conflicts 2016-06-16 14:07:49 +02:00
Z.J. van de Weg 31944179aa Award Emoji can't be awarded on system notes backend 2016-06-15 15:06:34 +02:00
Douglas Barbosa Alexandre 1491767583 Use Issue.visible_to_user in Notes.search to avoid query duplication 2016-06-13 19:32:00 -03:00
Douglas Barbosa Alexandre b56c456750 Project members with guest role can't access confidential issues 2016-06-13 19:32:00 -03:00
James Lopez b07dc938b9 fixed specs and refactored a few things due to recent model changes and merge conflicts 2016-06-13 13:34:36 +02:00
ZJ van de Weg 2f9c2149a3 Backend awardables on comments 2016-06-06 11:03:39 +02:00
Z.J. van de Weg 9d491712cf Merge branch 'master' into awardables 2016-06-03 15:20:11 +02:00
Douwe Maan 2d084dd848 Merge branch 'separate-banzai-references' into 'master'
Separate reference gathering from rendering

This is a required step to allow batch processing when gathering references. This in turn would allow grabbing (for example) all mentioned users of an issue/merge request using a single query.

cc @rspeicher @DouweM 

See merge request !3969
2016-06-01 15:51:59 +00:00
Yorick Peterse 580d250166
Refactor Participable
There are several changes to this module:

1. The use of an explicit stack in Participable#participants
2. Proc behaviour has been changed
3. Batch permissions checking

== Explicit Stack

Participable#participants no longer uses recursion to process "self" and
all child objects, instead it uses an Array and processes objects in
breadth-first order. This allows us to for example create a single
Gitlab::ReferenceExtractor instance and pass this to any Procs. Re-using
a ReferenceExtractor removes the need for running potentially many SQL
queries every time a Proc is called on a new object.

== Proc Behaviour Changed

Previously a Proc in Participable was expected to return an Array of
User instances. This has been changed and instead it's now expected that
a Proc modifies the Gitlab::ReferenceExtractor passed to it. The return
value of the Proc is ignored.

== Permissions Checking

The method Participable#participants uses
Ability.users_that_can_read_project to check if the returned users have
access to the project of "self" _without_ running multiple SQL queries
for every user.
2016-06-01 16:22:35 +02:00
Z.J. van de Weg 91a7b9333b Incorportate feedback 2016-06-01 12:10:08 +02:00
Robert Speicher 613bcdc626 Merge branch 'data_leak' into 'master'
Confidential notes data leak

Fixes part of https://gitlab.com/gitlab-org/gitlab-ee/issues/575

See merge request !1967
2016-05-31 19:35:13 +00:00
Valery Sizov 9154586ce5 Confidential notes data leak 2016-05-31 21:32:53 +03:00
ZJ van de Weg cbd7801b3d Merge branch 'master' into awardables 2016-05-30 18:54:08 +02:00
Grzegorz Bizon 99ef3a84b5 Validate presence of noteable_type in note model 2016-05-29 15:03:00 -04:00
Grzegorz Bizon 21d0cddd45 Do not override foreign attributes in note factory 2016-05-29 15:03:00 -04:00
Grzegorz Bizon 57b551a19f Remove redundant `with_options` from note validators 2016-05-29 15:03:00 -04:00