Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
cdefad88
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cdefad88
编写于
8月 26, 2012
作者:
D
Dmitriy Zaporozhets
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1305 from AlexDenisov/project_access_notifications
Project access notifications
上级
2c32574a
3c96d1f0
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
96 addition
and
1 deletion
+96
-1
app/mailers/notify.rb
app/mailers/notify.rb
+7
-0
app/observers/users_project_observer.rb
app/observers/users_project_observer.rb
+9
-0
app/views/notify/project_access_granted_email.html.haml
app/views/notify/project_access_granted_email.html.haml
+14
-0
config/application.rb
config/application.rb
+1
-1
spec/factories.rb
spec/factories.rb
+5
-0
spec/mailers/notify_spec.rb
spec/mailers/notify_spec.rb
+20
-0
spec/observers/users_project_observer_spec.rb
spec/observers/users_project_observer_spec.rb
+40
-0
未找到文件。
app/mailers/notify.rb
浏览文件 @
cdefad88
...
...
@@ -76,6 +76,13 @@ class Notify < ActionMailer::Base
mail
(
to:
recipient
(
recipient_id
),
subject:
subject
(
"changed issue #
#{
@issue
.
id
}
"
,
@issue
.
title
))
end
def
project_access_granted_email
(
user_project_id
)
@users_project
=
UsersProject
.
find
user_project_id
@project
=
@users_project
.
project
mail
(
to:
@users_project
.
user
.
email
,
subject:
subject
(
"access to project was granted"
))
end
private
# Look up a User by their ID and return their email address
...
...
app/observers/users_project_observer.rb
0 → 100644
浏览文件 @
cdefad88
class
UsersProjectObserver
<
ActiveRecord
::
Observer
def
after_create
(
users_project
)
Notify
.
project_access_granted_email
(
users_project
.
id
).
deliver
end
def
after_update
(
users_project
)
Notify
.
project_access_granted_email
(
users_project
.
id
).
deliver
end
end
app/views/notify/project_access_granted_email.html.haml
0 → 100644
浏览文件 @
cdefad88
%td
.content
{
align:
"left"
,
style:
"font-family: Helvetica, Arial, sans-serif; padding: 20px 0 0;"
,
valign:
"top"
,
width:
"600"
}
%table
{
border:
"0"
,
cellpadding:
"0"
,
cellspacing:
"0"
,
style:
"color: #717171; font: normal 11px Helvetica, Arial, sans-serif; margin: 0; padding: 0;"
,
width:
"600"
}
%tr
%td
{
style:
"font-size: 1px; line-height: 1px;"
,
width:
"21"
}
%td
{
align:
"left"
,
style:
"padding: 20px 0 0;"
}
%h2
{
style:
"color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "
}
=
"You got granted
#{
@users_project
.
project_access_human
}
access to project"
%td
{
style:
"font-size: 1px; line-height: 1px;"
,
width:
"21"
}
%tr
%td
{
style:
"font-size: 1px; line-height: 1px;"
,
width:
"21"
}
%td
{
align:
"left"
,
style:
"padding: 20px 0 0;"
}
%h2
{
style:
"color:#646464 !important; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "
}
=
link_to_gfm
truncate
(
@project
.
name
,
length:
45
),
project_url
(
@project
),
title:
@project
.
name
%br
config/application.rb
浏览文件 @
cdefad88
...
...
@@ -23,7 +23,7 @@ module Gitlab
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
config
.
active_record
.
observers
=
:mailer_observer
,
:activity_observer
,
:project_observer
,
:key_observer
,
:issue_observer
,
:user_observer
,
:system_hook_observer
config
.
active_record
.
observers
=
:mailer_observer
,
:activity_observer
,
:project_observer
,
:key_observer
,
:issue_observer
,
:user_observer
,
:system_hook_observer
,
:users_project_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
...
...
spec/factories.rb
浏览文件 @
cdefad88
...
...
@@ -90,3 +90,8 @@ Factory.add(:milestone, Milestone) do |obj|
obj
.
title
=
Faker
::
Lorem
.
sentence
obj
.
due_date
=
Date
.
today
+
1
.
month
end
Factory
.
add
(
:users_project
,
UsersProject
)
do
|
obj
|
obj
.
user
=
Factory
:user
obj
.
project
=
Factory
:project
end
spec/mailers/notify_spec.rb
浏览文件 @
cdefad88
...
...
@@ -145,6 +145,26 @@ describe Notify do
end
end
describe
'project access changed'
do
let
(
:project
)
{
Factory
.
create
(
:project
,
path:
"Fuu"
,
code:
"Fuu"
)
}
let
(
:user
)
{
Factory
.
create
:user
}
let
(
:users_project
)
{
Factory
.
create
(
:users_project
,
project:
project
,
user:
user
)
}
subject
{
Notify
.
project_access_granted_email
(
users_project
.
id
)
}
it
'has the correct subject'
do
should
have_subject
/access to project was granted/
end
it
'contains name of project'
do
should
have_body_text
/
#{
project
.
name
}
/
end
it
'contains new user role'
do
should
have_body_text
/
#{
users_project
.
project_access_human
}
/
end
end
context
'items that are noteable, the email for a note'
do
let
(
:note_author
)
{
Factory
.
create
(
:user
,
name:
'author_name'
)
}
let
(
:note
)
{
Factory
.
create
(
:note
,
project:
project
,
author:
note_author
)
}
...
...
spec/observers/users_project_observer_spec.rb
0 → 100644
浏览文件 @
cdefad88
require
'spec_helper'
describe
UsersProjectObserver
do
let
(
:user
)
{
Factory
.
create
:user
}
let
(
:project
)
{
Factory
.
create
(
:project
,
code:
"Fuu"
,
path:
"Fuu"
)
}
let
(
:users_project
)
{
Factory
.
create
(
:users_project
,
project:
project
,
user:
user
)}
subject
{
UsersProjectObserver
.
instance
}
describe
"#after_create"
do
it
"should called when UsersProject created"
do
subject
.
should_receive
(
:after_create
)
UsersProject
.
observers
.
enable
:users_project_observer
do
Factory
.
create
(
:users_project
,
project:
project
,
user:
user
)
end
end
it
"should send email to user"
do
Notify
.
should_receive
(
:project_access_granted_email
).
with
(
users_project
.
id
).
and_return
(
double
(
deliver:
true
))
subject
.
after_create
(
users_project
)
end
end
describe
"#after_update"
do
it
"should called when UsersProject updated"
do
subject
.
should_receive
(
:after_update
)
UsersProject
.
observers
.
enable
:users_project_observer
do
users_project
.
update_attribute
(
:project_access
,
40
)
end
end
it
"should send email to user"
do
Notify
.
should_receive
(
:project_access_granted_email
).
with
(
users_project
.
id
).
and_return
(
double
(
deliver:
true
))
subject
.
after_update
(
users_project
)
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录