Commit graph

25 commits

Author SHA1 Message Date
Yorick Peterse
26378511fe
Refactor Project#create_or_update_import_data
In https://gitlab.com/gitlab-org/release/framework/issues/28 we found
that this method was changed a lot over the years: 43 times if our
calculations were correct. Looking at the method, it had quite a few
branches going on:

    def create_or_update_import_data(data: nil, credentials: nil)
      return if data.nil? && credentials.nil?

      project_import_data = import_data || build_import_data

      if data
        project_import_data.data ||= {}
        project_import_data.data = project_import_data.data.merge(data)
      end

      if credentials
        project_import_data.credentials ||= {}
        project_import_data.credentials =
          project_import_data.credentials.merge(credentials)
      end

      project_import_data
    end

If we turn the || and ||= operators into regular if statements, we can
see a bit more clearly that this method has quite a lot of branches in
it:

    def create_or_update_import_data(data: nil, credentials: nil)
      if data.nil? && credentials.nil?
        return
      else
        project_import_data =
          if import_data
            import_data
          else
            build_import_data
          end

        if data
          if project_import_data.data
            # nothing
          else
            project_import_data.data = {}
          end

          project_import_data.data =
            project_import_data.data.merge(data)
        end

        if credentials
          if project_import_data.credentials
            # nothing
          else
            project_import_data.credentials = {}
          end

          project_import_data.credentials =
            project_import_data.credentials.merge(credentials)
        end

        project_import_data
      end
    end

The number of if statements and branches here makes it easy to make
mistakes. To resolve this, we refactor this code in such a way that we
can get rid of all but the first `if data.nil? && credentials.nil?`
statement. We can do this by simply sending `to_h` to `nil` in the right
places, which removes the need for statements such as `if data`.

Since this data gets written to a database, in ProjectImportData we do
make sure to not write empty Hash values. This requires an `unless`
(which is really a `if !`), but the resulting code is still very easy to
read.
2018-12-11 14:46:35 +01:00
gfyoung
50abbd3e53 Enable frozen string in app/models/*.rb
Partially addresses #47424.
2018-07-26 16:55:41 -07:00
Stan Hu
b5c706326a Upgrade to Ruby 2.4.4
Fixes that make this work:

* A change in Ruby (ce635262f5)
requires passing in the exact required length for OpenSSL keys and IVs.

* Ensure the secrets.yml is generated before any prepended modules are
loaded. This is done by renaming the `secret_token.rb` initializer to
`01_secret_token.rb`, which is a bit ugly but involves the least impact on
other files.
2018-05-29 15:19:33 -07:00
Nick Thomas
da5262f4e6 Backport changes in https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/2551 to CE 2017-08-07 19:17:11 +01:00
Yorick Peterse
e1a3bf30b6
Rename ActiverecordSerialize cop
This cop has been renamed to ActiveRecordSerialize to match the way
"ActiveRecord" is usually written.
2017-07-06 12:01:36 +02:00
Yorick Peterse
cd74c1434e
Added Cop to blacklist the use of serialize
This Cop blacklists the use of ActiveRecord's "serialize" method, except
for cases where we already use this.
2017-05-31 14:03:37 +02:00
James Lopez
31c95aa031 add missing attribute to attr_encrypted so it is fully backwards-compatible 2016-06-28 09:55:19 +02:00
Connor Shea
d287315dbf
Upgrade attr_encrypted and encryptor
attr_encrypted (1.3.4 => 3.0.1) Changelog:
https://github.com/attr-encrypted/attr_encrypted/blob/master/CHANGELOG.m
d

attr_encrypted 2.x included a vulnerability, so that major version is
skipped. 3.x requires that the algorithm and mode used by each
encrypted attribute is specified explicitly.

`nil` is no longer a valid value for the encrypted_value_iv field, so
it’s changed to a randomly generated string.
2016-05-30 13:51:21 -06: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
Dmitriy Zaporozhets
2dcd3f29dd
Annotate models
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-05-06 16:13:35 +02:00
Zeger-Jan van de Weg
47da013cf8 Annotate the models 2016-05-06 08:27:46 +02:00
Rémy Coutable
1fbea7cec9
Remove useless require 'file_size_validator' causing warnings
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-04-19 11:40:16 +02:00
James Lopez
be834c4de9 changed a few things based on feedback 2016-04-11 11:13:51 +02:00
James Lopez
05be0c306e removed TODO [ci skip] 2016-04-06 11:13:19 +02:00
James Lopez
b97654393e fix some issues with credentials 2016-04-06 10:36:30 +02:00
James Lopez
5e51fce4dc some refactoring to symbolise keys across importers and left a TODO 2016-04-05 15:41:15 +02:00
James Lopez
6d12d79d29 fix fogbugz import 2016-04-01 12:04:41 +02:00
James Lopez
dff4050f1d fixed some rubocop warnings 2016-03-21 17:29:19 +01:00
James Lopez
bd8a77674f fixed few issues with the migration 2016-03-21 17:16:27 +01:00
James Lopez
735563329d refactored a bunch of stuff based on MR feedback 2016-03-07 12:50:35 +01:00
James Lopez
7085850c50 fix specs 2016-03-04 18:37:00 +01:00
James Lopez
c2b33d3b71 added import url exposer to construct URL withunencrypted credentials 2016-03-04 16:23:19 +01:00
James Lopez
cefefb2ade WIP - refactored migration and updated project_import_data with encrypted att 2016-03-03 18:10:06 +01:00
Stan Hu
a3157626f1 Re-annotate models 2015-05-03 13:38:27 -07:00
Douwe Maan
7d98c8842d Move import data out of project so it doesn't take ages to load. 2015-04-17 14:49:00 +02:00