Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
d91836d9
Commit
d91836d9
authored
Feb 27, 2020
by
Pavel Shutsin
Committed by
Stan Hu
Mar 04, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add user_type field for service users
It will be used for code review analytics to detect service users
parent
355289e4
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
105 additions
and
6 deletions
+105
-6
app/models/user.rb
app/models/user.rb
+2
-1
app/models/user_bot_type_enums.rb
app/models/user_bot_type_enums.rb
+3
-1
app/models/user_type_enums.rb
app/models/user_type_enums.rb
+18
-0
db/migrate/20200304085423_add_user_type.rb
db/migrate/20200304085423_add_user_type.rb
+21
-0
db/migrate/20200304090155_add_user_type_index.rb
db/migrate/20200304090155_add_user_type_index.rb
+17
-0
db/schema.rb
db/schema.rb
+3
-1
ee/app/models/ee/user_bot_type_enums.rb
ee/app/models/ee/user_bot_type_enums.rb
+3
-1
ee/app/models/ee/user_type_enums.rb
ee/app/models/ee/user_type_enums.rb
+24
-0
ee/changelogs/unreleased/202680-allow-users-to-be-marked-as-bots.yml
...gs/unreleased/202680-allow-users-to-be-marked-as-bots.yml
+5
-0
ee/lib/analytics/merge_request_metrics_calculator.rb
ee/lib/analytics/merge_request_metrics_calculator.rb
+3
-1
ee/spec/factories/users.rb
ee/spec/factories/users.rb
+4
-0
ee/spec/models/ee/note_spec.rb
ee/spec/models/ee/note_spec.rb
+2
-1
No files found.
app/models/user.rb
View file @
d91836d9
...
...
@@ -60,6 +60,7 @@ class User < ApplicationRecord
MINIMUM_INACTIVE_DAYS
=
180
enum
bot_type:
::
UserBotTypeEnums
.
bots
enum
user_type:
::
UserTypeEnums
.
types
# Override Devise::Models::Trackable#update_tracked_fields!
# to limit database writes to at most once every hour
...
...
@@ -336,7 +337,7 @@ class User < ApplicationRecord
scope
:with_dashboard
,
->
(
dashboard
)
{
where
(
dashboard:
dashboard
)
}
scope
:with_public_profile
,
->
{
where
(
private_profile:
false
)
}
scope
:bots
,
->
{
where
.
not
(
bot_type:
nil
)
}
scope
:humans
,
->
{
where
(
bot_type:
nil
)
}
scope
:humans
,
->
{
where
(
user_type:
nil
,
bot_type:
nil
)
}
scope
:with_expiring_and_not_notified_personal_access_tokens
,
->
(
at
)
do
where
(
'EXISTS (?)'
,
...
...
app/models/user_bot_type_enums.rb
View file @
d91836d9
...
...
@@ -2,7 +2,9 @@
module
UserBotTypeEnums
def
self
.
bots
# When adding a new key, please ensure you are not conflicting with EE-only keys in app/models/user_bot_type_enums.rb
# When adding a new key, please ensure you are not conflicting
# with EE-only keys in app/models/user_type_enums.rb
# or app/models/user_bot_type_enums.rb
{
alert_bot:
2
}
...
...
app/models/user_type_enums.rb
0 → 100644
View file @
d91836d9
# frozen_string_literal: true
module
UserTypeEnums
def
self
.
types
# When adding a new key, please ensure you are not conflicting
# with EE-only keys in app/models/user_type_enums.rb
# or app/models/user_bot_type_enums.rb
bots
end
def
self
.
bots
{
AlertBot
:
2
}
end
end
UserTypeEnums
.
prepend_if_ee
(
'EE::UserTypeEnums'
)
db/migrate/20200304085423_add_user_type.rb
0 → 100644
View file @
d91836d9
# frozen_string_literal: true
class
AddUserType
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
with_lock_retries
do
add_column
:users
,
:user_type
,
:integer
,
limit:
2
end
end
def
down
with_lock_retries
do
remove_column
:users
,
:user_type
end
end
end
db/migrate/20200304090155_add_user_type_index.rb
0 → 100644
View file @
d91836d9
# frozen_string_literal: true
class
AddUserTypeIndex
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_concurrent_index
:users
,
:user_type
end
def
down
remove_concurrent_index
:users
,
:user_type
end
end
db/schema.rb
View file @
d91836d9
...
...
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2020_03_0
3_074328
)
do
ActiveRecord
::
Schema
.
define
(
version:
2020_03_0
4_090155
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"pg_trgm"
...
...
@@ -4325,6 +4325,7 @@ ActiveRecord::Schema.define(version: 2020_03_03_074328) do
t
.
string
"last_name"
,
limit:
255
t
.
string
"static_object_token"
,
limit:
255
t
.
integer
"role"
,
limit:
2
t
.
integer
"user_type"
,
limit:
2
t
.
index
"lower((name)::text)"
,
name:
"index_on_users_name_lower"
t
.
index
[
"accepted_term_id"
],
name:
"index_users_on_accepted_term_id"
t
.
index
[
"admin"
],
name:
"index_users_on_admin"
...
...
@@ -4347,6 +4348,7 @@ ActiveRecord::Schema.define(version: 2020_03_03_074328) do
t
.
index
[
"state"
],
name:
"index_users_on_state_and_internal_ee"
,
where:
"((ghost IS NOT TRUE) AND (bot_type IS NULL))"
t
.
index
[
"static_object_token"
],
name:
"index_users_on_static_object_token"
,
unique:
true
t
.
index
[
"unconfirmed_email"
],
name:
"index_users_on_unconfirmed_email"
,
where:
"(unconfirmed_email IS NOT NULL)"
t
.
index
[
"user_type"
],
name:
"index_users_on_user_type"
t
.
index
[
"username"
],
name:
"index_users_on_username"
t
.
index
[
"username"
],
name:
"index_users_on_username_trigram"
,
opclass: :gin_trgm_ops
,
using: :gin
end
...
...
ee/app/models/ee/user_bot_type_enums.rb
View file @
d91836d9
...
...
@@ -9,7 +9,9 @@ module EE
override
:bots
def
bots
# When adding a new key, please ensure you are not redefining a key that already exists in app/models/user_bot_type_enums.rb
# When adding a new key, please ensure you are not conflicting
# with EE-only keys in app/models/user_type_enums.rb
# or app/models/user_bot_type_enums.rb
super
.
merge
(
support_bot:
1
,
visual_review_bot:
3
...
...
ee/app/models/ee/user_type_enums.rb
0 → 100644
View file @
d91836d9
# frozen_string_literal: true
module
EE
module
UserTypeEnums
extend
ActiveSupport
::
Concern
class_methods
do
extend
::
Gitlab
::
Utils
::
Override
override
:types
def
types
# When adding a new key, please ensure you are not conflicting
# with EE-only keys in app/models/user_type_enums.rb
# or app/models/user_bot_type_enums.rb
super
.
merge
(
ServiceUser
:
4
)
end
override
:bots
def
bots
super
.
merge
(
SupportBot
:
1
,
VisualReviewBot
:
3
)
end
end
end
end
ee/changelogs/unreleased/202680-allow-users-to-be-marked-as-bots.yml
0 → 100644
View file @
d91836d9
---
title
:
Allow users to be marked as service users
merge_request
:
202680
author
:
type
:
other
ee/lib/analytics/merge_request_metrics_calculator.rb
View file @
d91836d9
...
...
@@ -19,7 +19,9 @@ module Analytics
# rubocop: disable CodeReuse/ActiveRecord
def
first_comment_at
merge_request
.
related_notes
.
by_humans
.
where
.
not
(
author_id:
merge_request
.
author_id
).
fresh
.
first
&
.
created_at
merge_request
.
related_notes
.
by_humans
.
where
.
not
(
author_id:
merge_request
.
author_id
)
.
fresh
.
first
&
.
created_at
end
# rubocop: enable CodeReuse/ActiveRecord
...
...
ee/spec/factories/users.rb
View file @
d91836d9
...
...
@@ -16,6 +16,10 @@ FactoryBot.modify do
)
end
end
trait
:service_user
do
user_type
{
:ServiceUser
}
end
end
factory
:omniauth_user
do
...
...
ee/spec/models/ee/note_spec.rb
View file @
d91836d9
...
...
@@ -94,10 +94,11 @@ describe Note do
end
describe
'.by_humans'
do
it
'
return human notes only
'
do
it
'
excludes notes by bots and service users
'
do
user_note
=
create
(
:note
)
create
(
:system_note
)
create
(
:note
,
author:
create
(
:user
,
:bot
))
create
(
:note
,
author:
create
(
:user
,
:service_user
))
expect
(
described_class
.
by_humans
).
to
match_array
([
user_note
])
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment