Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'dev' of https://github.com/liufengyun/jobsworth into dev

  • Loading branch information...
commit 20b6d116661445ad4fc5824ff443b5971cd8d018 2 parents 6e0c99d + ee015f8
@ari authored
View
4 app/controllers/customers_controller.rb
@@ -83,14 +83,14 @@ def search
elsif params[:entity] =~ /resource/
@resources = current_user.company.resources.where('lower(name) like ?', '%' + search_criteria.downcase + '%') if current_user.use_resources?
elsif params[:entity] =~ /project/
- @projects = current_user.company.projects.where('lower(name) like ?', '%' + search_criteria.downcase + '%')
+ @projects = current_user.projects.where('lower(name) like ?', '%' + search_criteria.downcase + '%')
end
else
@customers = current_user.company.customers.where('lower(name) LIKE ?', '%' + search_criteria.downcase + '%').where(:active => true)
@users = current_user.company.users.where('lower(name) LIKE ?', '%' + search_criteria.downcase + '%').where(:active => true)
@tasks = Task.all_accessed_by(current_user).where('lower(tasks.name) LIKE ?', '%' + search_criteria.downcase + '%').where("tasks.status = 0")
@resources = current_user.company.resources.where('lower(name) like ?', '%' + search_criteria.downcase + '%') if current_user.use_resources?
- @projects = current_user.company.projects.where('lower(name) like ?', '%' + search_criteria.downcase + '%')
+ @projects = current_user.projects.where('lower(name) like ?', '%' + search_criteria.downcase + '%')
end
end
View
10 app/controllers/milestones_controller.rb
@@ -116,13 +116,11 @@ def access_to_milestones
def set_due_at
unless params[:milestone][:due_at].blank?
begin
- # if due_at is not changed in edit, it should include time part
- format = "#{current_user.date_format} #{current_user.time_format}"
- @milestone.due_at = DateTime.strptime(params[:milestone][:due_at], format).ago(tz.current_period.utc_total_offset)
- rescue
- # if due_at is changed or set the first time, it only has date part, understood as midnight at user's timezone
+ # Only care about the date part, parse the input date string into DateTime in UTC.
+ # Later, the date part will be converted from DateTime to string display in UTC, so that it doesn't change.
format = "#{current_user.date_format}"
- @milestone.due_at = DateTime.strptime(params[:milestone][:due_at], format).ago(tz.current_period.utc_total_offset - 24*3600)
+ @milestone.due_at = DateTime.strptime(params[:milestone][:due_at], format).ago(-12.hours)
+ rescue
end
end
end
View
10 app/controllers/tasks_controller.rb
@@ -414,13 +414,11 @@ def check_if_user_has_projects
def task_due_calculation(params, task, tz)
if !params[:task].nil? && !params[:task][:due_at].nil? && params[:task][:due_at].length > 0
begin
- # if due_at is not changed in edit, it should include time part
- format = "#{current_user.date_format} #{current_user.time_format}"
- due_date = DateTime.strptime(params[:task][:due_at], format).ago(tz.current_period.utc_total_offset)
- rescue
- # if due_at is changed or set, it only has date part, understood as midnight at user's timezone
+ # Only care about the date part, parse the input date string into DateTime in UTC.
+ # Later, the date part will be converted from DateTime to string display in UTC, so that it doesn't change.
format = "#{current_user.date_format}"
- due_date = DateTime.strptime(params[:task][:due_at], format).ago(tz.current_period.utc_total_offset - 24*3600)
+ due_date = DateTime.strptime(params[:task][:due_at], format).ago(-12.hours)
+ rescue
end
task.due_at = due_date unless due_date.nil?
end
View
8 app/helpers/tasks_helper.rb
@@ -137,7 +137,7 @@ def due_date_field(task, permissions)
options = {
:id => "due_at", :title => date_tooltip.html_safe,
:size => 12,
- :value => (task.due_at.nil? ? "" : tz.utc_to_local(task.due_at).strftime("#{current_user.date_format} #{current_user.time_format}")),
+ :value => (task.due_at.nil? ? "" : task.due_at.utc.strftime("#{current_user.date_format}")),
:autocomplete => "off"
}
options = options.merge(permissions['edit'])
@@ -147,7 +147,9 @@ def due_date_field(task, permissions)
def target_date(task)
return _("Not set") if task.target_date.nil?
- return formatted_date_for_current_user(task.target_date)
+ # Before, the input date string is parsed into DateTime in UTC.
+ # Now, the date part is converted from DateTime to string display in UTC, so that it doesn't change.
+ return task.target_date.utc.strftime("#{current_user.date_format}")
end
def target_date_tooltip(task)
@@ -225,7 +227,7 @@ def last_comment_date(task)
def milestones_to_select_tag(milestones)
options = ([[_("[None]"), "0"]] + milestones.collect {|c| [ h(c.name), c.id, c.due_at ] }).map do |array|
- date = array[2].nil? ? _('Not set') : tz.utc_to_local(array[2]).strftime("#{current_user.date_format} #{current_user.time_format}")
+ date = array[2].nil? ? _('Not set') : array[2].utc.strftime("#{current_user.date_format}")
selected = if (@task.milestone_id == array[1]) || (@task.milestone_id.nil? && array[1] == "0") then "selected=\"selected\"" else "" end
text = if @task.milestone_id == array[1] and @task.milestone.complete? then "[#{array[0]}]" else array[0] end
"<option value=\"#{array[1]}\" data-date=\"#{date}\" #{selected}>#{text}</option>"
View
2  app/models/milestone.rb
@@ -25,7 +25,7 @@ def percent_complete
end
def complete?
- (self.completed_tasks == self.total_tasks && self.completed_tasks > 0) || (!self.completed_at.nil?)
+ !self.completed_at.nil?
end
def escape_twice(attr)
View
3  app/views/milestones/_form.html.erb
@@ -11,8 +11,7 @@
<div class="control-group">
<label for="milestone_due_at"><%=_ 'Due Date' %></label>
<div class="controls">
- <%= text_field 'milestone', 'due_at', :class=>:datefield, :value=> (@milestone.due_date.nil? ? "" : tz.utc_to_local(@milestone.due_date).strftime("#{current_user.date_format} #{current_user.time_format}")) %>
- <small>(new date is intepreted as Midnight, <%= current_user.time_zone %>)</small>
+ <%= text_field 'milestone', 'due_at', :class=>:datefield, :value=> (@milestone.due_date.nil? ? "" : @milestone.due_date.utc.strftime("#{current_user.date_format}")) %>
</div>
</div>
View
2  app/views/milestones/get_milestones.json.erb
@@ -1,7 +1,7 @@
<% @milestones = @milestones.map { |m|
{ :text => m.name.gsub(/"/,'\"'),
:value => m.id.to_s,
- :date=> (m.due_at.nil? ? _("Not set") : tz.utc_to_local(m.due_at).strftime("#{current_user.date_format} #{current_user.time_format}") )
+ :date=> (m.due_at.nil? ? _("Not set") : m.due_at.utc.strftime("#{current_user.date_format}") )
}.to_json }
@milestones = @milestones.join(", ")
%>
View
2  app/views/projects/edit.html.erb
@@ -26,7 +26,7 @@
<% @completed_milestones = Milestone.where("project_id = ? AND completed_at IS NOT NULL", @project.id).count %>
<% if @completed_milestones.to_i > 0 %>
- <%= link_to _('show %d completed', @completed_milestones), {:controller => 'milestones', :action => 'list_completed'}, :id => @project, :class => "pull-right" %>
+ <%= link_to _('show %d completed', @completed_milestones), {:controller => 'milestones', :action => 'list_completed', :id => @project.id}, :class => "pull-right" %>
<% end %>
View
1  app/views/tasks/_details.html.erb
@@ -30,7 +30,6 @@
</div>
<div id="due_date_field" style="display:none;" class="pull-left">
<%= due_date_field(@task, perms) %>
- <p>Midnight, <%= current_user.time_zone %></p>
</div>
</div>
View
43 test/functional/customers_controller_test.rb
@@ -1,7 +1,7 @@
require "test_helper"
class CustomersControllerTest < ActionController::TestCase
- fixtures :users, :companies, :tasks, :customers
+ fixtures :users, :companies, :tasks, :customers, :projects
def setup
@user = users(:tester)
@@ -93,7 +93,46 @@ def setup
assert_filter_failed
end
- signed_in_admin_context do
+ signed_in_admin_context do
+ should "unable to see invisible project in search results" do
+ project_hash = {
+ name: 'permission test project - invisible',
+ description: 'Some description',
+ customer_id: customers(:internal_customer).id,
+ company_id: companies(:cit).id
+ }
+
+ project = Project.create(project_hash)
+ assert Project.find(project.id)
+
+ get :search, :term => "test"
+ assert_nil assigns["projects"].detect {|p| p.name == project.name}
+ end
+
+ should "be able to see visible projects in search results" do
+ project_hash = {
+ name: 'permission test project - visible',
+ description: 'Some description',
+ customer_id: customers(:internal_customer).id,
+ company_id: companies(:cit).id
+ }
+
+ project = Project.create(project_hash)
+ assert Project.find(project.id)
+
+ permission = ProjectPermission.new
+ permission.user_id = @user.id
+ permission.project_id = project.id
+ permission.company_id = @user.company_id
+ permission.can_comment = 1
+ permission.can_work = 1
+ permission.can_close = 1
+ permission.save
+
+ get :search, :term => "test"
+ assert assigns["projects"].detect {|p| p.name == project.name}
+ end
+
context "with resources access" do
setup do
@user.use_resources = true
View
2  test/integration/task_edit_test.rb
@@ -14,7 +14,7 @@ def self.make_test_for_due_date
fill_in "due_at", :with => "27/07/2009"
click_button "Save"
visit "/tasks/edit/#{@task.task_num}"
- assert_equal find_by_id("due_at").value, "28/07/2009 00:00"
+ assert_equal find_by_id("due_at").value, "27/07/2009"
end
end
context "A logged in user" do
Please sign in to comment.
Something went wrong with that request. Please try again.