Feature #38951 » Add_history_to_project.patch
app/controllers/journals_controller.rb (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → app/controllers/journals_controller.rb (revision 41653+:c704208ed465+) | ||
---|---|---|
43 | 43 |
end |
44 | 44 | |
45 | 45 |
def diff |
46 |
@issue = @journal.issue
|
|
46 |
@journalized = @journal.journalized
|
|
47 | 47 |
if params[:detail_id].present? |
48 | 48 |
@detail = @journal.details.find_by_id(params[:detail_id]) |
49 | 49 |
else |
50 | 50 |
@detail = @journal.details.detect {|d| d.property == 'attr' && d.prop_key == 'description'} |
51 | 51 |
end |
52 |
unless @issue && @detail
|
|
52 |
unless @journalized && @detail
|
|
53 | 53 |
render_404 |
54 | 54 |
return false |
55 | 55 |
end |
56 | 56 |
if @detail.property == 'cf' |
57 |
unless @detail.custom_field && @detail.custom_field.visible_by?(@issue.project, User.current)
|
|
57 |
unless @detail.custom_field && @detail.custom_field.visible_by?(@journalized.project, User.current)
|
|
58 | 58 |
raise ::Unauthorized |
59 | 59 |
end |
60 | 60 |
end |
app/controllers/projects_controller.rb (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → app/controllers/projects_controller.rb (revision 41653+:c704208ed465+) | ||
---|---|---|
20 | 20 |
class ProjectsController < ApplicationController |
21 | 21 |
menu_item :overview |
22 | 22 |
menu_item :settings, :only => :settings |
23 |
menu_item :project_history, :only => :history |
|
23 | 24 |
menu_item :projects, :only => [:index, :new, :copy, :create] |
24 | 25 | |
25 | 26 |
before_action :find_project, |
... | ... | |
27 | 28 |
before_action :authorize, |
28 | 29 |
:except => [:index, :autocomplete, :list, :new, :create, :copy, |
29 | 30 |
:archive, :unarchive, |
30 |
:destroy] |
|
31 |
:destroy, :history]
|
|
31 | 32 |
before_action :authorize_global, :only => [:new, :create] |
32 | 33 |
before_action :require_admin, :only => [:copy, :archive, :unarchive] |
33 | 34 |
accept_rss_auth :index |
... | ... | |
212 | 213 |
end |
213 | 214 | |
214 | 215 |
def update |
216 |
@project.init_journal(User.current) |
|
215 | 217 |
@project.safe_attributes = params[:project] |
216 | 218 |
if @project.save |
217 | 219 |
respond_to do |format| |
... | ... | |
292 | 294 |
@project = nil |
293 | 295 |
end |
294 | 296 | |
297 |
def history |
|
298 |
@journals = @project.visible_journals_with_index |
|
299 |
end |
|
300 | ||
295 | 301 |
private |
296 | 302 | |
297 | 303 |
# Returns the ProjectEntry scope for index |
app/helpers/journals_helper.rb (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → app/helpers/journals_helper.rb (revision 41653+:c704208ed465+) | ||
---|---|---|
29 | 29 |
def render_journal_actions(issue, journal, options={}) |
30 | 30 |
links = [] |
31 | 31 |
dropbown_links = [] |
32 |
indice = journal.indice || @journal.issue.visible_journals_with_index.find{|j| j.id == @journal.id}.indice
|
|
32 |
indice = journal.indice || @journal.journalized.visible_journals_with_index.find{|j| j.id == @journal.id}.indice
|
|
33 | 33 | |
34 | 34 |
dropbown_links << copy_object_url_link(issue_url(issue, anchor: "note-#{indice}", only_path: false)) |
35 | 35 |
if journal.notes.present? |
app/models/journal.rb (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → app/models/journal.rb (revision 41653+:c704208ed465+) | ||
---|---|---|
24 | 24 |
# added as a quick fix to allow eager loading of the polymorphic association |
25 | 25 |
# since always associated to an issue, for now |
26 | 26 |
belongs_to :issue, :foreign_key => :journalized_id |
27 |
belongs_to :project, :foreign_key => :journalized_id |
|
27 | 28 | |
28 | 29 |
belongs_to :user |
29 | 30 |
has_many :details, :class_name => "JournalDetail", :dependent => :delete_all, :inverse_of => :journal |
app/models/project.rb (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → app/models/project.rb (revision 41653+:c704208ed465+) | ||
---|---|---|
51 | 51 |
has_one :repository, lambda {where(:is_default => true)} |
52 | 52 |
has_many :repositories, :dependent => :destroy |
53 | 53 |
has_many :changesets, :through => :repository |
54 |
has_many :journals, :as => :journalized, :dependent => :destroy, :inverse_of => :journalized |
|
55 | ||
54 | 56 |
has_one :wiki, :dependent => :destroy |
55 | 57 |
# Custom field for the project issues |
56 | 58 |
has_and_belongs_to_many :issue_custom_fields, |
... | ... | |
87 | 89 |
:if => proc {|project| project.saved_change_to_inherit_members?} |
88 | 90 |
after_save :remove_inherited_member_roles, :add_inherited_member_roles, |
89 | 91 |
:if => proc {|project| project.saved_change_to_parent_id?} |
92 |
after_save :create_journal |
|
90 | 93 |
after_update :update_versions_from_hierarchy_change, |
91 | 94 |
:if => proc {|project| project.saved_change_to_parent_id?} |
92 | 95 |
before_destroy :delete_all_members |
... | ... | |
991 | 994 |
end |
992 | 995 |
end |
993 | 996 | |
997 |
# Returns the journals that are visible to user with their index |
|
998 |
# Used to display the issue history |
|
999 |
def visible_journals_with_index(user=User.current) |
|
1000 |
result = journals. |
|
1001 |
preload(:details). |
|
1002 |
preload(:user => :email_address). |
|
1003 |
reorder(:created_on, :id).to_a |
|
1004 | ||
1005 |
result.each_with_index {|j, i| j.indice = i + 1} |
|
1006 | ||
1007 |
unless user.allowed_to?(:view_private_notes, project) |
|
1008 |
result.select! do |journal| |
|
1009 |
!journal.private_notes? || journal.user == user |
|
1010 |
end |
|
1011 |
end |
|
1012 |
Journal.preload_journals_details_custom_fields(result) |
|
1013 |
result.select! {|journal| journal.notes? || journal.visible_details.any?} |
|
1014 |
result |
|
1015 |
end |
|
1016 | ||
1017 |
def init_journal(user, notes = "") |
|
1018 |
@current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes) |
|
1019 |
end |
|
1020 | ||
1021 |
# Returns the current journal or nil if it's not initialized |
|
1022 |
def current_journal |
|
1023 |
@current_journal |
|
1024 |
end |
|
1025 | ||
1026 |
# Returns the names of attributes that are journalized when updating the issue |
|
1027 |
def journalized_attribute_names |
|
1028 |
names = Project.column_names - %w(id lft rgt created_on updated_on closed_on) |
|
1029 |
names |
|
1030 |
end |
|
1031 | ||
994 | 1032 |
private |
995 | 1033 | |
996 | 1034 |
def update_inherited_members |
... | ... | |
1295 | 1333 |
end |
1296 | 1334 |
update_attribute :status, STATUS_ARCHIVED |
1297 | 1335 |
end |
1336 | ||
1337 |
# Saves the changes in a Journal |
|
1338 |
# Called after_save |
|
1339 |
def create_journal |
|
1340 |
if current_journal |
|
1341 |
current_journal.save |
|
1342 |
end |
|
1343 |
end |
|
1298 | 1344 |
end |
app/views/journals/diff.html.erb (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → app/views/journals/diff.html.erb (revision 41653+:c704208ed465+) | ||
---|---|---|
1 |
<h2><%= @issue.tracker %> #<%= @issue.id %></h2>
|
|
1 |
<h2><%= link_to @journalized %></h2>
|
|
2 | 2 |
<p><%= authoring @journal.created_on, @journal.user, :label => :label_updated_time_by %></p> |
3 | 3 | |
4 | 4 |
<pre class="text-diff"><%= @diff.to_html %></pre> |
5 | 5 | |
6 | 6 |
<p> |
7 |
<%= link_to(l(:button_back), issue_path(@issue),
|
|
7 |
<%= link_to(l(:button_back), '#',
|
|
8 | 8 |
:onclick => 'if (document.referrer != "") {history.back(); return false;}') %> |
9 | 9 |
</p> |
10 | 10 | |
11 |
<% html_title "#{@issue.tracker.name} ##{@issue.id}: #{@issue.subject}" %> |
|
11 |
<% html_title @journalized %> |
/dev/null (revision 41653+:c704208ed465+) → app/views/projects/history.html.erb (revision 41653+:c704208ed465+) | ||
---|---|---|
1 |
<% for journal in @journals %> |
|
2 |
<div id="change-<%= journal.id %>" class="<%= journal.css_classes %>"> |
|
3 |
<div id="note-<%= journal.indice %>"> |
|
4 |
<div class="contextual"> |
|
5 |
<a href="#note-<%= journal.indice %>" class="journal-link">#<%= journal.indice %></a> |
|
6 |
</div> |
|
7 |
<h4 class='note-header'> |
|
8 |
<%= avatar(journal.user) %> |
|
9 |
<%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %> |
|
10 |
</h4> |
|
11 | ||
12 |
<% if journal.details.any? %> |
|
13 |
<ul class="details"> |
|
14 |
<% details_to_strings(journal.visible_details).each do |string| %> |
|
15 |
<li><%= string %></li> |
|
16 |
<% end %> |
|
17 |
</ul> |
|
18 |
<% end %> |
|
19 |
</div> |
|
20 |
</div> |
|
21 |
<%= call_hook(:view_project_history_journal_bottom, { :journal => journal }) %> |
|
22 |
<% end %> |
config/locales/en.yml (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → config/locales/en.yml (revision 41653+:c704208ed465+) | ||
---|---|---|
598 | 598 |
label_project: Project |
599 | 599 |
label_project_new: New project |
600 | 600 |
label_project_plural: Projects |
601 |
label_project_history: History |
|
602 | ||
601 | 603 |
label_x_projects: |
602 | 604 |
zero: no projects |
603 | 605 |
one: 1 project |
config/locales/fa.yml (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → config/locales/fa.yml (revision 41653+:c704208ed465+) | ||
---|---|---|
552 | 552 |
label_project: پروژه |
553 | 553 |
label_project_new: پروژه جدید |
554 | 554 |
label_project_plural: پروژهها |
555 |
label_project_history: سابقه پروژه |
|
555 | 556 |
label_x_projects: |
556 | 557 |
zero: بدون پروژه |
557 | 558 |
one: "۱ پروژه" |
config/routes.rb (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → config/routes.rb (revision 41653+:c704208ed465+) | ||
---|---|---|
265 | 265 |
get 'projects/:id/activity', :to => 'activities#index', :as => :project_activity |
266 | 266 |
get 'activity', :to => 'activities#index' |
267 | 267 | |
268 |
get 'projects/:id/history', :to => 'projects#history', :as => :project_history |
|
269 | ||
268 | 270 |
# repositories routes |
269 | 271 |
get 'projects/:id/repository/:repository_id/statistics', :to => 'repositories#stats' |
270 | 272 |
get 'projects/:id/repository/:repository_id/graph', :to => 'repositories#graph' |