Commit Graph

217 Commits

Author SHA1 Message Date
GitLab Bot 3209c1a49c Add latest changes from gitlab-org/gitlab@master 2019-11-19 06:06:07 +00:00
GitLab Bot 6d59e98918 Add latest changes from gitlab-org/gitlab@master 2019-10-18 18:06:21 +00:00
GitLab Bot b7e6df1abd Add latest changes from gitlab-org/gitlab@master 2019-10-17 00:07:27 +00:00
GitLab Bot 7bb7a8d529 Add latest changes from gitlab-org/gitlab@master 2019-09-25 03:06:21 +00:00
GitLab Bot 80f61b4035 Add latest changes from gitlab-org/gitlab@master 2019-09-18 14:02:45 +00:00
GitLab Bot b7dfe2ae40 Add latest changes from gitlab-org/gitlab@master 2019-09-13 13:26:31 +00:00
Markus Koller 60755fbc40
Optimize queries for snippet listings
- Avoid N+1 queries for authors and comment counts
- Avoid an additional snippet existence query
2019-09-10 15:24:28 +02:00
Luke Duncalfe 4b9b2a43d0 GraphQL mutations for add, remove and toggle emoji
Adding new `AddAwardEmoji`, `RemoveAwardEmoji` and `ToggleAwardEmoji`
GraphQL mutations.

Adding new `#authorized_find_with_pre_checks!` and (unused, but for
completeness `#authorized_find_with_post_checks!`) authorization
methods. These allow us to perform an authorized find, and run our own
additional checks before or after the authorization runs.

https://gitlab.com/gitlab-org/gitlab-ce/issues/62826
2019-06-28 12:03:33 +12:00
Nick Thomas 013f7cd24c
Inherit from ApplicationRecord instead of ActiveRecord::Base 2019-03-28 16:18:23 +00:00
Rémy Coutable 3a2abc1d50
Enable the Layout/ExtraSpacing cop
Signed-off-by: Rémy Coutable <remy@rymai.me>
2019-01-24 13:05:45 +01:00
Mark Chao ed0d691e0d Block private snippets from being embeddable 2018-12-20 14:32:51 +08:00
Mark Chao 30c6db8f03 Move embeddable? to model to be used outside view 2018-12-20 14:32:51 +08:00
Yorick Peterse d171ff6016
Rewrite SnippetsFinder to improve performance
This completely rewrites the SnippetsFinder class from the ground up in
order to improve its performance. The old code was beyond salvaging. It
was complex, included various Rails 5 workarounds, comments that
shouldn't be necessary, and most important of all: it produced a really
poorly performing database query.

As a result, I opted for rewriting the finder from scratch, instead of
trying to patch the existing code. Instead of trying to reuse as many
existing methods as possible, I opted for defining new methods
specifically meant for the SnippetsFinder. This requires some extra code
here and there, but allows us to have much more control over the
resulting SQL queries. It is these changes that then allow us to produce
a _much_ more efficient query.

To illustrate how bad the old query was, we will use my own snippets as
an example. Currently I have 52 snippets, most of which are global ones.
To retrieve these, you would run the following Ruby code:

    user = User.find_by(username: 'yorickpeterse')

    SnippetsFinder.new(user, author: user).execute

On GitLab.com the resulting query will take between 10 and 15 seconds to
run, producing the query plan found at
https://explain.depesz.com/s/Y5IX. Apart from the long execution time,
the total number of buffers (the sum of all shared hits) is around 185
GB, though the real number is probably (hopefully) much lower as I doubt
simply summing these numbers produces the true total number of buffers
used.

The new query's plan can be found at https://explain.depesz.com/s/wHdN,
and this query takes between 10 and 100-ish milliseconds to run. The
total number of buffers used is only about 30 MB.

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/52639
2018-11-05 14:28:29 +01:00
Jan Provaznik c1c1496405 Redact unsubscribe links in issuable texts
It's possible that user pastes accidentally also unsubscribe link
which is included in footer of notification emails. This unsubscribe
link contains personal token which attacker then use to act as the
original user (e.g. for sending comments under his/her identity).
2018-10-23 21:20:20 +02:00
Yorick Peterse 8a72f5c427
Added FromUnion to easily select from a UNION
This commit adds the module `FromUnion`, which provides the class method
`from_union`. This simplifies the process of selecting data from the
result of a UNION, and reduces the likelihood of making mistakes. As a
result, instead of this:

    union = Gitlab::SQL::Union.new([foo, bar])

    Foo.from("(#{union.to_sql}) #{Foo.table_name}")

We can now write this instead:

    Foo.from_union([foo, bar])

This commit also includes some changes to make this new setup work
properly. For example, a bug in Rails 4
(https://github.com/rails/rails/issues/24193) would break the use of
`from("sub-query-here").includes(:relation)` in certain cases. There was
also a CI query which appeared to repeat a lot of conditions from an
outer query on an inner query, which isn't necessary.

Finally, we include a RuboCop cop to ensure developers use this new
module, instead of using Gitlab::SQL::Union directly.

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/51307
2018-09-17 12:39:43 +02:00
Rémy Coutable f20a40f4a1 Merge branch 'frozen-string-enable-app-models' into 'master'
Enable frozen string in app/models/*.rb

See merge request gitlab-org/gitlab-ce!20851
2018-08-02 09:11:52 +00:00
Bob Van Landuyt f1d3ea63cf Show the status of a user in interactions
The status is shown for
- The author of a commit when viewing a commit
- Notes on a commit (regular/diff)
- The user that triggered a pipeline when viewing a pipeline
- The author of a merge request when viewing a merge request
- The author of notes on a merge request (regular/diff)
- The author of an issue when viewing an issue
- The author of notes on an issue
- The author of a snippet when viewing a snippet
- The author of notes on a snippet
- A user's profile page
- The list of members of a group/user
2018-07-30 15:01:26 +02:00
gfyoung 50abbd3e53 Enable frozen string in app/models/*.rb
Partially addresses #47424.
2018-07-26 16:55:41 -07:00
Jan Provaznik dcdfa04b32 Add discussion API
* adds basic discussions API for issues and snippets
* reorganizes notes specs (so same tests can be used for all noteable types - issues, MRs, snippets)
2018-03-07 12:27:50 +01:00
Douwe Maan 5e9e56924a Merge branch 'security-10-4-25223-snippets-finder-doesnt-obey-feature-visibility' into 'security-10-4'
[Port for security-10-4]: Makes SnippetFinder ensure feature visibility
2018-02-09 12:04:05 -06:00
Mario de la Ossa eaada9d706 use Gitlab::UserSettings directly as a singleton instead of including/extending it 2018-02-02 18:39:55 +00:00
Douwe Maan da42dfb3cf Use fuzzy search with minimum length of 3 characters where appropriate 2017-11-27 11:29:40 +01:00
Douwe Maan aedd2cfa5b Use Gitlab::SQL::Pattern where appropriate 2017-11-24 17:28:50 +01:00
Jarka Kadlecova e826c5d091 Fix link text from group context 2017-11-23 12:59:14 +01:00
Sean McGivern 5883ce95ef `current_application_settings` belongs on `Gitlab::CurrentSettings`
The initializers including this were doing so at the top level, so every object
loaded after them had a `current_application_settings` method. However, if
someone had rack-attack enabled (which was loaded before these initializers), it
would try to load the API, and fail, because `Gitlab::CurrentSettings` didn't
have that method.

To fix this:

1. Don't include `Gitlab::CurrentSettings` at the top level. We do not need
   `Object.new.current_application_settings` to work.
2. Make `Gitlab::CurrentSettings` explicitly `extend self`, as we already use it
   like that in several places.
3. Change the initializers to use that new form.
2017-08-31 13:38:33 +01:00
Yorick Peterse 8fbbf41e29
Added Cop to blacklist the use of `dependent:`
This is allowed for existing instances so we don't end up 76 offenses
right away, but for new code one should _only_ use this if they _have_
to remove non database data. Even then it's usually better to do this in
a service class as this gives you more control over how to remove the
data (e.g. in bulk).
2017-07-06 12:01:36 +02:00
Tiago Botelho 1207d451ed Removes file_name_regex from Gitlab::Regex 2017-07-05 19:10:14 +01:00
Phil Hughes 563ea34692 Merge branch '12910-snippets-description' into 'master'
Support descriptions for snippets

Closes #31894

See merge request !11071
2017-06-07 09:26:48 +00:00
Luke "Jared" Bennett 07c984d81c
Port fix-realtime-edited-text-for-issues 9-2-stable fix to master. 2017-05-31 11:35:05 +01:00
Jarka Kadlecova 4464c22d6d Support descriptions for snippets 2017-05-31 07:17:03 +02:00
Douwe Maan ad309f5d11 Merge branch 'snippets-finder-visibility' into 'security'
Refactor snippets finder & dont return internal snippets for external users

See merge request !2094
2017-05-10 16:48:18 +02:00
blackst0ne 154610c92b Fix feature tests 2017-05-04 14:54:25 +11:00
Douwe Maan 60ebd101d0 Use blob viewers for snippets 2017-04-30 11:21:20 -05:00
Douwe Maan 08bbb9fce6
Add option to start a new discussion on an MR 2017-04-05 17:44:14 +01:00
Oswaldo Ferreira d730b69eb2 Spam check only when spammable attributes have changed 2017-03-21 14:20:15 -03:00
Toon Claes a3fdd6acd2 Use string based `visibility` getter & setter
Add `visibility` & `visibility=` methods to the
`Gitlab::VisibilityLevel` module so the `visibility_level` can be
get/set with a string value.
2017-03-02 12:15:25 +01:00
Sean McGivern c63194ce6f Check public snippets for spam
Apply the same spam checks to public snippets (either personal snippets
that are public, or public snippets on public projects) as to issues on
public projects.
2017-02-02 10:23:51 +00:00
Sean McGivern f799585c41 Keep snippet visibility on error
When a snippet is submitted, but there's an error, we didn't keep the
visibility level. As the default is private, this means that submitting
a public snippet that failed would then fall back to being a private
snippet.
2017-02-02 10:23:50 +00:00
James Lopez 112f470572 Fix cross-project references copy to include the project reference
Also added relevant specs and refactored to_references in a bunch of places to be more consistent.
2017-01-03 13:01:46 +01:00
Rémy Coutable 5186618bb0 Merge branch '25209-improve-length-validators' into 'master'
Use :maximum instead of :within for length validators with a 0..N range

Closes #25209

See merge request !7894
2016-12-07 10:31:21 +00:00
Rémy Coutable 4e249d5bae
Use :maximum instead of :within for length validators with a 0..N range
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-12-06 10:23:17 +01:00
Oswaldo Ferreira f272ee6eba Add shorthand support to gitlab markdown references 2016-12-02 19:18:17 -02:00
Felipe Artur 9c740133a3 Allow JIRA references for project snippets 2016-11-21 12:09:41 -02:00
Nick Thomas e94cd6fdfe Add markdown cache columns to the database, but don't use them yet
This commit adds a number of _html columns and, with the exception of Note,
starts updating them whenever the content of their partner fields changes.

Note has a collision with the note_html attr_accessor; that will be fixed later

A background worker for clearing these cache columns is also introduced - use
`rake cache:clear` to set it off. You can clear the database or Redis caches
separately by running `rake cache:clear:db` or `rake cache:clear:redis`,
respectively.
2016-10-07 02:54:25 +01:00
Z.J. van de Weg 25004cbc32 Snippets get award emoji! 👍 2016-09-19 19:47:43 +03:00
Rémy Coutable 0d0f8a3b7d Merge branch 'feature/custom-highlighting' into 'master'
Add custom highlighting via .gitattributes

## What does this MR do?
Allows user control of language selection via a `gitlab-language` entry in `.gitattributes`

## Are there points in the code the reviewer needs to double check?
(paired with @stanhu)

## Why was this MR needed?
Guessing languages by filename is fraught and often wrong. In one project, `foo.pl` may be perl, and in another it may be prolog. Users might have a Thingfile that needs ruby highlighting, or depend on things that can't work in general, like `*.C` (capitalized) mapping to C++ instead of C.

This allows the user to override language choice so they never have to look at a mis-highlighted file.

## What are the relevant issue numbers?
https://github.com/jneen/rouge/issues/494
https://gitlab.com/gitlab-org/gitlab-ce/issues/13818 (*.tpl can't in general map to Smarty)
https://gitlab.com/gitlab-org/gitlab-ce/issues/13615 (in cases we don't have a language and mis-identify it, users could map to 'text' to turn off highlighting)

## Screenshots (if relevant)

## Does this MR meet the acceptance criteria?

- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- [x] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)
- [x] API support added (N/A)
- [x] Tests
  - [x] Added for this feature/bug
  - [x] All builds are passing
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

See merge request !4606
2016-06-28 08:42:42 +00:00
http://jneen.net/ e7b512efa6 move the path alias to a more appropriate location 2016-06-27 14:17:49 -07:00
http://jneen.net/ 5ff8371c5e add an alias for Snippet#path 2016-06-27 14:17:49 -07:00
Douglas Barbosa Alexandre 256cd8e498 Fix visibility of private project snippets for members when searching 2016-06-22 20:09:19 -03:00
Douglas Barbosa Alexandre 8f9b64c720 Fix internal snippets can be searched by anyone 2016-06-22 17:44:24 -03:00
Alejandro Rodríguez ad83c30855 Remove `projects` inclusion in `notes_with_associations` to skip some unnecessary queries
`notes_with_associations` are used for `participant` declarations, but `Participable`
only really cares about the target entity project, and not the participants
projects.

`notes_with_associations` are also used in `Commit::has_been_reverted?` which
employs the reference extractor of the commit, so no references to the notes
projects are made there (`Mentionable::all_references` cares only about the
`author` and other `attr_mentionable`). A paralel situation occurs on
`Issue::referenced_merge_requests`.
2016-06-08 10:26:05 -04: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
Jeroen van Baarsen f1479b56b7
Remove the annotate gem and delete old annotations
In 8278b763d9 the default behaviour of annotation
has changes, which was causing a lot of noise in diffs. We decided in #17382
that it is better to get rid of the whole annotate gem, and instead let people
look at schema.rb for the columns in a table.

Fixes: #17382
2016-05-09 18:00:28 +02:00
Zeger-Jan van de Weg 47da013cf8 Annotate the models 2016-05-06 08:27:46 +02:00
Zeger-Jan van de Weg ad99404d25 Properly handle bigger files 2016-04-28 21:28:39 +02:00
Yorick Peterse e7849b0b25 Memoize reference_pattern/link_reference_pattern
These methods are called quite often in loops so by memoizing their
output we can reduce timings a bit.
2016-04-01 11:13:30 +02:00
Yorick Peterse d7d5937531 Removed arel_table receiver from search methods
We can just use "arel_table" in these cases instead of
"SomeClass.arel_table".
2016-03-11 15:25:23 -05:00
Yorick Peterse 1f5284e5dd Use ILIKE/LIKE for searching snippets
Previously this used a regular LIKE which is case-sensitive on
PostgreSQL. This ensures that for both PostgreSQL and MySQL the
searching is case-insensitive similar to searching for projects.
2016-03-11 15:25:21 -05:00
Robert Speicher 836d593033 Remove `Snippet#expires_at`
This was removed from the interface in
https://github.com/gitlabhq/gitlabhq/pull/6027 but its implementation
lingered around for two years.
2016-03-05 18:12:17 -05:00
Douwe Maan f3ea06eb7f Autolink first so we don't pick up numeric anchors as issue references. 2015-12-01 15:53:32 +01:00
Douwe Maan d6a5b45c8e Recognize issue/MR/snippet/commit links as references. 2015-11-30 21:36:34 +01:00
Nicolas aecc989154 Make snippet filename optional.
Fixes #2384.
2015-06-20 01:06:57 +02:00
Robert Speicher 1a9da9178c Surround Project.reference_pattern in parenthesis inside other patterns 2015-05-26 15:49:22 -04:00
Robert Speicher b88da58cb6 Add `reference_pattern` to Referable models 2015-05-26 15:48:32 -04:00
Robert Speicher 8773f339a3 Minor model spec cleanups
Snippet model was missing project association
2015-05-26 15:48:30 -04:00
Robert Speicher c0faf91ff2 Add `to_reference` for models that support references
Now there is a single source of information for which attribute a model
uses to be referenced, and its special character.
2015-05-26 15:48:30 -04:00
Douwe Maan e739eb036d Move participants method to shared Participable concern. 2015-04-24 12:30:36 +02:00
Douwe Maan 630e879066 Clean up code somewhat. 2015-04-17 11:03:33 +02:00
Douwe Maan a9b04c4536 Fix Snippet#participants. 2015-04-15 18:59:01 +02:00
Douwe Maan 7633d60268 Include snippet author in recipients of snippet note notification. 2015-04-15 17:57:31 +02:00
Douwe Maan dfe0f9eedf Use more specific regexes. 2015-03-27 11:09:29 +01:00
Stan Hu 7e204cf389 Added comment notification events to HipChat and Slack services.
Supports four different event types all bundled under the "note" event type:

- comments on a commit
- comments on an issue
- comments on a merge request
- comments on a code snippet
2015-03-06 06:54:00 -08:00
Dmitriy Zaporozhets 62ed1c537e Explicitly define ordering in models using default_scope 2015-02-05 14:20:55 -08:00
Dmitriy Zaporozhets cc39bca3fa Rubocop: Style/AlignHash enabled 2015-02-02 21:15:44 -08:00
Dmitriy Zaporozhets 118bd7178b
Sanitize snippet file name in raw headers
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2014-12-12 13:28:48 +02:00
Dmitriy Zaporozhets f28a12a559
Add strict validation to snippet file names
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2014-12-12 13:15:42 +02:00
Valery Sizov 82c938ad75 annotate 2014-10-09 18:22:20 +03:00
Valery Sizov 47f539f5a6 Snippets: public/internal/private 2014-10-09 17:09:53 +03:00
Valery Sizov fd8d1d9b62 Snippets: rename public to internal 2014-10-07 11:54:00 +03:00
Charles Bushong 4cca1b050a Adding in snippet search functionality
http://feedback.gitlab.com/forums/176466-general/suggestions/5529795-search-though-snippets
2014-08-29 15:32:07 -04:00
Dmitriy Zaporozhets 2acde87e0d
Project hook, milestone, snippet strong params
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2014-06-26 18:51:11 +03:00
Dmitriy Zaporozhets 98ba075c32
User model to strong params. Comment other attr_accessible to let tests run
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2014-06-26 15:11:45 +03:00
Marin Jankovski 18b1f171bd Rename snippets scopes to plural names. 2014-06-04 08:37:19 +02:00
Marin Jankovski 90c2e0d971 Replace now forbidden keywords public and private for snippets scope 2014-06-03 11:37:23 +02:00
Dmitriy Zaporozhets 36f861f1b1
Re-annotate models
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2014-04-09 15:05:03 +03:00
Dmitriy Zaporozhets de855e2420
Default value for Snippet#private
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2014-03-17 15:50:16 +02:00
Dmitriy Zaporozhets 8dd37afe34 Reannotate 2013-08-21 12:34:02 +03:00
Dmitriy Zaporozhets 6e35aceff2 Annotated 2013-06-19 15:40:33 +03:00
Andrew8xx8 3e695acfa2 Notes fixed 2013-03-25 15:58:09 +04:00
Andrew8xx8 3b6228dc27 It's better to use STI instead 2013-03-25 00:37:14 +04:00
Andrew8xx8 8adf9c7956 Additional scopes added 2013-03-25 00:23:12 +04:00
Andrew8xx8 770f262a6a Private added to attr_accessible 2013-03-25 00:22:45 +04:00
Andrew8xx8 bc7c5f87bb Project snippet moved to separate model 2013-03-24 19:26:49 +04:00
Andrew8xx8 b5db541338 All scopes must be in lambdas 2013-02-12 11:16:45 +04:00
Valeriy Sizov 69ec189ad2 remove length of snippet content 2013-01-22 17:10:00 +02:00
Dmitriy Zaporozhets 190e483fb4 Rework of milestones 2012-12-14 08:34:05 +03:00
Dmitriy Zaporozhets 95c23b2f97 Annotated. schema updated 2012-11-19 21:24:05 +03:00
Dmitriy Zaporozhets 41e53eb980 Annotated 2012-10-09 11:14:17 +03:00
Andrey Kumanyaev df7c52489a simple refactoring 2012-10-09 04:10:04 +04:00
Nihad Abbasov 841e4fbd08 cosmetical cleanup of models 2012-09-27 02:05:53 -07:00
Nihad Abbasov 2a4359a572 annotate models 2012-09-27 02:05:53 -07:00
Nihad Abbasov 83efcabc82 set activerecord whitelist_attributes to true 2012-09-26 11:18:35 -07:00
Robert Speicher 7754189187 Fully embrace Ruby 1.9 hash syntax
Didn't bother with files in db/, config/, or features/
2012-08-10 18:25:15 -04:00
randx 6abc649590 Reannotated 2012-06-26 21:23:09 +03:00
Dmitriy Zaporozhets 9c76bd9540 Project linguist integration 2012-04-21 01:26:22 +03:00
Dmitriy Zaporozhets 10df55e11d Added missing dependent for notes assoc 2011-12-18 12:10:20 +02:00
Dmitriy Zaporozhets 0712e78597 Snippet restyle 2011-12-15 08:12:24 +02:00
Dmitriy Zaporozhets 23a1ba7362 Fix different styles/button positions 2011-12-08 01:35:57 +02:00
Nihad Abbasov b6cdd1c819 test expired snippets 2011-10-28 00:25:50 +05:00
Nihad Abbasov 325b84545c don't count expired snippets 2011-10-27 13:12:12 +05:00
Nihad Abbasov 000c032482 display recent snippets at top 2011-10-27 12:14:50 +05:00
Nihad Abbasov 8e1e17763f implement snippets lifetime 2011-10-27 11:46:21 +05:00
Nihad Abbasov d62200cad4 clean-up code
* Remove trailing whitespace
  * Converts hard-tabs into two-space soft-tabs
  * Remove consecutive blank lines
2011-10-26 18:46:25 +05:00
gitlabhq b3279b9b51 moved from albino -> pygments.rb 2011-10-22 14:08:03 +03:00
gitlabhq c463eeb090 refactoring 2011-10-20 22:00:00 +03:00
gitlabhq d03f2687c5 annotated 2011-10-17 18:31:21 +03:00
gitlabhq 9265de3d25 snippets are ready 2011-10-17 00:07:10 +03:00