OSDN Git Service

Admin gitolite logs. Refactored project creation. Few style fixes.
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Thu, 5 Jul 2012 18:59:37 +0000 (21:59 +0300)
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Thu, 5 Jul 2012 18:59:37 +0000 (21:59 +0300)
15 files changed:
app/assets/stylesheets/gitlab_bootstrap.scss
app/controllers/admin/logs_controller.rb [new file with mode: 0644]
app/controllers/projects_controller.rb
app/helpers/application_helper.rb
app/models/project.rb
app/views/admin/logs/show.html.haml [new file with mode: 0644]
app/views/events/_event_last_push.html.haml
app/views/layouts/admin.html.haml
app/views/projects/_form.html.haml
app/views/projects/create.js.haml
app/views/projects/edit.html.haml
app/views/projects/new.html.haml
config/routes.rb
lib/gitlab/logger.rb
spec/requests/projects_spec.rb

index 7f26f16..1b86cdd 100644 (file)
@@ -627,3 +627,10 @@ h3.page_title {
   font-weight: 600;
   line-height: 28px;
 }
+
+pre.logs { 
+  .log { 
+    font-size:12px;
+    line-height:18px;
+  }
+}
diff --git a/app/controllers/admin/logs_controller.rb b/app/controllers/admin/logs_controller.rb
new file mode 100644 (file)
index 0000000..c130b4b
--- /dev/null
@@ -0,0 +1,6 @@
+class Admin::LogsController < ApplicationController
+  layout "admin"
+  before_filter :authenticate_user!
+  before_filter :authenticate_admin!
+end
+
index ac70f65..26b62cb 100644 (file)
@@ -21,20 +21,13 @@ class ProjectsController < ApplicationController
     @project = Project.create_by_user(params[:project], current_user)
 
     respond_to do |format|
-      if @project.valid?
-        format.html { redirect_to @project, notice: 'Project was successfully created.' }
-        format.js
-      else
-        format.html { render action: "new" }
-        format.js
+      format.html do
+        if @project.saved?
+          redirect_to(@project, notice: 'Project was successfully created.')
+        else
+          render action: "new"
+        end
       end
-    end
-  rescue Gitlab::Gitolite::AccessDenied
-    render :js => "location.href = '#{errors_githost_path}'" and return
-  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
     end
   end
index 2e4281a..2697fff 100644 (file)
@@ -127,6 +127,7 @@ module ApplicationHelper
              when :admin_projects; controller.controller_name == "projects"
              when :admin_emails;   controller.controller_name == 'mailer'
              when :admin_resque;   controller.controller_name == 'resque'
+             when :admin_logs;   controller.controller_name == 'logs'
 
              else
                false
index cfdaa3f..ec4893e 100644 (file)
@@ -23,6 +23,8 @@ class Project < ActiveRecord::Base
   has_many :wikis,          :dependent => :destroy
   has_many :protected_branches, :dependent => :destroy
 
+  attr_accessor :error_code
+
   # 
   # Protected attributes
   #
@@ -48,7 +50,7 @@ class Project < ActiveRecord::Base
     Project.transaction do
       project.owner = user
 
-      return project unless project.save
+      project.save!
 
       # Add user as project master
       project.users_projects.create!(:project_access => UsersProject::MASTER, :user => user)
@@ -59,6 +61,21 @@ class Project < ActiveRecord::Base
     end
 
     project
+  rescue Gitlab::Gitolite::AccessDenied => ex
+    project.error_code = :gitolite
+    project
+  rescue => ex
+    project.error_code = :db
+    project.errors.add(:base, "Cant save project. Please try again later")
+    project
+  end
+
+  def git_error?
+    error_code == :gitolite
+  end
+
+  def saved?
+    id && valid?
   end
 
   #
diff --git a/app/views/admin/logs/show.html.haml b/app/views/admin/logs/show.html.haml
new file mode 100644 (file)
index 0000000..7963e18
--- /dev/null
@@ -0,0 +1,6 @@
+%h4
+  %i.icon-file
+  githost.log
+%pre.logs
+  - Gitlab::Logger.read_latest.each do |line|
+    %span.log= line
index 6127e32..fb4a728 100644 (file)
@@ -12,5 +12,5 @@
         = time_ago_in_words(event.created_at)
         ago.
 
-      = link_to new_mr_path_from_push_event(event), :title => "New Merge Request", :class => "btn small grouped primary" do
+      = link_to new_mr_path_from_push_event(event), :title => "New Merge Request", :class => "btn very_small primary" do
         Create Merge Request
index fee77f1..8de2582 100644 (file)
@@ -12,6 +12,8 @@
           = link_to "Projects", admin_projects_path
         %li{:class => tab_class(:admin_users)}
           = link_to "Users", admin_users_path
+        %li{:class => tab_class(:admin_logs)}
+          = link_to "Logs", admin_logs_path
         %li{:class => tab_class(:admin_emails)}
           = link_to "Emails", admin_emails_path
         %li{:class => tab_class(:admin_resque)}
index e057155..6bc48df 100644 (file)
     .input
       = f.text_field :name, :placeholder => "Example Project", :class => "xxlarge"
 
-  %hr
+  %h5.page_title 
   .alert.alert-info
     %h5 Advanced settings:
     .clearfix
       = f.label :path do
-        Git Clone
+        Path
       .input
         .input-prepend
-          %span.add-on= Gitlab.config.ssh_path
-          = f.text_field :path, :placeholder => "example_project", :disabled => !@project.new_record?
-          %span.add-on= ".git"
+          %strong
+            = text_field_tag :ppath, @project.path_to_repo, :class => "xlarge", :disabled => true
     .clearfix
       = f.label :code do
         URL
index 859c985..eeefc17 100644 (file)
@@ -1,7 +1,10 @@
-- if @project.valid?
+- if @project.saved?
   :plain
     location.href = "#{project_path(@project, :notice => 'Project was successfully created.')}";
 - else
+  - if @project.git_error?
+    location.href = "#{errors_githost_path}";
+  -else 
   :plain
     $('.project_new_holder').show();
     $("#new_project").replaceWith("#{escape_javascript(render('new_form'))}");
index 53a0320..987d43e 100644 (file)
@@ -1,6 +1,6 @@
 = render "project_head"
 .project_edit_holder
-  %h3 Edit Project
+  %h3.page_title Edit Project
   %hr
   = render "projects/form"
 %div.ajax_loader.hide
index ef3e3ac..0d119bd 100644 (file)
@@ -1,5 +1,5 @@
 .project_new_holder
-  %h3
+  %h3.page_title
     New Project
   %hr
   = render 'new_form'
index fa9a1b3..af99109 100644 (file)
@@ -50,6 +50,8 @@ Gitlab::Application.routes.draw do
     get 'mailer/preview_note'
     get 'mailer/preview_user_new'
     get 'mailer/preview_issue_new'
+
+    resource :logs
     resource :resque, :controller => 'resque'
     root :to => "dashboard#index"
   end
index 45a9907..e8d20ad 100644 (file)
@@ -2,7 +2,13 @@ module Gitlab
   class Logger
     def self.error(message)
       @@logger ||= ::Logger.new(File.join(Rails.root, "log/githost.log"))
+      message = Time.now.to_s(:long) + " -> " + message
       @@logger.error(message)
     end
+
+    def self.read_latest
+      path = Rails.root.join("log/githost.log")
+      logs = `tail -n 50 #{path}`.split("\n")
+    end
   end
 end
index b55a4db..c9c3484 100644 (file)
@@ -120,7 +120,7 @@ describe "Projects" do
       visit edit_project_path(@project)
 
       fill_in 'project_name', :with => 'Awesome'
-      fill_in 'project_path', :with => 'gitlabhq'
+      fill_in 'project_code', :with => 'gitlabhq'
       click_button "Save"
       @project = @project.reload
     end