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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
cc2daa74
Commit
cc2daa74
authored
Sep 15, 2017
by
haseeb
Committed by
Rémy Coutable
Sep 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created services for keys
parent
ff7eb46d
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
103 additions
and
49 deletions
+103
-49
app/controllers/admin/deploy_keys_controller.rb
app/controllers/admin/deploy_keys_controller.rb
+2
-3
app/controllers/profiles/gpg_keys_controller.rb
app/controllers/profiles/gpg_keys_controller.rb
+2
-2
app/controllers/profiles/keys_controller.rb
app/controllers/profiles/keys_controller.rb
+2
-2
app/controllers/projects/deploy_keys_controller.rb
app/controllers/projects/deploy_keys_controller.rb
+1
-1
app/models/deploy_key.rb
app/models/deploy_key.rb
+0
-6
app/models/gpg_key.rb
app/models/gpg_key.rb
+0
-5
app/models/key.rb
app/models/key.rb
+0
-5
app/services/deploy_keys/create_service.rb
app/services/deploy_keys/create_service.rb
+7
-0
app/services/gpg_keys/create_service.rb
app/services/gpg_keys/create_service.rb
+9
-0
app/services/keys/base_service.rb
app/services/keys/base_service.rb
+13
-0
app/services/keys/create_service.rb
app/services/keys/create_service.rb
+9
-0
changelogs/unreleased/35917_create_services_for_keys.yml
changelogs/unreleased/35917_create_services_for_keys.yml
+4
-0
spec/models/gpg_key_spec.rb
spec/models/gpg_key_spec.rb
+0
-12
spec/models/key_spec.rb
spec/models/key_spec.rb
+0
-12
spec/services/deploy_keys/create_service_spec.rb
spec/services/deploy_keys/create_service_spec.rb
+12
-0
spec/services/gpg_keys/create_service_spec.rb
spec/services/gpg_keys/create_service_spec.rb
+21
-0
spec/services/keys/create_service_spec.rb
spec/services/keys/create_service_spec.rb
+21
-0
spec/services/notification_service_spec.rb
spec/services/notification_service_spec.rb
+0
-1
No files found.
app/controllers/admin/deploy_keys_controller.rb
View file @
cc2daa74
...
...
@@ -10,9 +10,8 @@ class Admin::DeployKeysController < Admin::ApplicationController
end
def
create
@deploy_key
=
deploy_keys
.
new
(
create_params
.
merge
(
user:
current_user
))
if
@deploy_key
.
save
@deploy_key
=
DeployKeys
::
CreateService
.
new
(
current_user
,
create_params
.
merge
(
public:
true
)).
execute
if
@deploy_key
.
persisted?
redirect_to
admin_deploy_keys_path
else
render
'new'
...
...
app/controllers/profiles/gpg_keys_controller.rb
View file @
cc2daa74
...
...
@@ -7,9 +7,9 @@ class Profiles::GpgKeysController < Profiles::ApplicationController
end
def
create
@gpg_key
=
current_user
.
gpg_keys
.
new
(
gpg_key_params
)
@gpg_key
=
GpgKeys
::
CreateService
.
new
(
current_user
,
gpg_key_params
).
execute
if
@gpg_key
.
save
if
@gpg_key
.
persisted?
redirect_to
profile_gpg_keys_path
else
@gpg_keys
=
current_user
.
gpg_keys
.
select
(
&
:persisted?
)
...
...
app/controllers/profiles/keys_controller.rb
View file @
cc2daa74
...
...
@@ -11,9 +11,9 @@ class Profiles::KeysController < Profiles::ApplicationController
end
def
create
@key
=
current_user
.
keys
.
new
(
key_params
)
@key
=
Keys
::
CreateService
.
new
(
current_user
,
key_params
).
execute
if
@key
.
save
if
@key
.
persisted?
redirect_to
profile_key_path
(
@key
)
else
@keys
=
current_user
.
keys
.
select
(
&
:persisted?
)
...
...
app/controllers/projects/deploy_keys_controller.rb
View file @
cc2daa74
...
...
@@ -22,7 +22,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
end
def
create
@key
=
DeployKey
.
new
(
create_params
.
merge
(
user:
current_user
))
@key
=
DeployKey
s
::
CreateService
.
new
(
current_user
,
create_params
).
execute
unless
@key
.
valid?
&&
@project
.
deploy_keys
<<
@key
flash
[
:alert
]
=
@key
.
errors
.
full_messages
.
join
(
', '
).
html_safe
...
...
app/models/deploy_key.rb
View file @
cc2daa74
...
...
@@ -28,10 +28,4 @@ class DeployKey < Key
def
can_push_to?
(
project
)
can_push?
&&
has_access_to?
(
project
)
end
private
# we don't want to notify the user for deploy keys
def
notify_user
end
end
app/models/gpg_key.rb
View file @
cc2daa74
...
...
@@ -36,7 +36,6 @@ class GpgKey < ActiveRecord::Base
before_validation
:extract_fingerprint
,
:extract_primary_keyid
after_commit
:update_invalid_gpg_signatures
,
on: :create
after_commit
:notify_user
,
on: :create
def
primary_keyid
super
&
.
upcase
...
...
@@ -107,8 +106,4 @@ class GpgKey < ActiveRecord::Base
# only allows one key
self
.
primary_keyid
=
Gitlab
::
Gpg
.
primary_keyids_from_key
(
key
).
first
end
def
notify_user
NotificationService
.
new
.
new_gpg_key
(
self
)
end
end
app/models/key.rb
View file @
cc2daa74
...
...
@@ -28,7 +28,6 @@ class Key < ActiveRecord::Base
delegate
:name
,
:email
,
to: :user
,
prefix:
true
after_commit
:add_to_shell
,
on: :create
after_commit
:notify_user
,
on: :create
after_create
:post_create_hook
after_commit
:remove_from_shell
,
on: :destroy
after_destroy
:post_destroy_hook
...
...
@@ -118,8 +117,4 @@ class Key < ActiveRecord::Base
"type is forbidden. Must be
#{
allowed_types
}
"
end
def
notify_user
NotificationService
.
new
.
new_key
(
self
)
end
end
app/services/deploy_keys/create_service.rb
0 → 100644
View file @
cc2daa74
module
DeployKeys
class
CreateService
<
Keys
::
BaseService
def
execute
DeployKey
.
create
(
params
.
merge
(
user:
user
))
end
end
end
app/services/gpg_keys/create_service.rb
0 → 100644
View file @
cc2daa74
module
GpgKeys
class
CreateService
<
Keys
::
BaseService
def
execute
key
=
user
.
gpg_keys
.
create
(
params
)
notification_service
.
new_gpg_key
(
key
)
if
key
.
persisted?
key
end
end
end
app/services/keys/base_service.rb
0 → 100644
View file @
cc2daa74
module
Keys
class
BaseService
attr_accessor
:user
,
:params
def
initialize
(
user
,
params
)
@user
,
@params
=
user
,
params
end
def
notification_service
NotificationService
.
new
end
end
end
app/services/keys/create_service.rb
0 → 100644
View file @
cc2daa74
module
Keys
class
CreateService
<
::
Keys
::
BaseService
def
execute
key
=
user
.
keys
.
create
(
params
)
notification_service
.
new_key
(
key
)
if
key
.
persisted?
key
end
end
end
changelogs/unreleased/35917_create_services_for_keys.yml
0 → 100644
View file @
cc2daa74
---
title
:
creation of keys moved to services
merge_request
:
13331
author
:
haseebeqx
spec/models/gpg_key_spec.rb
View file @
cc2daa74
...
...
@@ -140,18 +140,6 @@ describe GpgKey do
end
end
describe
'notification'
,
:mailer
do
let
(
:user
)
{
create
(
:user
)
}
it
'sends a notification'
do
perform_enqueued_jobs
do
create
(
:gpg_key
,
user:
user
)
end
should_email
(
user
)
end
end
describe
'#revoke'
do
it
'invalidates all associated gpg signatures and destroys the key'
do
gpg_key
=
create
:gpg_key
...
...
spec/models/key_spec.rb
View file @
cc2daa74
...
...
@@ -169,16 +169,4 @@ describe Key, :mailer do
expect
(
described_class
.
new
(
key:
"
#{
valid_key
}
"
).
key
).
to
eq
(
valid_key
)
end
end
describe
'notification'
do
let
(
:user
)
{
create
(
:user
)
}
it
'sends a notification'
do
perform_enqueued_jobs
do
create
(
:key
,
user:
user
)
end
should_email
(
user
)
end
end
end
spec/services/deploy_keys/create_service_spec.rb
0 → 100644
View file @
cc2daa74
require
'spec_helper'
describe
DeployKeys
::
CreateService
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:params
)
{
attributes_for
(
:deploy_key
)
}
subject
{
described_class
.
new
(
user
,
params
)
}
it
"creates a deploy key"
do
expect
{
subject
.
execute
}.
to
change
{
DeployKey
.
where
(
params
.
merge
(
user:
user
)).
count
}.
by
(
1
)
end
end
spec/services/gpg_keys/create_service_spec.rb
0 → 100644
View file @
cc2daa74
require
'spec_helper'
describe
GpgKeys
::
CreateService
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:params
)
{
attributes_for
(
:gpg_key
)
}
subject
{
described_class
.
new
(
user
,
params
)
}
context
'notification'
,
:mailer
do
it
'sends a notification'
do
perform_enqueued_jobs
do
subject
.
execute
end
should_email
(
user
)
end
end
it
'creates a gpg key'
do
expect
{
subject
.
execute
}.
to
change
{
user
.
gpg_keys
.
where
(
params
).
count
}.
by
(
1
)
end
end
spec/services/keys/create_service_spec.rb
0 → 100644
View file @
cc2daa74
require
'spec_helper'
describe
Keys
::
CreateService
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:params
)
{
attributes_for
(
:key
)
}
subject
{
described_class
.
new
(
user
,
params
)
}
context
'notification'
,
:mailer
do
it
'sends a notification'
do
perform_enqueued_jobs
do
subject
.
execute
end
should_email
(
user
)
end
end
it
'creates a key'
do
expect
{
subject
.
execute
}.
to
change
{
user
.
keys
.
where
(
params
).
count
}.
by
(
1
)
end
end
spec/services/notification_service_spec.rb
View file @
cc2daa74
...
...
@@ -84,7 +84,6 @@ describe NotificationService, :mailer do
let!
(
:key
)
{
create
(
:personal_key
,
key_options
)
}
it
{
expect
(
notification
.
new_key
(
key
)).
to
be_truthy
}
it
{
should_email
(
key
.
user
)
}
describe
'never emails the ghost user'
do
let
(
:key_options
)
{
{
user:
User
.
ghost
}
}
...
...
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