commit
046b1691d7
@ -0,0 +1,60 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V1 |
||||
|
||||
module ApiController |
||||
|
||||
module ClassMethods |
||||
|
||||
def included(base) |
||||
base.class_eval do |
||||
if ((respond_to? :skip_before_filter) && |
||||
(respond_to? :prepend_before_filter)) |
||||
skip_before_filter :disable_api |
||||
prepend_before_filter :disable_everything_except_api |
||||
end |
||||
end |
||||
end |
||||
|
||||
def permeate_permissions(*filter_names) |
||||
filter_names.each do |filter_name| |
||||
define_method filter_name do |*args, &block| |
||||
begin |
||||
original_controller = params[:controller] |
||||
params[:controller] = original_controller.gsub(api_version, "") |
||||
result = super(*args, &block) |
||||
ensure |
||||
params[:controller] = original_controller |
||||
end |
||||
result |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
extend ClassMethods |
||||
|
||||
def api_version |
||||
/api\/v1\// |
||||
end |
||||
|
||||
permeate_permissions :authorize |
||||
permeate_permissions :authorize_for_user |
||||
permeate_permissions :check_if_deletion_allowed |
||||
permeate_permissions :find_optional_project |
||||
permeate_permissions :find_project |
||||
permeate_permissions :find_time_entry |
||||
|
||||
end |
||||
end |
||||
end |
@ -0,0 +1,151 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V1 |
||||
|
||||
class IssuesController < IssuesController |
||||
|
||||
include ::Api::V1::ApiController |
||||
|
||||
def index |
||||
sort_init(@query.sort_criteria.empty? ? [DEFAULT_SORT_ORDER] : @query.sort_criteria) |
||||
sort_update(@query.sortable_columns) |
||||
|
||||
if @query.valid? |
||||
@issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], |
||||
:order => sort_clause) |
||||
.page(page_param) |
||||
.per_page(per_page_param) |
||||
|
||||
@issue_count_by_group = @query.issue_count_by_group |
||||
|
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
else |
||||
# Send html if the query is not valid |
||||
render(:template => 'issues/index', :layout => !request.xhr?) |
||||
end |
||||
rescue ActiveRecord::RecordNotFound |
||||
render_404 |
||||
end |
||||
|
||||
def show |
||||
@journals = @issue.journals.changing.find(:all, :include => [:user, :journaled], :order => "#{Journal.table_name}.created_at ASC") |
||||
@journals.reverse! if User.current.wants_comments_in_reverse_order? |
||||
@changesets = @issue.changesets.visible.all(:include => [{ :repository => {:project => :enabled_modules} }, :user]) |
||||
@changesets.reverse! if User.current.wants_comments_in_reverse_order? |
||||
|
||||
@relations = @issue.relations(:include => { :other_issue => [:status, |
||||
:priority, |
||||
:tracker, |
||||
{ :project => :enabled_modules }] |
||||
} |
||||
).select{ |r| r.other_issue(@issue) && r.other_issue(@issue).visible? } |
||||
|
||||
@ancestors = @issue.ancestors.visible.all(:include => [:tracker, |
||||
:assigned_to, |
||||
:status, |
||||
:priority, |
||||
:fixed_version, |
||||
:project]) |
||||
@descendants = @issue.descendants.visible.all(:include => [:tracker, |
||||
:assigned_to, |
||||
:status, |
||||
:priority, |
||||
:fixed_version, |
||||
:project]) |
||||
|
||||
@edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
||||
@time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def create |
||||
call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) |
||||
IssueObserver.instance.send_notification = params[:send_notification] == '0' ? false : true |
||||
if @issue.save |
||||
attachments = Attachment.attach_files(@issue, params[:attachments]) |
||||
render_attachment_warning_if_needed(@issue) |
||||
flash[:notice] = l(:notice_successful_create) |
||||
call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) |
||||
respond_to do |format| |
||||
format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) } |
||||
end |
||||
return |
||||
else |
||||
respond_to do |format| |
||||
format.api { render_validation_errors(@issue) } |
||||
end |
||||
end |
||||
end |
||||
|
||||
def update |
||||
update_issue_from_params |
||||
JournalObserver.instance.send_notification = params[:send_notification] == '0' ? false : true |
||||
if @issue.save_issue_with_child_records(params, @time_entry) |
||||
render_attachment_warning_if_needed(@issue) |
||||
flash[:notice] = l(:notice_successful_update) unless @issue.current_journal == @journal |
||||
|
||||
respond_to do |format| |
||||
format.api { head :ok } |
||||
end |
||||
else |
||||
render_attachment_warning_if_needed(@issue) |
||||
flash[:notice] = l(:notice_successful_update) unless @issue.current_journal == @journal |
||||
@journal = @issue.current_journal |
||||
|
||||
respond_to do |format| |
||||
format.api { render_validation_errors(@issue) } |
||||
end |
||||
end |
||||
end |
||||
|
||||
def destroy |
||||
@hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f |
||||
if @hours > 0 |
||||
case params[:todo] |
||||
when 'destroy' |
||||
# nothing to do |
||||
when 'nullify' |
||||
TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) |
||||
when 'reassign' |
||||
reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) |
||||
if reassign_to.nil? |
||||
flash.now[:error] = l(:error_issue_not_found_in_project) |
||||
return |
||||
else |
||||
TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) |
||||
end |
||||
else |
||||
# display the destroy form if it's a user request |
||||
return unless api_request? |
||||
end |
||||
end |
||||
@issues.each do |issue| |
||||
begin |
||||
issue.reload.destroy |
||||
rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists |
||||
# nothing to do, issue was already deleted (eg. by a parent) |
||||
end |
||||
end |
||||
respond_to do |format| |
||||
format.api { head :ok } |
||||
end |
||||
|
||||
end |
||||
|
||||
end |
||||
end |
||||
end |
@ -0,0 +1,34 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V1 |
||||
|
||||
class NewsController < NewsController |
||||
|
||||
include ::Api::V1::ApiController |
||||
|
||||
def index |
||||
scope = @project ? @project.news.visible : News.visible |
||||
|
||||
@newss = scope.includes(:author, :project) |
||||
.order("#{News.table_name}.created_on DESC") |
||||
.page(page_param) |
||||
.per_page(per_page_param) |
||||
|
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
end |
||||
end |
||||
end |
@ -0,0 +1,107 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V1 |
||||
|
||||
class ProjectsController < ProjectsController |
||||
|
||||
include ::Api::V1::ApiController |
||||
|
||||
include PaginationHelper |
||||
|
||||
def index |
||||
@projects = Project.visible.order('lft') |
||||
.page(page_param) |
||||
.per_page(per_page_param) |
||||
|
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def show |
||||
@users_by_role = @project.users_by_role |
||||
@subprojects = @project.children.visible.all |
||||
@news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
||||
@trackers = @project.rolled_up_trackers |
||||
|
||||
cond = @project.project_condition(Setting.display_subprojects_issues?) |
||||
|
||||
@open_issues_by_tracker = Issue.visible.count(:group => :tracker, |
||||
:include => [:project, :status, :tracker], |
||||
:conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false]) |
||||
@total_issues_by_tracker = Issue.visible.count(:group => :tracker, |
||||
:include => [:project, :status, :tracker], |
||||
:conditions => cond) |
||||
|
||||
if User.current.allowed_to?(:view_time_entries, @project) |
||||
@total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f |
||||
end |
||||
|
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def level_list |
||||
respond_to do |format| |
||||
format.api { |
||||
@elements = Project.project_level_list(Project.visible) |
||||
} |
||||
end |
||||
end |
||||
|
||||
def update |
||||
@project.safe_attributes = params[:project] |
||||
if validate_parent_id && @project.save |
||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') |
||||
respond_to do |format| |
||||
format.api { head :ok } |
||||
end |
||||
else |
||||
respond_to do |format| |
||||
format.api { render_validation_errors(@project) } |
||||
end |
||||
end |
||||
end |
||||
|
||||
def destroy |
||||
@project_to_destroy = @project |
||||
@project_to_destroy.destroy |
||||
|
||||
respond_to do |format| |
||||
format.api { head :ok } |
||||
end |
||||
end |
||||
|
||||
def create |
||||
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
||||
@trackers = Tracker.all |
||||
@project = Project.new |
||||
@project.safe_attributes = params[:project] |
||||
|
||||
if validate_parent_id && @project.save |
||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') |
||||
add_current_user_to_project_if_not_admin(@project) |
||||
respond_to do |format| |
||||
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => '/projects', :action => 'show', :id => @project.id) } |
||||
end |
||||
else |
||||
respond_to do |format| |
||||
format.api { render_validation_errors(@project) } |
||||
end |
||||
end |
||||
end |
||||
|
||||
end |
||||
end |
||||
end |
@ -0,0 +1,105 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V1 |
||||
|
||||
class TimelogController < TimelogController |
||||
|
||||
include ::Api::V1::ApiController |
||||
|
||||
def index |
||||
sort_init 'spent_on', 'desc' |
||||
sort_update 'spent_on' => 'spent_on', |
||||
'user' => 'user_id', |
||||
'activity' => 'activity_id', |
||||
'project' => "#{Project.table_name}.name", |
||||
'issue' => 'issue_id', |
||||
'hours' => 'hours' |
||||
|
||||
cond = ARCondition.new |
||||
if @issue |
||||
cond << "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}" |
||||
elsif @project |
||||
cond << @project.project_condition(Setting.display_subprojects_issues?) |
||||
end |
||||
|
||||
retrieve_date_range |
||||
cond << ['spent_on BETWEEN ? AND ?', @from, @to] |
||||
|
||||
respond_to do |format| |
||||
format.api { |
||||
@entry_count = TimeEntry.visible.count(:include => [:project, :issue], :conditions => cond.conditions) |
||||
@entries = TimeEntry.visible.includes(:project, :activity, :user, {:issue => :tracker}) |
||||
.where(cond.conditions) |
||||
.order(sort_clause) |
||||
.page(page_param) |
||||
.per_page(per_page_param) |
||||
} |
||||
end |
||||
end |
||||
|
||||
def show |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def create |
||||
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) |
||||
@time_entry.safe_attributes = params[:time_entry] |
||||
|
||||
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) |
||||
|
||||
if @time_entry.save |
||||
respond_to do |format| |
||||
format.api { render :action => 'show', :status => :created, :location => time_entry_url(@time_entry) } |
||||
end |
||||
else |
||||
respond_to do |format| |
||||
format.api { render_validation_errors(@time_entry) } |
||||
end |
||||
end |
||||
end |
||||
|
||||
def update |
||||
@time_entry.safe_attributes = params[:time_entry] |
||||
|
||||
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) |
||||
|
||||
if @time_entry.save |
||||
respond_to do |format| |
||||
format.api { head :ok } |
||||
end |
||||
else |
||||
respond_to do |format| |
||||
format.api { render_validation_errors(@time_entry) } |
||||
end |
||||
end |
||||
end |
||||
|
||||
def destroy |
||||
if @time_entry.destroy && @time_entry.destroyed? |
||||
respond_to do |format| |
||||
format.api { head :ok } |
||||
end |
||||
else |
||||
respond_to do |format| |
||||
format.api { render_validation_errors(@time_entry) } |
||||
end |
||||
end |
||||
rescue ::ActionController::RedirectBackError |
||||
redirect_to :action => 'index', :project_id => @time_entry.project |
||||
end |
||||
|
||||
end |
||||
end |
||||
end |
@ -0,0 +1,157 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V1 |
||||
|
||||
class UsersController < UsersController |
||||
|
||||
include ::Api::V1::ApiController |
||||
|
||||
def index |
||||
sort_init 'login', 'asc' |
||||
sort_update %w(login firstname lastname mail admin created_on last_login_on) |
||||
|
||||
scope = User |
||||
scope = scope.in_group(params[:group_id].to_i) if params[:group_id].present? |
||||
|
||||
@status = params[:status] ? params[:status].to_i : 1 |
||||
c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) |
||||
|
||||
unless params[:name].blank? |
||||
name = "%#{params[:name].strip.downcase}%" |
||||
c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name] |
||||
end |
||||
|
||||
@users = scope.order(sort_clause) |
||||
.where(c.conditions) |
||||
.page(page_param) |
||||
.per_page(per_page_param) |
||||
|
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def show |
||||
# show projects based on current user visibility |
||||
@memberships = @user.memberships.all(:conditions => Project.visible_by(User.current)) |
||||
|
||||
events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10) |
||||
@events_by_day = events.group_by(&:event_date) |
||||
|
||||
unless User.current.admin? |
||||
if !(@user.active? || @user.registered?) || (@user != User.current && @memberships.empty? && events.empty?) |
||||
render_404 |
||||
return |
||||
end |
||||
end |
||||
|
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def create |
||||
@user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) |
||||
@user.safe_attributes = params[:user] |
||||
@user.admin = params[:user][:admin] || false |
||||
@user.login = params[:user][:login] |
||||
@user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] if @user.change_password_allowed? |
||||
|
||||
if @user.save |
||||
# TODO: Similar to My#account |
||||
@user.pref.attributes = params[:pref] |
||||
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1') |
||||
@user.pref.save |
||||
|
||||
@user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) |
||||
|
||||
UserMailer.account_information(@user, params[:user][:password]).deliver if params[:send_information] |
||||
|
||||
respond_to do |format| |
||||
format.api { render :action => 'show', :status => :created, :location => user_url(@user) } |
||||
end |
||||
else |
||||
@auth_sources = AuthSource.find(:all) |
||||
# Clear password input |
||||
@user.password = @user.password_confirmation = nil |
||||
|
||||
respond_to do |format| |
||||
format.api { render_validation_errors(@user) } |
||||
end |
||||
end |
||||
end |
||||
|
||||
def update |
||||
@user.admin = params[:user][:admin] if params[:user][:admin] |
||||
@user.login = params[:user][:login] if params[:user][:login] |
||||
@user.safe_attributes = params[:user].except(:login) # :login is protected |
||||
if params[:user][:password].present? && @user.change_password_allowed? |
||||
@user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] |
||||
end |
||||
# Was the account actived ? (do it before User#save clears the change) |
||||
was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) |
||||
if @user.save |
||||
# TODO: Similar to My#account |
||||
@user.pref.attributes = params[:pref] |
||||
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1') |
||||
@user.pref.save |
||||
|
||||
@user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) |
||||
|
||||
if was_activated |
||||
UserMailer.account_activated(@user).deliver |
||||
elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.change_password_allowed? |
||||
UserMailer.account_information(@user, params[:user][:password]).deliver |
||||
end |
||||
|
||||
respond_to do |format| |
||||
format.api { head :ok } |
||||
end |
||||
else |
||||
@auth_sources = AuthSource.find(:all) |
||||
@membership ||= Member.new |
||||
# Clear password input |
||||
@user.password = @user.password_confirmation = nil |
||||
|
||||
respond_to do |format| |
||||
format.api { render_validation_errors(@user) } |
||||
end |
||||
end |
||||
rescue ::ActionController::RedirectBackError |
||||
redirect_to :controller => '/users', :action => 'edit', :id => @user |
||||
end |
||||
|
||||
def destroy |
||||
# as destroying users is a lengthy process we handle it in the background |
||||
# and lock the account now so that no action can be performed with it |
||||
@user.status = User::STATUS_LOCKED |
||||
@user.save |
||||
|
||||
# TODO: use Delayed::Worker.delay_jobs = false in test environment as soon as |
||||
# delayed job allows for it |
||||
Rails.env.test? ? |
||||
@user.destroy : |
||||
@user.delay.destroy |
||||
|
||||
flash[:notice] = l('account.deleted') |
||||
|
||||
respond_to do |format| |
||||
format.api do |
||||
head :ok |
||||
end |
||||
end |
||||
end |
||||
|
||||
end |
||||
end |
||||
end |
@ -0,0 +1,32 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V2 |
||||
|
||||
module ApiController |
||||
|
||||
include ::Api::V1::ApiController |
||||
extend ::Api::V1::ApiController::ClassMethods |
||||
|
||||
def api_version |
||||
/api\/v2\// |
||||
end |
||||
|
||||
permeate_permissions :apply_at_timestamp, |
||||
:determine_base, |
||||
:find_all_projects_by_project_id, |
||||
:find_project_by_project_id, |
||||
:jump_to_project_menu_item |
||||
|
||||
end |
||||
end |
||||
end |
@ -0,0 +1,29 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V2 |
||||
|
||||
class AuthenticationController < AuthenticationController |
||||
|
||||
include ::Api::V2::ApiController |
||||
|
||||
unloadable |
||||
|
||||
def index |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
end |
||||
|
||||
end |
||||
end |
@ -0,0 +1,29 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V2 |
||||
|
||||
class PlanningElementJournalsController < PlanningElementJournalsController |
||||
|
||||
include ::Api::V2::ApiController |
||||
|
||||
def index |
||||
@journals = @planning_element.journals |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
end |
||||
|
||||
end |
||||
end |
||||
|
@ -0,0 +1,40 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V2 |
||||
|
||||
class PlanningElementStatusesController < PlanningElementStatusesController |
||||
unloadable |
||||
helper :timelines |
||||
|
||||
include ::Api::V2::ApiController |
||||
|
||||
accept_key_auth :index, :show |
||||
|
||||
def index |
||||
@planning_element_statuses = PlanningElementStatus.active |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def show |
||||
@planning_element_status = PlanningElementStatus.active.find(params[:id]) |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
end |
||||
|
||||
end |
||||
end |
||||
|
@ -0,0 +1,35 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V2 |
||||
|
||||
class PlanningElementTypeColorsController < PlanningElementTypeColorsController |
||||
|
||||
include ::Api::V2::ApiController |
||||
|
||||
def index |
||||
@colors = PlanningElementTypeColor.all |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def show |
||||
@color = PlanningElementTypeColor.find(params[:id]) |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
end |
||||
end |
||||
end |
@ -0,0 +1,35 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V2 |
||||
|
||||
class PlanningElementTypesController < PlanningElementTypesController |
||||
|
||||
include ::Api::V2::ApiController |
||||
|
||||
def index |
||||
@planning_element_types = @base.all |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def show |
||||
@planning_element_type = @base.find(params[:id]) |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
end |
||||
|
||||
end |
||||
end |
@ -0,0 +1,113 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V2 |
||||
|
||||
class PlanningElementsController < PlanningElementsController |
||||
|
||||
include ::Api::V2::ApiController |
||||
|
||||
def index |
||||
optimize_planning_elements_for_less_db_queries |
||||
|
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def create |
||||
@planning_element = @planning_elements.new(permitted_params.planning_element) |
||||
successfully_created = @planning_element.save |
||||
|
||||
respond_to do |format| |
||||
|
||||
format.api do |
||||
if successfully_created |
||||
redirect_url = api_v2_project_planning_element_url( |
||||
@project, @planning_element, |
||||
# TODO this probably should be (params[:format] ||'xml'), however, client code currently anticipates xml responses. |
||||
:format => 'xml' |
||||
) |
||||
see_other(redirect_url) |
||||
else |
||||
render_validation_errors(@planning_element) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
def show |
||||
@planning_element = @project.planning_elements.find(params[:id]) |
||||
|
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def update |
||||
@planning_element = @planning_elements.find(params[:id]) |
||||
@planning_element.attributes = permitted_params.planning_element |
||||
|
||||
successfully_updated = @planning_element.save |
||||
|
||||
respond_to do |format| |
||||
format.api do |
||||
if successfully_updated |
||||
no_content |
||||
else |
||||
render_validation_errors(@planning_element) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
def list |
||||
options = {:order => 'id'} |
||||
|
||||
projects = Project.visible.select do |project| |
||||
User.current.allowed_to?(:view_planning_elements, project) |
||||
end |
||||
|
||||
if params[:ids] |
||||
ids = params[:ids].split(/,/).map(&:strip).select { |s| s =~ /^\d*$/ }.map(&:to_i).sort |
||||
project_ids = projects.map(&:id).sort |
||||
options[:conditions] = ["id IN (?) AND project_id IN (?)", ids, project_ids] |
||||
end |
||||
|
||||
@planning_elements = PlanningElement.all(options) |
||||
|
||||
respond_to do |format| |
||||
format.api { render :action => :index } |
||||
end |
||||
end |
||||
|
||||
def destroy |
||||
@planning_element = @project.planning_elements.find(params[:id]) |
||||
@planning_element.destroy! |
||||
|
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def move_to_trash |
||||
@planning_element = @planning_elements.find(params[:id]) |
||||
@planning_element.destroy |
||||
|
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
end |
||||
|
||||
end |
||||
end |
@ -0,0 +1,45 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V2 |
||||
|
||||
class ProjectAssociationsController < ProjectAssociationsController |
||||
|
||||
include ::Api::V2::ApiController |
||||
|
||||
respond_to :api |
||||
|
||||
def index |
||||
@project_associations = @project.project_associations.visible |
||||
|
||||
respond_with(@project_associations) |
||||
end |
||||
|
||||
def available_projects |
||||
available_projects = @project.associated_project_candidates |
||||
|
||||
@elements = Project.project_level_list(Project.visible) |
||||
@disabled = Project.visible - available_projects |
||||
|
||||
respond_with(@elements, @disabled) |
||||
end |
||||
|
||||
def show |
||||
@project_association = @project.project_associations.find(params[:id]) |
||||
check_visibility |
||||
|
||||
respond_with(@project_associations) |
||||
end |
||||
end |
||||
|
||||
end |
||||
end |
@ -0,0 +1,35 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V2 |
||||
|
||||
class ProjectTypesController < ProjectTypesController |
||||
|
||||
include ::Api::V2::ApiController |
||||
|
||||
def index |
||||
@project_types = ProjectType.all |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def show |
||||
@project_type = ProjectType.find(params[:id]) |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
end |
||||
|
||||
end |
||||
end |
@ -0,0 +1,51 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V2 |
||||
class ProjectsController < ProjectsController |
||||
|
||||
include ::Api::V2::ApiController |
||||
|
||||
def index |
||||
options = {:order => 'lft'} |
||||
|
||||
if params[:ids] |
||||
ids, identifiers = params[:ids].split(/,/).map(&:strip).partition { |s| s =~ /^\d*$/ } |
||||
ids = ids.map(&:to_i).sort |
||||
identifiers = identifiers.sort |
||||
|
||||
options[:conditions] = ["id IN (?) OR identifier IN (?)", ids, identifiers] |
||||
end |
||||
|
||||
@projects = @base.visible.all(options) |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def show |
||||
@project = @base.find(params[:id]) |
||||
authorize |
||||
return if performed? |
||||
|
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def find_project |
||||
@project = Project.find(params[:id]) |
||||
end |
||||
|
||||
end |
||||
end |
||||
end |
@ -0,0 +1,35 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V2 |
||||
|
||||
class ReportedProjectStatusesController < ReportedProjectStatusesController |
||||
|
||||
include ::Api::V2::ApiController |
||||
|
||||
def index |
||||
@reported_project_statuses = @base.all |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def show |
||||
@reported_project_status = @base.find(params[:id]) |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
end |
||||
|
||||
end |
||||
end |
@ -0,0 +1,168 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V2 |
||||
|
||||
class ReportingsController < ReportingsController |
||||
|
||||
include ::Api::V2::ApiController |
||||
|
||||
def available_projects |
||||
available_projects = @project.reporting_to_project_candidates |
||||
respond_to do |format| |
||||
format.api { |
||||
@elements = Project.project_level_list(Project.visible) |
||||
@disabled = Project.visible - available_projects |
||||
} |
||||
end |
||||
end |
||||
|
||||
def index |
||||
|
||||
condition_params = []; |
||||
temp_condition = "" |
||||
condition = "" |
||||
|
||||
if (params[:project_types].present?) |
||||
project_types = params[:project_types].split(/,/).map(&:to_i) |
||||
temp_condition += "#{Project.quoted_table_name}.project_type_id IN (?)" |
||||
condition_params << project_types |
||||
if (project_types.include?(-1)) |
||||
temp_condition += " OR #{Project.quoted_table_name}.project_type_id IS NULL" |
||||
temp_condition = "(#{temp_condition})" |
||||
end |
||||
end |
||||
|
||||
condition += temp_condition |
||||
temp_condition = "" |
||||
|
||||
if (params[:project_statuses].present?) |
||||
condition += " AND " unless condition.empty? |
||||
|
||||
project_statuses = params[:project_statuses].split(/,/).map(&:to_i) |
||||
temp_condition += "#{Reporting.quoted_table_name}.reported_project_status_id IN (?)" |
||||
condition_params << project_statuses |
||||
if (project_statuses.include?(-1)) |
||||
temp_condition += " OR #{Reporting.quoted_table_name}.reported_project_status_id IS NULL" |
||||
temp_condition = "(#{temp_condition})" |
||||
end |
||||
end |
||||
|
||||
condition += temp_condition |
||||
temp_condition = "" |
||||
|
||||
if (params[:project_responsibles].present?) |
||||
condition += " AND " unless condition.empty? |
||||
|
||||
project_responsibles = params[:project_responsibles].split(/,/).map(&:to_i) |
||||
temp_condition += "#{Project.quoted_table_name}.responsible_id IN (?)" |
||||
condition_params << project_responsibles |
||||
if (project_responsibles.include?(-1)) |
||||
temp_condition += " OR #{Project.quoted_table_name}.responsible_id IS NULL" |
||||
temp_condition = "(#{temp_condition})" |
||||
end |
||||
end |
||||
|
||||
condition += temp_condition |
||||
temp_condition = "" |
||||
|
||||
if (params[:project_parents].present?) |
||||
condition += " AND " unless condition.empty? |
||||
|
||||
project_parents = params[:project_parents].split(/,/).map(&:to_i) |
||||
nested_set_selection = Project.find(project_parents).map { |p| p.lft..p.rgt }.inject([]) { |r, e| e.each { |i| r << i }; r } |
||||
|
||||
temp_condition += "#{Project.quoted_table_name}.lft IN (?)" |
||||
condition_params << nested_set_selection |
||||
end |
||||
|
||||
condition += temp_condition |
||||
temp_condition = "" |
||||
|
||||
if (params[:grouping_one].present? && condition.present?) |
||||
condition += " OR " |
||||
|
||||
grouping = params[:grouping_one].split(/,/).map(&:to_i) |
||||
temp_condition += "#{Project.quoted_table_name}.id IN (?)" |
||||
condition_params << grouping |
||||
end |
||||
|
||||
condition += temp_condition |
||||
conditions = [condition] + condition_params unless condition.empty? |
||||
|
||||
case params[:only] |
||||
when "via_source" |
||||
@reportings = @project.reportings_via_source.find(:all, |
||||
:include => :project, |
||||
:conditions => conditions |
||||
) |
||||
when "via_target" |
||||
@reportings = @project.reportings_via_target.find(:all, |
||||
:include => :project, |
||||
:conditions => conditions |
||||
) |
||||
else |
||||
@reportings = @project.reportings.all |
||||
end |
||||
|
||||
# get all reportings for which projects have ancestors. |
||||
nested_sets_for_parents = (@reportings.inject([]) { |r, e| r << e.reporting_to_project; r << e.project }).uniq.map { |p| [p.lft, p.rgt] } |
||||
|
||||
condition_params = []; |
||||
temp_condition = "" |
||||
condition = "" |
||||
|
||||
nested_sets_for_parents.each do |set| |
||||
condition += " OR " unless condition.empty? |
||||
condition += "#{Project.quoted_table_name}.lft < ? AND #{Project.quoted_table_name}.rgt > ?" |
||||
condition_params << set[0] |
||||
condition_params << set[1] |
||||
end |
||||
|
||||
conditions = [condition] + condition_params unless condition.empty? |
||||
|
||||
case params[:only] |
||||
when "via_source" |
||||
@ancestor_reportings = @project.reportings_via_source.find(:all, |
||||
:include => :project, |
||||
:conditions => conditions |
||||
) |
||||
when "via_target" |
||||
@ancestor_reportings = @project.reportings_via_target.find(:all, |
||||
:include => :project, |
||||
:conditions => conditions |
||||
) |
||||
else |
||||
@ancestor_reportings = @project.reportings.all |
||||
end |
||||
|
||||
@reportings = (@reportings + @ancestor_reportings).uniq |
||||
|
||||
respond_to do |format| |
||||
format.api do |
||||
@reportings.select(&:visible?) |
||||
end |
||||
end |
||||
end |
||||
|
||||
def show |
||||
@reporting = @project.reportings_via_source.find(params[:id]) |
||||
check_visibility |
||||
|
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
end |
||||
|
||||
end |
||||
end |
@ -0,0 +1,35 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V2 |
||||
|
||||
class ScenariosController < ScenariosController |
||||
|
||||
include ::Api::V2::ApiController |
||||
|
||||
def index |
||||
@scenarios = @project.scenarios |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def show |
||||
@scenario = @project.scenarios.find(params[:id]) |
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
end |
||||
|
||||
end |
||||
end |
@ -0,0 +1,20 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Api |
||||
module V2 |
||||
|
||||
class TimelinesController < TimelinesController |
||||
include ::Api::V2::ApiController |
||||
end |
||||
|
||||
end |
||||
end |
@ -0,0 +1,17 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class PrincipalsController < ApplicationController |
||||
extend Pagination::Controller |
||||
|
||||
paginate_model Principal |
||||
search_for Principal, :like |
||||
end |
@ -1,62 +0,0 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Timelines::TimelinesProjectsController < ApplicationController |
||||
extend Timelines::Pagination::Controller |
||||
|
||||
unloadable |
||||
helper :timelines |
||||
|
||||
before_filter :determine_base |
||||
|
||||
accept_key_auth :index, :show |
||||
|
||||
timelines_paginate_model Project |
||||
|
||||
def index |
||||
options = {:order => 'lft'} |
||||
|
||||
if params[:ids] |
||||
ids, identifiers = params[:ids].split(/,/).map(&:strip).partition { |s| s =~ /^\d*$/ } |
||||
ids = ids.map(&:to_i).sort |
||||
identifiers = identifiers.sort |
||||
|
||||
options[:conditions] = ["id IN (?) OR identifier IN (?)", ids, identifiers] |
||||
end |
||||
|
||||
@projects = @base.visible.all(options) |
||||
respond_to do |format| |
||||
format.html { render_404 } |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
def show |
||||
@project = @base.find(params[:id]) |
||||
authorize |
||||
return if performed? |
||||
|
||||
respond_to do |format| |
||||
format.html { render_404 } |
||||
format.api |
||||
end |
||||
end |
||||
|
||||
protected |
||||
|
||||
def determine_base |
||||
if params[:project_type_id] |
||||
@base = Timelines::ProjectType.find(params[:project_type_id]).projects |
||||
else |
||||
@base = Project |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,103 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'will_paginate' |
||||
|
||||
module PaginationHelper |
||||
def pagination_links_full(paginator, options = {}) |
||||
merged_options = { next_label: I18n.t(:label_next), |
||||
previous_label: I18n.t(:label_next), |
||||
container: true }.merge(options) |
||||
|
||||
html = ''.html_safe |
||||
|
||||
if paginator.total_entries > 0 |
||||
html << will_paginate(paginator, merged_options.merge({ :container => false }) ) |
||||
|
||||
html << content_tag(:span, "(#{paginator.offset + 1} - #{paginator.offset + paginator.length}/#{paginator.total_entries})", :class => 'range') |
||||
|
||||
if per_page_links && links = per_page_links(paginator.per_page) |
||||
html << links |
||||
end |
||||
end |
||||
|
||||
merged_options[:container] ? |
||||
content_tag(:p, html, :class => "pagination") : |
||||
html |
||||
end |
||||
|
||||
def per_page_links(selected=nil) |
||||
links = Setting.per_page_options_array.collect do |n| |
||||
n == selected ? |
||||
content_tag(:span, n, :class => 'current') : |
||||
link_to_content_update(n, params.merge(:per_page => n)) |
||||
end |
||||
content_tag :span, :class => 'per_page_options' do |
||||
links.size > 1 ? l(:label_display_per_page, links.join(', ')).html_safe : nil |
||||
end |
||||
end |
||||
|
||||
# Returns page option used for pagination |
||||
# based on: |
||||
# * offset |
||||
# * limit |
||||
# * page |
||||
# parameters. |
||||
# Preferes page over the other two and |
||||
# calculates page in it's absence based on limit and offset. |
||||
# Return 1 if all else fails. |
||||
|
||||
def page_param(options = params) |
||||
page = if options[:page] |
||||
|
||||
options[:page].to_i |
||||
|
||||
elsif options[:offset] && options[:limit] |
||||
|
||||
begin |
||||
# + 1 as page is not 0 but 1 based |
||||
options[:offset].to_i/per_page_param(options) + 1 |
||||
rescue ZeroDivisionError |
||||
1 |
||||
end |
||||
|
||||
else |
||||
|
||||
1 |
||||
|
||||
end |
||||
|
||||
page > 0 ? |
||||
page : |
||||
1 |
||||
end |
||||
|
||||
# Returns per_page option used for pagination |
||||
# based on: |
||||
# * per_page session value |
||||
# * per_page options value |
||||
# * limit options value |
||||
# in that order |
||||
# Return smallest possible setting if all else fails. |
||||
|
||||
def per_page_param(options = params) |
||||
per_page_candidates = [session[:per_page].to_i, options[:per_page].to_i, options[:limit].to_i] |
||||
|
||||
unless (union = per_page_candidates & Setting.per_page_options_array).empty? |
||||
session[:per_page] = union.first |
||||
|
||||
union.first |
||||
else |
||||
Setting.per_page_options_array.sort.first |
||||
end |
||||
end |
||||
end |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue