Defect #44361 » news_preview_cross_project_v2.patch
| app/assets/javascripts/application-legacy.js | ||
|---|---|---|
| 1226 | 1226 |
var jstBlock = tab.parents('.jstBlock');
|
| 1227 | 1227 | |
| 1228 | 1228 |
var element = encodeURIComponent(jstBlock.find('.wiki-edit').val());
|
| 1229 |
var attachments = form.find('.attachments_fields input').serialize();
|
|
| 1229 |
var params = form.find('.attachments_fields input, [data-preview-param]').serialize();
|
|
| 1230 | 1230 | |
| 1231 | 1231 |
$.ajax({
|
| 1232 | 1232 |
url: url, |
| 1233 | 1233 |
type: 'post', |
| 1234 |
data: "text=" + element + '&' + attachments,
|
|
| 1234 |
data: "text=" + element + '&' + params,
|
|
| 1235 | 1235 |
success: function(data){
|
| 1236 | 1236 |
jstBlock.find('.wiki-preview').html(data);
|
| 1237 | 1237 |
} |
| app/controllers/previews_controller.rb | ||
|---|---|---|
| 47 | 47 | |
| 48 | 48 |
def find_project |
| 49 | 49 |
project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id] |
| 50 |
@project = Project.find(project_id) |
|
| 50 |
@project = Project.find(project_id) if project_id.present?
|
|
| 51 | 51 |
rescue ActiveRecord::RecordNotFound |
| 52 | 52 |
render_404 |
| 53 | 53 |
end |
| app/views/news/_form.html.erb | ||
|---|---|---|
| 4 | 4 |
<% if @project.nil? %> |
| 5 | 5 |
<p> |
| 6 | 6 |
<label><%= l(:field_project) %> <span class="required">*</span></label> |
| 7 |
<%= select_tag :project_id, options_for_select(project_tree_options_for_select(Project.allowed_to(:manage_news).to_a), Project.allowed_to(:manage_news).first), {:required => true} %>
|
|
| 7 |
<%= select_tag :project_id, options_for_select(project_tree_options_for_select(Project.allowed_to(:manage_news).to_a), Project.allowed_to(:manage_news).first), {:required => true, :data => {:preview_param => true}} %>
|
|
| 8 | 8 |
<%= hidden_field_tag :cross_project, 1, id: nil %> |
| 9 | 9 |
</p> |
| 10 | 10 |
<% end %> |
| test/functional/previews_controller_test.rb | ||
|---|---|---|
| 109 | 109 |
assert_select 'p', :text => /News description/ |
| 110 | 110 |
end |
| 111 | 111 | |
| 112 |
def test_preview_new_news_without_project_should_be_successful |
|
| 113 |
@request.session[:user_id] = 2 |
|
| 114 |
post( |
|
| 115 |
:news, |
|
| 116 |
:params => {
|
|
| 117 |
:text => 'News description', |
|
| 118 |
} |
|
| 119 |
) |
|
| 120 |
assert_response :success |
|
| 121 |
assert_select 'p', :text => /News description/ |
|
| 122 |
end |
|
| 123 | ||
| 124 |
def test_preview_news_with_invalid_project_should_return_404 |
|
| 125 |
@request.session[:user_id] = 2 |
|
| 126 |
post( |
|
| 127 |
:news, |
|
| 128 |
:params => {
|
|
| 129 |
:project_id => 'invalid', |
|
| 130 |
:text => 'News description', |
|
| 131 |
} |
|
| 132 |
) |
|
| 133 |
assert_response :not_found |
|
| 134 |
end |
|
| 135 | ||
| 136 |
def test_preview_new_news_should_render_project_scoped_syntax |
|
| 137 |
@request.session[:user_id] = 2 |
|
| 138 |
post( |
|
| 139 |
:news, |
|
| 140 |
:params => {
|
|
| 141 |
:project_id => '1', |
|
| 142 |
:text => '[[CookBook documentation]]' |
|
| 143 |
} |
|
| 144 |
) |
|
| 145 |
assert_response :success |
|
| 146 |
assert_select 'a.wiki-page[href=?]', '/projects/ecookbook/wiki/CookBook_documentation' |
|
| 147 |
end |
|
| 148 | ||
| 149 |
def test_preview_new_news_without_project_should_not_render_project_scoped_syntax |
|
| 150 |
@request.session[:user_id] = 2 |
|
| 151 |
post( |
|
| 152 |
:news, |
|
| 153 |
:params => {
|
|
| 154 |
:text => '[[CookBook documentation]]' |
|
| 155 |
} |
|
| 156 |
) |
|
| 157 |
assert_response :success |
|
| 158 |
assert_select 'a.wiki-page', :count => 0 |
|
| 159 |
end |
|
| 160 | ||
| 112 | 161 |
def test_preview_existing_news |
| 113 | 162 |
get( |
| 114 | 163 |
:news, |
- « Previous
- 1
- 2
- Next »