diff options
author | Dmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com> | 2011-10-09 01:36:38 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com> | 2011-10-09 01:36:38 +0400 |
commit | e98c77857f9f765d1854b92c2dc33049504a596d (patch) | |
tree | 52fbfc1cdb55df21843965479c97be0c91121a9a /app/controllers | |
parent | 0f43e98ef8c2da8908b1107f75b67cda2572c2c4 (diff) |
init commitv0.9.4
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/admin/mailer_controller.rb | 44 | ||||
-rw-r--r-- | app/controllers/admin/projects_controller.rb | 73 | ||||
-rw-r--r-- | app/controllers/admin/team_members_controller.rb | 75 | ||||
-rw-r--r-- | app/controllers/admin/users_controller.rb | 84 | ||||
-rw-r--r-- | app/controllers/application_controller.rb | 40 | ||||
-rw-r--r-- | app/controllers/commits_controller.rb | 44 | ||||
-rw-r--r-- | app/controllers/dashboard_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/issues_controller.rb | 72 | ||||
-rw-r--r-- | app/controllers/keys_controller.rb | 38 | ||||
-rw-r--r-- | app/controllers/notes_controller.rb | 49 | ||||
-rw-r--r-- | app/controllers/profile_controller.rb | 21 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 149 | ||||
-rw-r--r-- | app/controllers/team_members_controller.rb | 66 |
13 files changed, 757 insertions, 0 deletions
diff --git a/app/controllers/admin/mailer_controller.rb b/app/controllers/admin/mailer_controller.rb new file mode 100644 index 00000000000..05ad267fad5 --- /dev/null +++ b/app/controllers/admin/mailer_controller.rb @@ -0,0 +1,44 @@ +class Admin::MailerController < ApplicationController + before_filter :authenticate_user! + before_filter :authenticate_admin! + + def preview + + end + + def preview_note + @note = Note.first + @user = @note.author + @project = @note.project + case params[:type] + when "Commit" then + @commit = @project.commit + render :file => 'notify/note_commit_email.html.haml', :layout => 'notify' + when "Issue" then + @issue = Issue.first + render :file => 'notify/note_issue_email.html.haml', :layout => 'notify' + else + render :file => 'notify/note_wall_email.html.haml', :layout => 'notify' + end + rescue + render :text => "Preview not avaialble" + end + + def preview_user_new + @user = User.first + @password = "DHasJKDHAS!" + + render :file => 'notify/new_user_email.html.haml', :layout => 'notify' + rescue + render :text => "Preview not avaialble" + end + + def preview_issue_new + @issue = Issue.first + @user = @issue.assignee + @project = @issue.project + render :file => 'notify/new_issue_email.html.haml', :layout => 'notify' + rescue + render :text => "Preview not avaialble" + end +end diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb new file mode 100644 index 00000000000..fe5ada8f1cb --- /dev/null +++ b/app/controllers/admin/projects_controller.rb @@ -0,0 +1,73 @@ +class Admin::ProjectsController < ApplicationController + before_filter :authenticate_user! + before_filter :authenticate_admin! + + def index + @admin_projects = Project.page(params[:page]) + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @admin_projects } + end + end + + def show + @admin_project = Project.find_by_code(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @admin_project } + end + end + + def new + @admin_project = Project.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @admin_project } + end + end + + def edit + @admin_project = Project.find_by_code(params[:id]) + end + + def create + @admin_project = Project.new(params[:project]) + + respond_to do |format| + if @admin_project.save + format.html { redirect_to [:admin, @admin_project], notice: 'Project was successfully created.' } + format.json { render json: @admin_project, status: :created, location: @admin_project } + else + format.html { render action: "new" } + format.json { render json: @admin_project.errors, status: :unprocessable_entity } + end + end + end + + def update + @admin_project = Project.find_by_code(params[:id]) + + respond_to do |format| + if @admin_project.update_attributes(params[:project]) + format.html { redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.' } + format.json { head :ok } + else + format.html { render action: "edit" } + format.json { render json: @admin_project.errors, status: :unprocessable_entity } + end + end + end + + def destroy + @admin_project = Project.find_by_code(params[:id]) + @admin_project.destroy + + respond_to do |format| + format.html { redirect_to admin_projects_url } + format.json { head :ok } + end + end +end diff --git a/app/controllers/admin/team_members_controller.rb b/app/controllers/admin/team_members_controller.rb new file mode 100644 index 00000000000..bca9bfebbfd --- /dev/null +++ b/app/controllers/admin/team_members_controller.rb @@ -0,0 +1,75 @@ +class Admin::TeamMembersController < ApplicationController + before_filter :authenticate_user! + before_filter :authenticate_admin! + + def index + @admin_team_members = UsersProject.page(params[:page]).per(100).order("project_id DESC") + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @admin_team_members } + end + end + + def show + @admin_team_member = UsersProject.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @admin_team_member } + end + end + + def new + @admin_team_member = UsersProject.new(params[:team_member]) + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @admin_team_member } + end + end + + def edit + @admin_team_member = UsersProject.find(params[:id]) + end + + def create + @admin_team_member = UsersProject.new(params[:team_member]) + @admin_team_member.project_id = params[:team_member][:project_id] + + respond_to do |format| + if @admin_team_member.save + format.html { redirect_to admin_team_member_path(@admin_team_member), notice: 'UsersProject was successfully created.' } + format.json { render json: @admin_team_member, status: :created, location: @team_member } + else + format.html { render action: "new" } + format.json { render json: @admin_team_member.errors, status: :unprocessable_entity } + end + end + end + + def update + @admin_team_member = UsersProject.find(params[:id]) + @admin_team_member.project_id = params[:team_member][:project_id] + + respond_to do |format| + if @admin_team_member.update_attributes(params[:team_member]) + format.html { redirect_to admin_team_member_path(@admin_team_member), notice: 'UsersProject was successfully updated.' } + format.json { head :ok } + else + format.html { render action: "edit" } + format.json { render json: @admin_team_member.errors, status: :unprocessable_entity } + end + end + end + + def destroy + @admin_team_member = UsersProject.find(params[:id]) + @admin_team_member.destroy + + respond_to do |format| + format.html { redirect_to admin_team_members_url } + format.json { head :ok } + end + end +end diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb new file mode 100644 index 00000000000..5190dd06a8d --- /dev/null +++ b/app/controllers/admin/users_controller.rb @@ -0,0 +1,84 @@ +class Admin::UsersController < ApplicationController + before_filter :authenticate_user! + before_filter :authenticate_admin! + + def index + @admin_users = User.page(params[:page]) + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @admin_users } + end + end + + def show + @admin_user = User.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @admin_user } + end + end + + def new + @admin_user = User.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @admin_user } + end + end + + def edit + @admin_user = User.find(params[:id]) + end + + def create + admin = params[:user].delete("admin") + + @admin_user = User.new(params[:user]) + @admin_user.admin = (admin && admin.to_i > 0) + + respond_to do |format| + if @admin_user.save + Notify.new_user_email(@admin_user, params[:user][:password]).deliver + format.html { redirect_to [:admin, @admin_user], notice: 'User was successfully created.' } + format.json { render json: @admin_user, status: :created, location: @admin_user } + else + format.html { render action: "new" } + format.json { render json: @admin_user.errors, status: :unprocessable_entity } + end + end + end + + def update + admin = params[:user].delete("admin") + if params[:user][:password].empty? + params[:user].delete(:password) + params[:user].delete(:password_confirmation) + end + + @admin_user = User.find(params[:id]) + @admin_user.admin = (admin && admin.to_i > 0) + + respond_to do |format| + if @admin_user.update_attributes(params[:user]) + format.html { redirect_to [:admin, @admin_user], notice: 'User was successfully updated.' } + format.json { head :ok } + else + format.html { render action: "edit" } + format.json { render json: @admin_user.errors, status: :unprocessable_entity } + end + end + end + + def destroy + @admin_user = User.find(params[:id]) + @admin_user.destroy + + respond_to do |format| + format.html { redirect_to admin_users_url } + format.json { head :ok } + end + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 00000000000..09c44502cdf --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,40 @@ +class ApplicationController < ActionController::Base + before_filter :authenticate_user! + protect_from_forgery + + helper_method :abilities, :can? + + protected + + def abilities + @abilities ||= Six.new + end + + def can?(object, action, subject) + abilities.allowed?(object, action, subject) + end + + def project + @project ||= Project.find_by_code(params[:project_id]) + end + + def add_project_abilities + abilities << Ability + end + + def authenticate_admin! + return redirect_to(new_user_session_path) unless current_user.is_admin? + end + + def authorize_project!(action) + return redirect_to(new_user_session_path) unless can?(current_user, action, project) + end + + def method_missing(method_sym, *arguments, &block) + if method_sym.to_s =~ /^authorize_(.*)!$/ + authorize_project!($1.to_sym) + else + super + end + end +end diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb new file mode 100644 index 00000000000..d7daec13f0f --- /dev/null +++ b/app/controllers/commits_controller.rb @@ -0,0 +1,44 @@ +require "base64" + +class CommitsController < ApplicationController + before_filter :project + + # Authorize + before_filter :add_project_abilities + before_filter :authorize_read_project! + + def index + @repo = project.repo + @branch = if !params[:branch].blank? + params[:branch] + elsif !params[:tag].blank? + params[:tag] + else + "master" + end + + if params[:path] + @commits = @repo.log(@branch, params[:path], :max_count => params[:limit] || 100, :skip => params[:offset] || 0) + else + @commits = @repo.commits(@branch, params[:limit] || 100, params[:offset] || 0) + end + + respond_to do |format| + format.html # index.html.erb + format.js + format.json { render json: @commits } + end + end + + def show + @commit = project.repo.commits(params[:id]).first + @notes = project.notes.where(:noteable_id => @commit.id, :noteable_type => "Commit") + @note = @project.notes.new(:noteable_id => @commit.id, :noteable_type => "Commit") + + respond_to do |format| + format.html # show.html.erb + format.js + format.json { render json: @commit } + end + end +end diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb new file mode 100644 index 00000000000..e1192e4dc5d --- /dev/null +++ b/app/controllers/dashboard_controller.rb @@ -0,0 +1,2 @@ +class DashboardController < ApplicationController +end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb new file mode 100644 index 00000000000..f8b4719809b --- /dev/null +++ b/app/controllers/issues_controller.rb @@ -0,0 +1,72 @@ +class IssuesController < ApplicationController + before_filter :authenticate_user! + before_filter :project + + # Authorize + before_filter :add_project_abilities + before_filter :authorize_read_issue! + before_filter :authorize_write_issue!, :only => [:new, :create, :close, :edit, :update] + before_filter :authorize_admin_issue!, :only => [:destroy] + + respond_to :js + + def index + @issues = case params[:f].to_i + when 1 then @project.issues.all + when 2 then @project.issues.closed + when 3 then @project.issues.opened.assigned(current_user) + else @project.issues.opened + end + + respond_to do |format| + format.html # index.html.erb + format.js + end + end + + def new + @issue = @project.issues.new + respond_with(@issue) + end + + def edit + @issue = @project.issues.find(params[:id]) + respond_with(@issue) + end + + def show + @issue = @project.issues.find(params[:id]) + @notes = @issue.notes + @note = @project.notes.new(:noteable => @issue) + end + + def create + @issue = @project.issues.new(params[:issue]) + @issue.author = current_user + if @issue.save + Notify.new_issue_email(@issue).deliver + end + + respond_with(@issue) + end + + def update + @issue = @project.issues.find(params[:id]) + @issue.update_attributes(params[:issue]) + + respond_to do |format| + format.js + format.html { redirect_to [@project, @issue]} + end + end + + + def destroy + @issue = @project.issues.find(params[:id]) + @issue.destroy + + respond_to do |format| + format.js { render :nothing => true } + end + end +end diff --git a/app/controllers/keys_controller.rb b/app/controllers/keys_controller.rb new file mode 100644 index 00000000000..003de6b301a --- /dev/null +++ b/app/controllers/keys_controller.rb @@ -0,0 +1,38 @@ +class KeysController < ApplicationController + respond_to :js + + def index + @keys = current_user.keys.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @keys } + end + end + + def new + @key = current_user.keys.new + + respond_with(@key) + end + + def create + @key = current_user.keys.new(params[:key]) + @key.save + + respond_with(@key) + end + + # DELETE /keys/1 + # DELETE /keys/1.json + def destroy + @key = current_user.keys.find(params[:id]) + @key.destroy + + respond_to do |format| + format.html { redirect_to keys_url } + format.js { render :nothing => true } + format.json { head :ok } + end + end +end diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb new file mode 100644 index 00000000000..d0a40eb18e4 --- /dev/null +++ b/app/controllers/notes_controller.rb @@ -0,0 +1,49 @@ +class NotesController < ApplicationController + before_filter :project + + # Authorize + before_filter :add_project_abilities + before_filter :authorize_write_note!, :only => [:create] + before_filter :authorize_admin_note!, :only => [:destroy] + + respond_to :js + + def create + @note = @project.notes.new(params[:note]) + @note.author = current_user + + if @note.save + notify if params[:notify] == '1' + end + + + respond_to do |format| + format.html {redirect_to :back} + format.js + end + end + + def destroy + @note = @project.notes.find(params[:id]) + @note.destroy + + respond_to do |format| + format.js { render :nothing => true } + end + end + + protected + + def notify + @project.users.reject { |u| u.id == current_user.id } .each do |u| + case @note.noteable_type + when "Commit" then + Notify.note_commit_email(u, @note).deliver + when "Issue" then + Notify.note_issue_email(u, @note).deliver + else + Notify.note_wall_email(u, @note).deliver + end + end + end +end diff --git a/app/controllers/profile_controller.rb b/app/controllers/profile_controller.rb new file mode 100644 index 00000000000..666c6309dce --- /dev/null +++ b/app/controllers/profile_controller.rb @@ -0,0 +1,21 @@ +class ProfileController < ApplicationController + def show + @user = current_user + end + + def password + @user = current_user + end + + def password_update + params[:user].reject!{ |k, v| k != "password" && k != "password_confirmation"} + @user = current_user + + if @user.update_attributes(params[:user]) + flash[:notice] = "Password was successfully updated. Please login with it" + redirect_to new_user_session_path + else + render :action => "password" + end + end +end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb new file mode 100644 index 00000000000..06f97f57c51 --- /dev/null +++ b/app/controllers/projects_controller.rb @@ -0,0 +1,149 @@ +class ProjectsController < ApplicationController + before_filter :project, :except => [:index, :new, :create] + + # Authorize + before_filter :add_project_abilities + before_filter :authorize_read_project!, :except => [:index, :new, :create] + before_filter :authorize_admin_project!, :only => [:edit, :update, :destroy] + + def index + @projects = current_user.projects.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @projects } + end + end + + def show + @repo = project.repo + @commit = @repo.commits.first + @tree = @commit.tree + @tree = @tree / params[:path] if params[:path] + + respond_to do |format| + format.html # show.html.erb + format.json { render json: project } + end + rescue Grit::NoSuchPathError => ex + respond_to do |format| + format.html {render "projects/empty"} + end + end + + def tree + @repo = project.repo + @branch = if !params[:branch].blank? + params[:branch] + elsif !params[:tag].blank? + params[:tag] + else + "master" + end + + if params[:commit_id] + @commit = @repo.commits(params[:commit_id]).first + else + @commit = @repo.commits(@branch || "master").first + end + @tree = @commit.tree + @tree = @tree / params[:path] if params[:path] + + respond_to do |format| + format.html # show.html.erb + format.js do + # temp solution + response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate" + response.headers["Pragma"] = "no-cache" + response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" + end + format.json { render json: project } + end + end + + def blob + @repo = project.repo + @commit = project.commit(params[:commit_id]) + @tree = project.tree(@commit, params[:path]) + + if @tree.is_a?(Grit::Blob) + send_data(@tree.data, :type => @tree.mime_type, :disposition => 'inline', :filename => @tree.name) + else + head(404) + end + end + + def new + @project = Project.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @project } + end + end + + def edit + end + + def create + @project = Project.new(params[:project]) + + Project.transaction do + @project.save! + @project.users_projects.create!(:admin => true, :read => true, :write => true, :user => current_user) + end + + respond_to do |format| + if @project.valid? + format.html { redirect_to @project, notice: 'Project was successfully created.' } + format.js + format.json { render json: @project, status: :created, location: @project } + else + format.html { render action: "new" } + format.js + format.json { render json: @project.errors, status: :unprocessable_entity } + end + end + rescue StandardError => ex + @project.errors.add(:base, "Cant save project. Please try again later") + respond_to do |format| + format.html { render action: "new" } + format.js + format.json { render json: @project.errors, status: :unprocessable_entity } + end + end + + def update + respond_to do |format| + if project.update_attributes(params[:project]) + format.html { redirect_to project, notice: 'Project was successfully updated.' } + format.js + format.json { head :ok } + else + format.html { render action: "edit" } + format.js + format.json { render json: project.errors, status: :unprocessable_entity } + end + end + end + + def destroy + project.destroy + + respond_to do |format| + format.html { redirect_to projects_url } + format.json { head :ok } + end + end + + def wall + @notes = @project.common_notes + @note = Note.new + end + + protected + + def project + @project ||= Project.find_by_code(params[:id]) + end +end diff --git a/app/controllers/team_members_controller.rb b/app/controllers/team_members_controller.rb new file mode 100644 index 00000000000..fd3c944b289 --- /dev/null +++ b/app/controllers/team_members_controller.rb @@ -0,0 +1,66 @@ +class TeamMembersController < ApplicationController + before_filter :project + + # Authorize + before_filter :add_project_abilities + before_filter :authorize_read_team_member! + before_filter :authorize_admin_team_member!, :only => [:new, :create, :destroy, :update] + + def show + @team_member = project.users_projects.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.js + format.json { render json: @team_member } + end + end + + def new + @team_member = project.users_projects.new + + respond_to do |format| + format.html # new.html.erb + format.js + format.json { render json: @team_member } + end + end + + def create + @team_member = UsersProject.new(params[:team_member]) + @team_member.project = project + + respond_to do |format| + if @team_member.save + format.html { redirect_to @team_member, notice: 'Team member was successfully created.' } + format.js + format.json { render json: @team_member, status: :created, location: @team_member } + else + format.html { render action: "new" } + format.js + format.json { render json: @team_member.errors, status: :unprocessable_entity } + end + end + end + + def update + @team_member = project.users_projects.find(params[:id]) + @team_member.update_attributes(params[:team_member]) + + respond_to do |format| + format.js + format.html { redirect_to team_project_path(@project)} + end + end + + def destroy + @team_member = project.users_projects.find(params[:id]) + @team_member.destroy + + respond_to do |format| + format.html { redirect_to root_path } + format.json { head :ok } + format.js { render :nothing => true } + end + end +end |