Permalink
Browse files

adding priviledges

  • Loading branch information...
1 parent a98ba6b commit 4e88a557224f1c9ac5d9daa20ade902a2f1cf8e2 @Benedict Benedict committed Jan 10, 2012
Showing with 1,293 additions and 79 deletions.
  1. +19 −0 app/controllers/deployments_controller.rb
  2. +27 −0 app/controllers/project_users_controller.rb
  3. +19 −0 app/controllers/projects_controller.rb
  4. +17 −0 app/controllers/roles_controller.rb
  5. +29 −0 app/controllers/stage_users_controller.rb
  6. +42 −1 app/controllers/stages_controller.rb
  7. +2 −0 app/models/project.rb
  8. +11 −1 app/models/stage.rb
  9. +5 −0 app/models/stages_user.rb
  10. +31 −0 app/models/user.rb
  11. +12 −9 app/views/layouts/_projects.html.erb
  12. +24 −0 app/views/projects/_users.html.erb
  13. +11 −17 app/views/projects/index.html.erb
  14. +43 −47 app/views/projects/show.html.erb
  15. +32 −0 app/views/stages/_users.html.erb
  16. +40 −0 app/views/stages/show.html.erb
  17. +2 −0 config.ru
  18. +7 −1 config/routes.rb
  19. +12 −0 db/migrate/20120110001522_create_projects_users.rb
  20. +14 −0 db/migrate/20120110003946_stage_privileges.rb
  21. +12 −1 db/schema.rb
  22. +1 −2 lib/webistrano/deployer.rb
  23. 0 script/generate
  24. +20 −0 vendor/plugins/webistrano_privileges/MIT-LICENSE
  25. +24 −0 vendor/plugins/webistrano_privileges/README
  26. +22 −0 vendor/plugins/webistrano_privileges/Rakefile
  27. +33 −0 ...plugins/webistrano_privileges/generators/privileges_extensions/privileges_extensions_generator.rb
  28. +20 −0 vendor/plugins/webistrano_privileges/generators/privileges_extensions/templates/controller.rb
  29. +12 −0 vendor/plugins/webistrano_privileges/generators/privileges_extensions/templates/migration.rb
  30. +42 −0 ...ns/webistrano_privileges/generators/privileges_extensions/templates/views/projects_index.html.erb
  31. +40 −0 .../webistrano_privileges/generators/privileges_extensions/templates/views/projects_partial.html.erb
  32. +73 −0 ...gins/webistrano_privileges/generators/privileges_extensions/templates/views/show_project.html.erb
  33. +24 −0 ...ins/webistrano_privileges/generators/privileges_extensions/templates/views/users_partial.html.erb
  34. +1 −0 vendor/plugins/webistrano_privileges/init.rb
  35. 0 vendor/plugins/webistrano_privileges/install.rb
  36. +27 −0 vendor/plugins/webistrano_privileges/lib/webistrano_privileges.rb
  37. +4 −0 vendor/plugins/webistrano_privileges/tasks/webistrano_privileges_tasks.rake
  38. +8 −0 vendor/plugins/webistrano_privileges/test/webistrano_privileges_test.rb
  39. 0 vendor/plugins/webistrano_privileges/uninstall.rb
  40. +20 −0 vendor/plugins/webistrano_stage_privileges/MIT-LICENSE
  41. +24 −0 vendor/plugins/webistrano_stage_privileges/README
  42. +22 −0 vendor/plugins/webistrano_stage_privileges/Rakefile
  43. +160 −0 ..._stage_privileges/generators/stage_privileges_extensions/stage_privileges_extensions_generator.rb
  44. +14 −0 .../webistrano_stage_privileges/generators/stage_privileges_extensions/templates/stage_privileges.rb
  45. +29 −0 ...trano_stage_privileges/generators/stage_privileges_extensions/templates/stage_users_controller.rb
  46. +5 −0 ...ugins/webistrano_stage_privileges/generators/stage_privileges_extensions/templates/stages_user.rb
  47. +42 −0 ...strano_stage_privileges/generators/stage_privileges_extensions/templates/views/_projects.html.erb
  48. +32 −0 ...ebistrano_stage_privileges/generators/stage_privileges_extensions/templates/views/_users.html.erb
  49. +161 −0 .../webistrano_stage_privileges/generators/stage_privileges_extensions/templates/views/show.html.erb
  50. +1 −0 vendor/plugins/webistrano_stage_privileges/init.rb
  51. 0 vendor/plugins/webistrano_stage_privileges/install.rb
  52. +9 −0 vendor/plugins/webistrano_stage_privileges/lib/webistrano_stage_privileges.rb
  53. +4 −0 vendor/plugins/webistrano_stage_privileges/tasks/webistrano_stage_privileges_tasks.rake
  54. +8 −0 vendor/plugins/webistrano_stage_privileges/test/webistrano_stage_privileges_test.rb
  55. 0 vendor/plugins/webistrano_stage_privileges/uninstall.rb
View
19 app/controllers/deployments_controller.rb
@@ -1,6 +1,8 @@
class DeploymentsController < ApplicationController
before_filter :load_stage
+ before_filter :ensure_user_access, :except => [:show, :latest, :index]
+
before_filter :ensure_deployment_possible, :only => [:new, :create]
# GET /projects/1/stages/1/deployments
@@ -101,6 +103,23 @@ def cancel
end
protected
+
+ def ensure_user_access
+
+ if (current_user.stages.include?( @stage) && !current_user.read_only(@stage)) || ensure_admin
+
+ return true
+
+ else
+
+ flash[:notice] = "Action not allowed"
+
+ return false
+
+ end
+
+ end
+
def ensure_deployment_possible
if current_stage.deployment_possible?
true
View
27 app/controllers/project_users_controller.rb
@@ -0,0 +1,27 @@
+class ProjectUsersController < ApplicationController
+
+ protect_from_forgery :except => [:create, :destroy]
+ before_filter :ensure_admin, :only => [:destroy, :create]
+
+ def create
+ @project = Project.find params[:project_id]
+ @project_user = User.find params[:project_user][:id]
+ @project.users << @project_user unless @project.user_ids.include?(@project_user.id)
+ redirect_to project_path(@project.id)
+ end
+
+ def destroy
+ @project = Project.find params[:project_id]
+ @project_user = User.find params[:id]
+ @project.users.delete @project_user if @project.user_ids.include?(@project_user.id)
+
+ @project.stages.each do |stage|
+
+ stage.users.delete @project_user if stage.user_ids.include?(@project_user.id)
+
+ end
+
+ redirect_to project_path(@project.id)
+ end
+
+end
View
19 app/controllers/projects_controller.rb
@@ -1,4 +1,6 @@
class ProjectsController < ApplicationController
+ before_filter :ensure_user, :only => [:show]
+
before_filter :load_templates, :only => [:new, :create, :edit, :update]
before_filter :ensure_admin, :only => [:new, :edit, :destroy, :create, :update]
@@ -105,6 +107,23 @@ def destroy
end
protected
+
+ def ensure_user
+
+ if current_user.projects.include?( Project.find(params[:id])) || ensure_admin
+
+ return true
+
+ else
+
+ flash[:notice] = "Action not allowed"
+
+ return false
+
+ end
+
+ end
+
def load_templates
@templates = ProjectConfiguration.templates.sort.collect do |k,v|
[k.to_s.titleize, k.to_s]
View
17 app/controllers/roles_controller.rb
@@ -72,6 +72,23 @@ def destroy
end
protected
+
+ def ensure_user_access
+
+ if (current_user.stages.include?(@stage) && !current_user.read_only(@stage)) || ensure_admin
+
+ return true
+
+ else
+
+ flash[:notice] = "Action not allowed"
+
+ return false
+
+ end
+
+ end
+
def load_host_choices
@host_choices = Host.find(:all, :order => "name ASC").collect {|h| [ h.name, h.id ] }
end
View
29 app/controllers/stage_users_controller.rb
@@ -0,0 +1,29 @@
+
+class StageUsersController < ApplicationController
+
+ protect_from_forgery :except => [:create, :destroy]
+ before_filter :ensure_admin, :only => [:destroy, :create]
+
+ def create
+ @stage = Stage.find params[:stage_id]
+ user = User.find params[:stage_user][:id]
+ read_only = params[:stage_user][:read_only]
+ if user and @stage and !@stage.user_ids.include?(user.id) then
+ stages_user = StagesUser.new
+ stages_user.stage_id = @stage.id
+ stages_user.user_id = user.id
+ stages_user.read_only = (read_only.to_i != 0)?true:false
+ stages_user.save
+ end
+ redirect_to project_stage_path(@stage.project.id,@stage)
+ end
+
+ def destroy
+ @stage = Stage.find params[:stage_id]
+ @stage_user = User.find params[:id]
+ @stage.users.delete @stage_user if @stage.user_ids.include?(@stage_user.id)
+ redirect_to project_stage_path(@stage.project.id,@stage)
+ end
+
+end
+
View
43 app/controllers/stages_controller.rb
@@ -1,6 +1,11 @@
class StagesController < ApplicationController
before_filter :load_project
+
+ before_filter :ensure_user, :only => [:show]
+
+ before_filter :ensure_user_access, :only => [:edit, :update, :destroy, :capfile, :recipes]
+
# GET /projects/1/stages.xml
def index
@@ -104,7 +109,43 @@ def capfile
# GET | PUT /projects/1/stages/1/recipes
# GET /projects/1/stages/1/recipes.xml
- def recipes
+
+
+ def ensure_user
+
+ if current_user.stages.include?( Stage.find(params[:id])) || ensure_admin
+
+ return true
+
+ else
+
+ flash[:notice] = "Action not allowed"
+
+ return false
+
+ end
+
+ end
+
+ def ensure_user_access
+
+ @stage = Stage.find(params[:id])
+
+ if (current_user.stages.include?(@stage) && !current_user.read_only(@stage)) || ensure_admin
+
+ return true
+
+ else
+
+ flash[:notice] = "Action not allowed"
+
+ return false
+
+ end
+
+ end
+
+ def recipes
@stage = current_project.stages.find(params[:id])
if request.put?
@stage.recipe_ids = params[:stage][:recipe_ids] rescue []
View
2 app/models/project.rb
@@ -1,4 +1,6 @@
class Project < ActiveRecord::Base
+ has_and_belongs_to_many :users
+
has_many :stages, :dependent => :destroy, :order => 'name ASC'
has_many :deployments, :through => :stages
has_many :configuration_parameters, :dependent => :destroy, :class_name => "ProjectConfiguration", :order => 'name ASC'
View
12 app/models/stage.rb
@@ -1,4 +1,14 @@
-class Stage < ActiveRecord::Base
+class Stage < ActiveRecord::Base
+
+ has_many :stages_user
+
+ has_many :users , :through => :stages_user
+
+
+ has_many :stages_user
+
+ has_many :users , :through => :stages_user
+
belongs_to :project
has_and_belongs_to_many :recipes
has_many :roles, :dependent => :destroy, :order => "name ASC"
View
5 app/models/stages_user.rb
@@ -0,0 +1,5 @@
+class StagesUser < ActiveRecord::Base
+ belongs_to :stage
+ belongs_to :user
+
+end
View
31 app/models/user.rb
@@ -1,5 +1,36 @@
require 'digest/sha1'
class User < ActiveRecord::Base
+ has_and_belongs_to_many :projects
+
+ has_many :stages_user
+
+ has_many :stages , :through => :stages_user
+
+ def read_only(stage)
+
+ su = stages_user.find_by_stage_id(stage.id)
+
+ return su.read_only? if su
+
+ return false
+
+ end
+
+ def access(stage)
+
+ (stages_user.find_by_stage_id(stage.id).read_only?)? 'read only' : 'full access'
+
+ end
+
+ def project_stages(project)
+
+ return stages if !stages
+
+ stages.select{|stage| stage.project.id == project.id}
+
+ end
+
+
has_many :deployments, :dependent => :nullify, :order => 'created_at DESC'
# Virtual attribute for the unencrypted password
View
21 app/views/layouts/_projects.html.erb
@@ -1,7 +1,8 @@
+<%projects = current_user.admin? ? Project.find(:all) : current_user.projects%>
<div id="projects_open_content" style="<%=h show_if_opened(status) %>">
- <% if Project.count > 0 %>
- <% for project in Project.find(:all, :order => "name ASC") %>
- <a href="<%= project_path(project) %>" class="menu_link <%=h active_link_class(project) %>" title="<%=h project.name %>">
+ <% if projects.length > 0 %>
+ <% for project in projects.sort{|a,b| a.name <=> b.name} %>
+ <a href="<%= project_path(project) %>" class="menu_link <%=h active_link_class(project) %>">
<div class="menu_icons">
<%= image_tag('peritor_theme/arrow_menu_right.gif', :width => '20', :height => '20', :border => '0', :style => "#{h( do_not_show_stages_of_project(project))}", :id => "#{h(dom_id(project))}_arrow_right", :onclick => "open_menu('#{h( dom_id(project))}'); return false;" )%>
@@ -12,28 +13,30 @@
</div>
</a>
<div id="<%=h dom_id(project) %>_stages" style="<%=h show_stages_of_project(project) %>">
- <% if project.stages.count > 0 %>
- <% for stage in project.stages %>
- <a href="<%= project_stage_path(project, stage) %>" class="menu_link <%=h active_link_class(stage) %>" title="<%=h stage.name %>">
+ <%stages = current_user.admin? ? project.stages : current_user.project_stages(project)%>
+ <% if stages.count > 0 %>
+ <% for stage in stages %>
+
+ <a href="<%= project_stage_path(project, stage) %>" class="menu_link <%=h active_link_class(stage) %>">
<div class="menu_link_title" style="padding-left: 30px; *padding-left: 33px"><%=h stage.name %></div>
</a>
<% end %>
- <% else %>
+ <% elsif current_user.admin?%>
<a href="<%= new_project_stage_path(project) %>" class="menu_link menu_link_new">
<div class="menu_link_title" style="padding-left: 30px; *padding-left: 33px">New stage</div>
</a>
<% end %>
</div>
<% end %>
<% else %>
- <div class="menu_item">No project created yet</div>
+ <div class="menu_item">No projects for you</div>
<a href="<%= new_project_path %>" class="menu_link menu_link_create">New project</a>
<% end %>
</div>
<div id="projects_closed_content" style="<%=h show_if_closed(status) %>">
<a href="javascript:open_menu_box('projects')" class="menu_link menu_link_create">
<div class="menu_link_title">
- <%=h pluralize(Project.count, 'project')%>
+ <%=h pluralize(projects.length, 'project')%>
</div>
</a>
</div>
View
24 app/views/projects/_users.html.erb
@@ -0,0 +1,24 @@
+<% if @project.users.empty? %>
+ <br/>
+ No users added yet.<br />
+ <br/>
+<% else %>
+ <table class="sortable">
+ <% for user in @project.users %>
+ <tr class="<%= cycle :even, :odd, :name => 'users' %>">
+ <td nowrap><%= link_to h(user.login), user_path(user) %></td>
+ <% if current_user.admin? -%>
+ <td><%= link_to 'Remove', project_project_user_path(@project, user), :confirm => 'Are you sure?', :method => :delete %></td>
+ <% end -%>
+ </tr>
+ <% end %>
+ </table>
+<% end %>
+
+<% if current_user.admin? %>
+<form action='<%=project_project_users_path(@project)%>' method='post'>
+ <label>Add user: </label>
+ <%=select 'project_user', 'id', User.find(:all).reject{|u| @project.user_ids.include?(u.id)}.collect{|u| [u.login, u.id]}%>
+ <input type='submit' value='Add' />
+</form>
+<%end%>
View
28 app/views/projects/index.html.erb
@@ -1,10 +1,12 @@
+<%projects = current_user.admin? ? Project.find(:all) : current_user.projects%>
+<h2>Projects</h2>
+
<fieldset class="fieldset">
- <legend> <%=h pluralize(Project.count, 'Project')%> listed</legend>
+ <legend> <%=h pluralize(projects.length, 'Project')%> listed for you</legend>
-<% if @projects.empty? %>
+<% if projects.empty? %>
<br/>
- No projects configured yet.<br />
- Please add a project.
+ No projects listed for you.<br />
<br/>
<% else %>
<table class="sortable">
@@ -15,34 +17,26 @@
<th width="1%">#Deploy.</th>
<th width="1%">Created At</th>
</tr>
- <% for project in @projects %>
+ <% for project in projects %>
<tr class="<%= cycle :even, :odd, :name => 'projects' %>">
<td><%= link_to h(project.name), project_path(project) %></td>
<td><%=h project.description %></td>
<td><%=h project.stages.count %></td>
<td><%=h project.deployments.count %></td>
<td><%=h project.created_at.to_s(:date_with_day) %></td>
<td><%= link_to 'Edit', edit_project_path(project) %></td>
- <td><%= link_to 'Clone', clone_form_path(project) %></td>
+ <%if current_user.admin?%>
<td><%= link_to 'Delete', project_path(project), :confirm => 'Are you sure?', :method => :delete %></td>
+ <%end%>
</tr>
<% end %>
</table>
<% end %>
<br />
+<%if current_user.admin?%>
<%= link_to 'New project', new_project_path, :class => 'arrow_link' %>
+<%end%>
</fieldset>
-
-<% content_for(:breadcrumb) do %>
- <% breadcrumb_box do %>
- <%= link_to "Projects", projects_path %>
- <% end %>
-<% end %>
-
-<% content_for(:page_title) do %>
- <% @page_title = "Projects" %>
- <h2>Projects</h2>
-<% end %>
View
90 app/views/projects/show.html.erb
@@ -1,39 +1,48 @@
-<div class="special_box">
- <div class="special_box_top"></div>
- <div class="special_box_middle stages_box">
- <% if @project.stages.count > 0 %>
- <p><strong>Choose a stage:</strong></p>
- <% for stage in @project.stages %>
- <p><%= link_to h(stage.name), project_stage_path(@project, stage), :class => 'arrow_link' %></p>
- <% end %>
- <% else %>
- <p><strong>No stage configured yet</strong></p>
- <%= link_to 'New stage', new_project_stage_path(@project), :class => 'arrow_link' %>
+<h2>Project: <%=h @project.name %></h2>
+
+<div class="special_box stages_box">
+ <% if @project.stages.count > 0 %>
+ <p><strong>Choose a stage:</strong></p>
+ <% for stage in @project.stages %>
+ <p><%= link_to h(stage.name), project_stage_path(@project, stage), :class => 'arrow_link' %></p>
<% end %>
- </div>
- <div class="special_box_bottom"></div>
+ <% else %>
+ <p><strong>No stage configured yet</strong></p>
+ <%= link_to 'New stage', new_project_stage_path(@project), :class => 'arrow_link' %>
+ <% end %>
</div>
-<div class="box">
- <div class="box_top"></div>
- <div class="box_middle">
- <p>
- <b>Description:</b>
- <%=h @project.description %>
- </p>
- <p>
- <b>Project Type:</b>
- <%=h @project.template %>
- </p>
- <p>
- <b>#Deployments:</b>
- <%=h @project.deployments.count %>
- </p><br />
- <%= link_to 'Edit project', edit_project_path(@project), :class => 'arrow_link' %> |
- <%= link_to 'Clone project', clone_form_path(@project), :class => 'arrow_link' %> |
- <%= link_to 'Delete project', project_path(@project), :confirm => 'Are you sure?', :method => :delete, :class => 'arrow_link' %>
+<div style="float: left; width:380px;">
+ <div class="box_top_left">
+ <div class="box_top_right">
+ <div class="box_top">
+ </div>
+ </div>
+ </div>
+ <div class="box_body" style="min-height: 123px;">
+ <div>
+ <p>
+ <b>Description:</b>
+ <%=h @project.description %>
+ </p>
+ <p>
+ <b>Project Type:</b>
+ <%=h @project.template %>
+ </p>
+ <p>
+ <b>#Deployments:</b>
+ <%=h @project.deployments.count %>
+ </p><br />
+ <%= link_to 'Edit Project', edit_project_path(@project), :class => 'arrow_link' %> |
+ <%= link_to 'Delete', project_path(@project), :confirm => 'Are you sure?', :method => :delete, :class => 'arrow_link' %>
+ </div>
+ </div>
+ <div class="box_bottom_left">
+ <div class="box_bottom_right">
+ <div class="box_bottom">
+ </div>
+ </div>
</div>
- <div class="box_bottom"></div>
</div>
<div class="clear"></div>
@@ -58,20 +67,7 @@
<br /><br />
<fieldset class="fieldset">
- <legend>Recent Deployments</legend>
- <%= render(:partial => 'deployments')%>
+ <legend>Privileged users</legend>
+ <%= render(:partial => 'users')%>
<br />
</fieldset>
-
-<% content_for(:breadcrumb) do %>
- <% breadcrumb_box do %>
- <%= link_to "Manage projects", projects_path, :style => "float:right", :class => "arrow_link" %>
- <%= link_to "Projects", projects_path %> &gt;
- Project <%= link_to current_project.name, project_path(current_project) %>
- <% end %>
-<% end %>
-
-<% content_for(:page_title) do %>
- <% @page_title = "Project #{h(current_project.name)}" %>
- <h2>Project <%= link_to h(current_project.name), project_path(current_project) %></h2>
-<% end %>
View
32 app/views/stages/_users.html.erb
@@ -0,0 +1,32 @@
+<!--alimaher-->
+<% if @stage.users.empty? %>
+ <br/>
+ No users added yet.<br />
+ <br/>
+<% else %>
+ <table class="sortable">
+ <% for user in @stage.users %>
+ <tr class="<%= cycle :even, :odd, :name => 'users' %>">
+ <!--alimaher-->
+ <td nowrap><%= link_to h("#{user.login} (#{user.access(@stage)})"), user_path(user) %></td>
+ <!--end alimaher-->
+ <% if current_user.admin? -%>
+ <td><%= link_to 'Remove', project_stage_stage_user_path(@stage.project, @stage, user), :confirm => 'Are you sure?', :method => :delete %></td>
+ <% end -%>
+ </tr>
+ <% end %>
+ </table>
+<% end %>
+
+<% if current_user.admin? %>
+<form action='<%=project_stage_stage_users_path(@stage.project,@stage)%>' method='post'>
+ <label>Add user: </label>
+ <%=select 'stage_user', 'id', @stage.project.users.reject{|u| @stage.user_ids.include?(u.id)}.collect{|u| [u.login, u.id]}%>
+ <!--alimaher-->
+ <%= check_box 'stage_user','read_only', {:checked => false, :class => 'noframe'} %>
+ <label for="read_only">read only</label>
+ <!--end alimaher-->
+ <input type='submit' value='Add' />
+</form>
+<%end%>
+<!--end alimaher-->
View
40 app/views/stages/show.html.erb
@@ -1,4 +1,7 @@
<div class="special_box">
+ <!--alimaher-->
+ <%if !current_user.read_only(@stage) || current_user.admin? %>
+ <!--end alimaher-->
<div class="special_box_top"></div>
<div class="special_box_middle deployments_box">
<p><%= link_to 'Deploy', new_project_stage_deployment_path(current_project, @stage) + '?task=deploy', :class => 'arrow_link' %></p>
@@ -15,7 +18,11 @@
:onclick => "location.href='#{tasks_project_stage_path(current_project, @stage)}#' + $F('task'); return false" %>
</p>
</div>
+
<div class="special_box_bottom"></div>
+ <!--alimaher-->
+ <%end%>
+ <!--end alimaher-->
</div>
<div class="box">
@@ -37,10 +44,16 @@
<b>#Hosts:</b>
<%=h @stage.hosts.count %>
</p>
+ <!--alimaher-->
+ <%if !current_user.read_only(@stage) || current_user.admin? %>
+ <!--end alimaher-->
<br />
<%= link_to 'Edit stage', edit_project_stage_path(current_project, @stage), :class => 'arrow_link' %> |
<%= link_to 'Delete stage', project_stage_path(current_project, @stage), :confirm => 'Are you sure?', :method => :delete, :class => 'arrow_link' %> |
<%= link_to 'Export capfile', {:action => 'capfile', :project_id => current_project, :id => @stage}, {:onclick => "loadWindow('#{url_for(:action => 'capfile', :project_id => current_project, :id => @stage)}'); return false", :class => 'arrow_link'} %>
+ <!--alimaher-->
+ <%end%>
+ <!--end alimaher-->
</div>
<div class="box_bottom"></div>
</div>
@@ -57,27 +70,45 @@
<%= render(:partial => 'effective_config')%>
<br />
</div>
+ <!--alimaher-->
+ <%if !current_user.read_only(@stage) || current_user.admin? %>
+ <!--end alimaher-->
<%= link_to 'New configuration', new_project_stage_stage_configuration_path(current_project, @stage), :class => 'arrow_link' %> |
<a id="s_e_c" href="#" onclick="show_effective_config(); return false" class="arrow_link">Show effective configuration</a>
<a id="h_e_c" href="#" onclick="hide_effective_config(); return false" class="arrow_link" style="display:none;">Hide effective configuration</a>
+ <!--alimaher-->
+ <%end%>
+ <!--end alimaher-->
</fieldset>
<br /><br />
<fieldset class="fieldset">
<legend>Used recipes</legend>
<%= render(:partial => 'recipes')%>
+ <!--alimaher-->
+ <%if !current_user.read_only(@stage) || current_user.admin? %>
+ <!--end alimaher-->
<br />
<%= link_to 'Manage stage recipes', {:action => 'recipes', :project_id => current_project, :id => @stage} , :class => 'arrow_link'%>
+ <!--alimaher-->
+ <%end%>
+ <!--end alimaher-->
</fieldset>
<br /><br />
<fieldset class="fieldset">
<legend>Deployed hosts</legend>
<%= render(:partial => 'roles')%>
+ <!--alimaher-->
+ <%if !current_user.read_only(@stage) || current_user.admin? %>
+ <!--end alimaher-->
<br />
<%= link_to 'Add host', new_project_stage_role_path(current_project, @stage) , :class => 'arrow_link'%>
+ <!--alimaher-->
+ <%end%>
+ <!--end alimaher-->
</fieldset>
<br /><br />
@@ -87,6 +118,15 @@
<%= render(:partial => 'deployments')%>
</fieldset>
+<!--alimaher-->
+<br /><br />
+<fieldset class="fieldset">
+ <legend>Privileged users</legend>
+ <%= render(:partial => 'users')%>
+ <br />
+</fieldset>
+<!--end alimaher-->
+
<br />
<% content_for(:page_scripts) do %>
<script type="text/javascript">
View
2 config.ru
@@ -0,0 +1,2 @@
+require File.dirname(__FILE__) + '/config/environment'
+run ActionController::Dispatcher.new
View
8 config/routes.rb
@@ -20,10 +20,16 @@
map.resources :hosts
map.resources :recipes, :collection => {:preview => :get}
map.resources :projects, :member => {:dashboard => :get} do |projects|
+ projects.resources :project_users
+
projects.resources :project_configurations
projects.resources :stages, :member => {:capfile => :get, :recipes => :any, :tasks => :get} do |stages|
- stages.resources :stage_configurations
+
+stages.resources :stage_users
+
+stages.resources :stage_users
+stages.resources :stage_configurations
stages.resources :roles
stages.resources :deployments, :collection => {:latest => :get}, :member => {:cancel => :post}
end
View
12 db/migrate/20120110001522_create_projects_users.rb
@@ -0,0 +1,12 @@
+class CreateProjectsUsers < ActiveRecord::Migration
+ def self.up
+ create_table :projects_users, :id => false do |t|
+ t.integer :project_id
+ t.integer :user_id
+ end
+ end
+
+ def self.down
+ drop_table :projects_users
+ end
+end
View
14 db/migrate/20120110003946_stage_privileges.rb
@@ -0,0 +1,14 @@
+class StagePrivileges < ActiveRecord::Migration
+ def self.up
+ create_table :stages_users, :id => false do |t|
+ t.integer :stage_id
+ t.integer :user_id
+ t.boolean :read_only
+ end
+ end
+
+ def self.down
+ drop_table :stages_users
+ end
+
+end
View
13 db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110512144542) do
+ActiveRecord::Schema.define(:version => 20120110001522) do
create_table "configuration_parameters", :force => true do |t|
t.string "name"
@@ -62,6 +62,11 @@
t.datetime "updated_at"
end
+ create_table "projects_users", :id => false, :force => true do |t|
+ t.integer "project_id"
+ t.integer "user_id"
+ end
+
create_table "recipe_versions", :force => true do |t|
t.integer "recipe_id"
t.integer "version"
@@ -116,6 +121,12 @@
add_index "stages", ["project_id"], :name => "index_stages_on_project_id"
+ create_table "stages_users", :id => false, :force => true do |t|
+ t.integer "stage_id"
+ t.integer "user_id"
+ t.boolean "read_only"
+ end
+
create_table "users", :force => true do |t|
t.string "login"
t.string "email"
View
3 lib/webistrano/deployer.rb
@@ -22,8 +22,7 @@ def initialize(deployment)
@deployment = deployment
- if(@deployment.task && !@deployment.new_record?)
- # a read deployment
+ if(!@deployment[:task].nil? && !@deployment.new_record?) # a read deployment
@logger = Webistrano::Logger.new(deployment)
@logger.level = Webistrano::Logger::TRACE
validate
View
0 script/generate 100755 → 100644
File mode changed.
View
20 vendor/plugins/webistrano_privileges/MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008 [name of plugin creator]
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
24 vendor/plugins/webistrano_privileges/README
@@ -0,0 +1,24 @@
+WebistranoPrivileges
+====================
+
+webistrano_privileges is a simple Rails plugin that introduces access control to Webistrano-1.3. After applying the plugin to your working webistrano project copy, and running two shell commands, webistrano will be accomodating a simple access control scheme. Admins can manipulate all projects. Non-admins can manipulate only THEIR projects. Admins can add and remove users to projects.
+
+What the plugin basically does is:
+- it generates a migration for a many-to-many relation between users and projects.
+- it generates a route and a controller for adding and removing users from projects
+- it replaces some views to present the added functionality.
+- it introduces some logic to secure unauthorized access to projects from non-related users.
+
+
+After installing the plugin:
+============================
+- run the generate command, accept whenever prompted for overwriting existing files:
+
+ >> ruby script/generate privileges_extensions
+
+- migrate
+
+ >> rake db:migrate RAILS_ENV=production
+
+
+===========================================================================
View
22 vendor/plugins/webistrano_privileges/Rakefile
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the webistrano_privileges plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the webistrano_privileges plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'WebistranoPrivileges'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
View
33 ...webistrano_privileges/generators/privileges_extensions/privileges_extensions_generator.rb
@@ -0,0 +1,33 @@
+class PrivilegesExtensionsGenerator < Rails::Generator::Base
+
+ def manifest
+ #added files and changed views
+ record do |m|
+ m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "create_projects_users"
+ m.template 'controller.rb', 'app/controllers/project_users_controller.rb'
+ m.template 'views/show_project.html.erb', 'app/views/projects/show.html.erb'
+ m.template 'views/users_partial.html.erb', 'app/views/projects/_users.html.erb'
+ m.template 'views/projects_partial.html.erb', 'app/views/layouts/_projects.html.erb'
+ m.template 'views/projects_index.html.erb', 'app/views/projects/index.html.erb'
+
+ #added lines
+ m.gsub_file 'app/models/project.rb', /(#{Regexp.escape("class Project < ActiveRecord::Base")})/mi do |match|
+ "#{match}\n has_and_belongs_to_many :users\n"
+ end
+
+ m.gsub_file 'app/models/user.rb', /(#{Regexp.escape("class User < ActiveRecord::Base")})/mi do |match|
+ "#{match}\n has_and_belongs_to_many :projects\n"
+ end
+
+ m.gsub_file 'config/routes.rb', /(#{Regexp.escape("map.resources :projects, :member => {:dashboard => :get} do |projects|")})/mi do |match|
+ "#{match}\n projects.resources :project_users\n"
+ end
+
+ m.gsub_file 'app/controllers/application.rb', /(#{Regexp.escape("class ApplicationController < ActionController::Base")})/mi do |match|
+ "#{match}\n include WebistranoPrivileges::ControllerExtensions\n before_filter :setup_privileges\n"
+ end
+
+ end
+ end
+
+end
View
20 ...or/plugins/webistrano_privileges/generators/privileges_extensions/templates/controller.rb
@@ -0,0 +1,20 @@
+class ProjectUsersController < ApplicationController
+
+ protect_from_forgery :except => [:create, :destroy]
+ before_filter :ensure_admin, :only => [:destroy, :create]
+
+ def create
+ @project = Project.find params[:project_id]
+ @project_user = User.find params[:project_user][:id]
+ @project.users << @project_user unless @project.user_ids.include?(@project_user.id)
+ redirect_to project_path(@project.id)
+ end
+
+ def destroy
+ @project = Project.find params[:project_id]
+ @project_user = User.find params[:id]
+ @project.users.delete @project_user if @project.user_ids.include?(@project_user.id)
+ redirect_to project_path(@project.id)
+ end
+
+end
View
12 vendor/plugins/webistrano_privileges/generators/privileges_extensions/templates/migration.rb
@@ -0,0 +1,12 @@
+class CreateProjectsUsers < ActiveRecord::Migration
+ def self.up
+ create_table :projects_users, :id => false do |t|
+ t.integer :project_id
+ t.integer :user_id
+ end
+ end
+
+ def self.down
+ drop_table :projects_users
+ end
+end
View
42 ...trano_privileges/generators/privileges_extensions/templates/views/projects_index.html.erb
@@ -0,0 +1,42 @@
+<%%projects = current_user.admin? ? Project.find(:all) : current_user.projects%>
+<h2>Projects</h2>
+
+<fieldset class="fieldset">
+ <legend> <%%=h pluralize(projects.length, 'Project')%> listed for you</legend>
+
+<%% if projects.empty? %>
+<br/>
+ No projects listed for you.<br />
+ <br/>
+<%% else %>
+ <table class="sortable">
+ <tr>
+ <th width="1%">Name</th>
+ <th width="96%">Description</th>
+ <th width="1%">#Stages</th>
+ <th width="1%">#Deploy.</th>
+ <th width="1%">Created At</th>
+ </tr>
+ <%% for project in projects %>
+ <tr class="<%%= cycle :even, :odd, :name => 'projects' %>">
+ <td><%%= link_to h(project.name), project_path(project) %></td>
+ <td><%%=h project.description %></td>
+ <td><%%=h project.stages.count %></td>
+ <td><%%=h project.deployments.count %></td>
+ <td><%%=h project.created_at.to_s(:date_with_day) %></td>
+ <td><%%= link_to 'Edit', edit_project_path(project) %></td>
+ <%%if current_user.admin?%>
+ <td><%%= link_to 'Delete', project_path(project), :confirm => 'Are you sure?', :method => :delete %></td>
+ <%%end%>
+ </tr>
+ <%% end %>
+ </table>
+<%% end %>
+
+<br />
+
+<%%if current_user.admin?%>
+<%%= link_to 'New project', new_project_path, :class => 'arrow_link' %>
+<%%end%>
+
+</fieldset>
View
40 ...ano_privileges/generators/privileges_extensions/templates/views/projects_partial.html.erb
@@ -0,0 +1,40 @@
+<%%projects = current_user.admin? ? Project.find(:all) : current_user.projects%>
+<div id="projects_open_content" style="<%%=h show_if_opened(status) %>">
+ <%% if projects.length > 0 %>
+ <%% for project in projects.sort{|a,b| a.name <=> b.name} %>
+ <a href="<%%= project_path(project) %>" class="menu_link <%%=h active_link_class(project) %>">
+ <div class="menu_icons">
+
+ <%%= image_tag('peritor_theme/arrow_menu_right.gif', :width => '20', :height => '20', :border => '0', :style => "#{h( do_not_show_stages_of_project(project))}", :id => "#{h(dom_id(project))}_arrow_right", :onclick => "open_menu('#{h( dom_id(project))}'); return false;" )%>
+
+ <%%= image_tag('peritor_theme/arrow_menu_down.gif', :width => '20', :height => '20', :border => '0', :style => "#{h( show_stages_of_project(project))}", :id => "#{h(dom_id(project))}_arrow_down", :onclick => "close_menu('#{h( dom_id(project))}'); return false;" )%></div>
+ <div class="menu_link_title has_submenu">
+ <%%=h project.name %>
+ </div>
+ </a>
+ <div id="<%%=h dom_id(project) %>_stages" style="<%%=h show_stages_of_project(project) %>">
+ <%% if project.stages.count > 0 %>
+ <%% for stage in project.stages %>
+ <a href="<%%= project_stage_path(project, stage) %>" class="menu_link <%%=h active_link_class(stage) %>">
+ <div class="menu_link_title" style="padding-left: 30px; *padding-left: 33px"><%%=h stage.name %></div>
+ </a>
+ <%% end %>
+ <%% else %>
+ <a href="<%%= new_project_stage_path(project) %>" class="menu_link menu_link_new">
+ <div class="menu_link_title" style="padding-left: 30px; *padding-left: 33px">New stage</div>
+ </a>
+ <%% end %>
+ </div>
+ <%% end %>
+ <%% else %>
+ <div class="menu_item">No projects for you</div>
+ <a href="<%%= new_project_path %>" class="menu_link menu_link_create">New project</a>
+ <%% end %>
+</div>
+<div id="projects_closed_content" style="<%%=h show_if_closed(status) %>">
+ <a href="javascript:open_menu_box('projects')" class="menu_link menu_link_create">
+ <div class="menu_link_title">
+ <%%=h pluralize(projects.length, 'project')%>
+ </div>
+ </a>
+</div>
View
73 ...istrano_privileges/generators/privileges_extensions/templates/views/show_project.html.erb
@@ -0,0 +1,73 @@
+<h2>Project: <%%=h @project.name %></h2>
+
+<div class="special_box stages_box">
+ <%% if @project.stages.count > 0 %>
+ <p><strong>Choose a stage:</strong></p>
+ <%% for stage in @project.stages %>
+ <p><%%= link_to h(stage.name), project_stage_path(@project, stage), :class => 'arrow_link' %></p>
+ <%% end %>
+ <%% else %>
+ <p><strong>No stage configured yet</strong></p>
+ <%%= link_to 'New stage', new_project_stage_path(@project), :class => 'arrow_link' %>
+ <%% end %>
+</div>
+
+<div style="float: left; width:380px;">
+ <div class="box_top_left">
+ <div class="box_top_right">
+ <div class="box_top">
+ </div>
+ </div>
+ </div>
+ <div class="box_body" style="min-height: 123px;">
+ <div>
+ <p>
+ <b>Description:</b>
+ <%%=h @project.description %>
+ </p>
+ <p>
+ <b>Project Type:</b>
+ <%%=h @project.template %>
+ </p>
+ <p>
+ <b>#Deployments:</b>
+ <%%=h @project.deployments.count %>
+ </p><br />
+ <%%= link_to 'Edit Project', edit_project_path(@project), :class => 'arrow_link' %> |
+ <%%= link_to 'Delete', project_path(@project), :confirm => 'Are you sure?', :method => :delete, :class => 'arrow_link' %>
+ </div>
+ </div>
+ <div class="box_bottom_left">
+ <div class="box_bottom_right">
+ <div class="box_bottom">
+ </div>
+ </div>
+ </div>
+</div>
+
+<div class="clear"></div>
+<br>
+
+<fieldset class="fieldset">
+ <legend>Project configuration</legend>
+ <%%= render(:partial => 'configs')%>
+ <br />
+ <%%= link_to 'New configuration', new_project_project_configuration_path(@project), :class => 'arrow_link' %>
+</fieldset>
+
+<br /><br />
+
+<fieldset class="fieldset">
+ <legend>Stages</legend>
+ <%%= render(:partial => 'stages')%>
+ <br />
+ <%%= link_to 'New stage', new_project_stage_path(@project), :class => 'arrow_link' %>
+</fieldset>
+
+<br /><br />
+
+<fieldset class="fieldset">
+ <legend>Privileged users</legend>
+ <%%= render(:partial => 'users')%>
+ <br />
+</fieldset>
View
24 ...strano_privileges/generators/privileges_extensions/templates/views/users_partial.html.erb
@@ -0,0 +1,24 @@
+<%% if @project.users.empty? %>
+ <br/>
+ No users added yet.<br />
+ <br/>
+<%% else %>
+ <table class="sortable">
+ <%% for user in @project.users %>
+ <tr class="<%%= cycle :even, :odd, :name => 'users' %>">
+ <td nowrap><%%= link_to h(user.login), user_path(user) %></td>
+ <%% if current_user.admin? -%>
+ <td><%%= link_to 'Remove', project_project_user_path(@project, user), :confirm => 'Are you sure?', :method => :delete %></td>
+ <%% end -%>
+ </tr>
+ <%% end %>
+ </table>
+<%% end %>
+
+<%% if current_user.admin? %>
+<form action='<%%=project_project_users_path(@project)%>' method='post'>
+ <label>Add user: </label>
+ <%%=select 'project_user', 'id', User.find(:all).reject{|u| @project.user_ids.include?(u.id)}.collect{|u| [u.login, u.id]}%>
+ <input type='submit' value='Add' />
+</form>
+<%%end%>
View
1 vendor/plugins/webistrano_privileges/init.rb
@@ -0,0 +1 @@
+require "#{RAILS_ROOT}/vendor/plugins/webistrano_privileges/lib/webistrano_privileges.rb"
View
0 vendor/plugins/webistrano_privileges/install.rb
No changes.
View
27 vendor/plugins/webistrano_privileges/lib/webistrano_privileges.rb
@@ -0,0 +1,27 @@
+module WebistranoPrivileges
+
+ module ControllerExtensions
+ def setup_privileges
+
+ #check if in a resource nested in a project
+ unless params[:project_id].nil?
+ unless current_user.admin? or current_user.project_ids.include?(params[:project_id].to_i)
+ flash[:notice] = "Action not allowed"
+ redirect_to home_path
+ return false
+ end
+ end
+
+ #check if in projects controller
+ if controller_name == "projects" and action_name != "index" and action_name != "dashboard"
+ unless current_user.admin? or current_user.project_ids.include?(params[:id].to_i)
+ flash[:notice] = "Action not allowed"
+ redirect_to home_path
+ return false
+ end
+ end
+
+ end
+ end
+
+end
View
4 vendor/plugins/webistrano_privileges/tasks/webistrano_privileges_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :webistrano_privileges do
+# # Task goes here
+# end
View
8 vendor/plugins/webistrano_privileges/test/webistrano_privileges_test.rb
@@ -0,0 +1,8 @@
+require 'test/unit'
+
+class WebistranoPrivilegesTest < Test::Unit::TestCase
+ # Replace this with your real tests.
+ def test_this_plugin
+ flunk
+ end
+end
View
0 vendor/plugins/webistrano_privileges/uninstall.rb
No changes.
View
20 vendor/plugins/webistrano_stage_privileges/MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008 [name of plugin creator]
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
24 vendor/plugins/webistrano_stage_privileges/README
@@ -0,0 +1,24 @@
+WebistranoStagePrivileges
+====================
+
+webistrano_stage_privileges is a simple Rails plugin that improves access control to Webistrano-1.5 which is intruduced by previous plugin 'webistrano_privileges'. Webistrano_stage_privileges is sponsored by PopCap Games. After applying the plugin to your working webistrano project copy with webistrano_privileges previously installed, and running two shell commands, webistrano will be accomodating a simple access control scheme to different project stages in addition to the project access control introduced by the previous plugin. Admins can manipulate all project stages to assign users with full access or read only access to different stages. Non-admins can manipulate only THEIR project stages. Admins can add and remove users to different stages by selecting them out of project users.
+
+What the plugin basically does is:
+- it generates a migration for a many-to-many relation between users and stages.
+- it generates a route and a controller for adding and removing users from stages
+- it replaces some views to present the added functionality.
+- it introduces some logic to secure unauthorized access (full/read only) to stages from non-related users.
+
+
+After installing the plugin:
+============================
+- run the generate command, accept whenever prompted for overwriting existing files:
+
+ >> ruby script/generate stage_privileges_extensions
+
+- migrate
+
+ >> rake db:migrate RAILS_ENV=production
+
+
+===========================================================================
View
22 vendor/plugins/webistrano_stage_privileges/Rakefile
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the webistrano_stage_privileges plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the webistrano_stage_privileges plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'WebistranoStagePrivileges'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
View
160 ...rivileges/generators/stage_privileges_extensions/stage_privileges_extensions_generator.rb
@@ -0,0 +1,160 @@
+class StagePrivilegesExtensionsGenerator < Rails::Generator::Base
+
+ def manifest
+ #added files
+ record do |m|
+ m.migration_template 'stage_privileges.rb', 'db/migrate', :migration_file_name => "stage_privileges"
+ #models
+ #13
+ m.template 'stages_user.rb','app/models/stages_user.rb'
+ #stage
+ #12
+ m.gsub_file 'app/models/stage.rb', /(#{Regexp.escape("class Stage < ActiveRecord::Base")})/mi do |match|
+ "#{match}\n
+ has_many :stages_user\n
+ has_many :users , :through => :stages_user\n"
+ end
+
+ m.gsub_file 'app/models/user.rb', /(#{Regexp.escape("has_and_belongs_to_many :projects")})/mi do |match|
+ "#{match}\n
+ has_many :stages_user\n
+ has_many :stages , :through => :stages_user\n
+ def read_only(stage)\n
+ su = stages_user.find_by_stage_id(stage.id)\n
+ return su.read_only? if su\n
+ return false\n
+ end\n
+ def access(stage)\n
+ (stages_user.find_by_stage_id(stage.id).read_only?)? 'read only' : 'full access'\n
+ end\n
+ def project_stages(project)\n
+ return stages if !stages\n
+ stages.select{|stage| stage.project.id == project.id}\n
+ end\n"
+ end
+
+ m.gsub_file 'app/controllers/project_users_controller.rb', /(#{Regexp.escape("@project.users.delete @project_user if @project.user_ids.include?(@project_user.id)")})/mi do |match|
+ "#{match}\n
+ @project.stages.each do |stage|\n
+ stage.users.delete @project_user if stage.user_ids.include?(@project_user.id)\n
+ end\n"
+ end
+
+ #8
+ m.template 'stage_users_controller.rb','app/controllers/stage_users_controller.rb'
+ #deployments_controller
+ #1
+ m.gsub_file 'app/controllers/deployments_controller.rb', /(#{Regexp.escape("before_filter :load_stage")})/mi do |match|
+ "#{match}\n before_filter :ensure_user_access, :except => [:show, :latest, :index]\n"
+ end
+ #2
+ m.gsub_file 'app/controllers/deployments_controller.rb', /(#{Regexp.escape("protected")})/mi do |match|
+ "#{match}\n
+ def ensure_user_access\n
+ if (current_user.stages.include?( @stage) && !current_user.read_only(@stage)) || ensure_admin\n
+ return true\n
+ else\n
+ flash[:notice] = \"Action not allowed\"\n
+ return false\n
+ end\n
+ end\n"
+ end
+
+ #projects_controller
+ #4
+ m.gsub_file 'app/controllers/projects_controller.rb', /(#{Regexp.escape("class ProjectsController < ApplicationController")})/mi do |match|
+ "#{match}\n before_filter :ensure_user, :only => [:show]\n"
+ end
+ #5
+ m.gsub_file 'app/controllers/projects_controller.rb', /(#{Regexp.escape("protected")})/mi do |match|
+ "#{match}\n
+ def ensure_user\n
+ if current_user.projects.include?( Project.find(params[:id])) || ensure_admin\n
+ return true\n
+ else\n
+ flash[:notice] = \"Action not allowed\"\n
+ return false\n
+ end\n
+ end\n"
+ end
+ #roles_controller
+ #6
+ m.gsub_file 'app/controllers/roles_controller.rb', /(#{Regexp.escape("protected")})/mi do |match|
+ "#{match}\n
+ def ensure_user_access\n
+ if (current_user.stages.include?(@stage) && !current_user.read_only(@stage)) || ensure_admin\n
+ return true\n
+ else\n
+ flash[:notice] = \"Action not allowed\"\n
+ return false\n
+ end\n
+ end\n"
+ end
+ #stage_configurations_controller
+ #7
+ m.gsub_file 'app/controllers/stage_configurations_controller.rb', /(#{Regexp.escape("protected")})/mi do |match|
+ "#{match}\n
+ def ensure_user_access\n
+ if (current_user.stages.include?( @stage) && !current_user.read_only(@stage)) || ensure_admin\n
+ return true\n
+ else\n
+ flash[:notice] = \"Action not allowed\"\n
+ return false\n
+ end\n
+ end\n"
+ end
+
+ #stages_controller
+ #9
+ m.gsub_file 'app/controllers/stages_controller.rb', /(#{Regexp.escape("before_filter :load_project")})/mi do |match|
+ "#{match}\n
+ before_filter :ensure_user, :only => [:show]\n
+ before_filter :ensure_user_access, :only => [:edit, :update, :destroy, :capfile, :recipes]\n"
+ end
+
+ #10
+ m.gsub_file 'app/controllers/stages_controller.rb', /(#{Regexp.escape("def recipes")})/mi do |match|
+ "\n
+ def ensure_user\n
+ if current_user.stages.include?( Stage.find(params[:id])) || ensure_admin\n
+ return true\n
+ else\n
+ flash[:notice] = \"Action not allowed\"\n
+ return false\n
+ end\n
+ end\n
+ def ensure_user_access\n
+ @stage = Stage.find(params[:id])\n
+ if (current_user.stages.include?(@stage) && !current_user.read_only(@stage)) || ensure_admin\n
+ return true\n
+ else\n
+ flash[:notice] = \"Action not allowed\"\n
+ return false\n
+ end\n
+ end\n
+ #{match}"
+ end
+
+ #routes.rb
+ #19
+ m.gsub_file 'config/routes.rb', /(#{Regexp.escape("stages.resources :stage_configurations")})/mi do |match|
+ "\nstages.resources :stage_users\n#{match}"
+ end
+
+ m.gsub_file 'config/routes.rb', /(#{Regexp.escape("stages.resources :stage_configurations")})/mi do |match|
+ "\nstages.resources :stage_users\n#{match}"
+ end
+
+ #15
+ m.template 'views/_projects.html.erb', 'app/views/layouts/_projects.html.erb'
+
+ #16
+ m.template 'views/_users.html.erb', 'app/views/stages/_users.html.erb'
+
+ #17
+ m.template 'views/show.html.erb', 'app/views/stages/show.html.erb'
+
+ end
+ end
+
+end
View
14 ...ano_stage_privileges/generators/stage_privileges_extensions/templates/stage_privileges.rb
@@ -0,0 +1,14 @@
+class StagePrivileges < ActiveRecord::Migration
+ def self.up
+ create_table :stages_users, :id => false do |t|
+ t.integer :stage_id
+ t.integer :user_id
+ t.boolean :read_only
+ end
+ end
+
+ def self.down
+ drop_table :stages_users
+ end
+
+end
View
29 ...age_privileges/generators/stage_privileges_extensions/templates/stage_users_controller.rb
@@ -0,0 +1,29 @@
+
+class StageUsersController < ApplicationController
+
+ protect_from_forgery :except => [:create, :destroy]
+ before_filter :ensure_admin, :only => [:destroy, :create]
+
+ def create
+ @stage = Stage.find params[:stage_id]
+ user = User.find params[:stage_user][:id]
+ read_only = params[:stage_user][:read_only]
+ if user and @stage and !@stage.user_ids.include?(user.id) then
+ stages_user = StagesUser.new
+ stages_user.stage_id = @stage.id
+ stages_user.user_id = user.id
+ stages_user.read_only = (read_only.to_i != 0)?true:false
+ stages_user.save
+ end
+ redirect_to project_stage_path(@stage.project.id,@stage)
+ end
+
+ def destroy
+ @stage = Stage.find params[:stage_id]
+ @stage_user = User.find params[:id]
+ @stage.users.delete @stage_user if @stage.user_ids.include?(@stage_user.id)
+ redirect_to project_stage_path(@stage.project.id,@stage)
+ end
+
+end
+
View
5 ...bistrano_stage_privileges/generators/stage_privileges_extensions/templates/stages_user.rb
@@ -0,0 +1,5 @@
+class StagesUser < ActiveRecord::Base
+ belongs_to :stage
+ belongs_to :user
+
+end
View
42 ...tage_privileges/generators/stage_privileges_extensions/templates/views/_projects.html.erb
@@ -0,0 +1,42 @@
+<%%projects = current_user.admin? ? Project.find(:all) : current_user.projects%>
+<div id="projects_open_content" style="<%%=h show_if_opened(status) %>">
+ <%% if projects.length > 0 %>
+ <%% for project in projects.sort{|a,b| a.name <=> b.name} %>
+ <a href="<%%= project_path(project) %>" class="menu_link <%%=h active_link_class(project) %>">
+ <div class="menu_icons">
+
+ <%%= image_tag('peritor_theme/arrow_menu_right.gif', :width => '20', :height => '20', :border => '0', :style => "#{h( do_not_show_stages_of_project(project))}", :id => "#{h(dom_id(project))}_arrow_right", :onclick => "open_menu('#{h( dom_id(project))}'); return false;" )%>
+
+ <%%= image_tag('peritor_theme/arrow_menu_down.gif', :width => '20', :height => '20', :border => '0', :style => "#{h( show_stages_of_project(project))}", :id => "#{h(dom_id(project))}_arrow_down", :onclick => "close_menu('#{h( dom_id(project))}'); return false;" )%></div>
+ <div class="menu_link_title has_submenu">
+ <%%=h project.name %>
+ </div>
+ </a>
+ <div id="<%%=h dom_id(project) %>_stages" style="<%%=h show_stages_of_project(project) %>">
+ <%%stages = current_user.admin? ? project.stages : current_user.project_stages(project)%>
+ <%% if stages.count > 0 %>
+ <%% for stage in stages %>
+
+ <a href="<%%= project_stage_path(project, stage) %>" class="menu_link <%%=h active_link_class(stage) %>">
+ <div class="menu_link_title" style="padding-left: 30px; *padding-left: 33px"><%%=h stage.name %></div>
+ </a>
+ <%% end %>
+ <%% elsif current_user.admin?%>
+ <a href="<%%= new_project_stage_path(project) %>" class="menu_link menu_link_new">
+ <div class="menu_link_title" style="padding-left: 30px; *padding-left: 33px">New stage</div>
+ </a>
+ <%% end %>
+ </div>
+ <%% end %>
+ <%% else %>
+ <div class="menu_item">No projects for you</div>
+ <a href="<%%= new_project_path %>" class="menu_link menu_link_create">New project</a>
+ <%% end %>
+</div>
+<div id="projects_closed_content" style="<%%=h show_if_closed(status) %>">
+ <a href="javascript:open_menu_box('projects')" class="menu_link menu_link_create">
+ <div class="menu_link_title">
+ <%%=h pluralize(projects.length, 'project')%>
+ </div>
+ </a>
+</div>
View
32 ...o_stage_privileges/generators/stage_privileges_extensions/templates/views/_users.html.erb
@@ -0,0 +1,32 @@
+<!--alimaher-->
+<%% if @stage.users.empty? %>
+ <br/>
+ No users added yet.<br />
+ <br/>
+<%% else %>
+ <table class="sortable">
+ <%% for user in @stage.users %>
+ <tr class="<%%= cycle :even, :odd, :name => 'users' %>">
+ <!--alimaher-->
+ <td nowrap><%%= link_to h("#{user.login} (#{user.access(@stage)})"), user_path(user) %></td>
+ <!--end alimaher-->
+ <%% if current_user.admin? -%>
+ <td><%%= link_to 'Remove', project_stage_stage_user_path(@stage.project, @stage, user), :confirm => 'Are you sure?', :method => :delete %></td>
+ <%% end -%>
+ </tr>
+ <%% end %>
+ </table>
+<%% end %>
+
+<%% if current_user.admin? %>
+<form action='<%%=project_stage_stage_users_path(@stage.project,@stage)%>' method='post'>
+ <label>Add user: </label>
+ <%%=select 'stage_user', 'id', @stage.project.users.reject{|u| @stage.user_ids.include?(u.id)}.collect{|u| [u.login, u.id]}%>
+ <!--alimaher-->
+ <%%= check_box 'stage_user','read_only', {:checked => false, :class => 'noframe'} %>
+ <label for="read_only">read only</label>
+ <!--end alimaher-->
+ <input type='submit' value='Add' />
+</form>
+<%%end%>
+<!--end alimaher-->
View
161 ...ano_stage_privileges/generators/stage_privileges_extensions/templates/views/show.html.erb
@@ -0,0 +1,161 @@
+<div class="special_box">
+ <!--alimaher-->
+ <%%if !current_user.read_only(@stage) || current_user.admin? %>
+ <!--end alimaher-->
+ <div class="special_box_top"></div>
+ <div class="special_box_middle deployments_box">
+ <p><%%= link_to 'Deploy', new_project_stage_deployment_path(current_project, @stage) + '?task=deploy', :class => 'arrow_link' %></p>
+ <p><%%= link_to 'Deploy and migrate', new_project_stage_deployment_path(current_project, @stage) + '?task=deploy:migrations', :class => 'arrow_link' %></p>
+ <p><%%= link_to 'Restart app servers', new_project_stage_deployment_path(current_project, @stage) + '?task=deploy:restart', :class => 'arrow_link' %></p>
+ <p><%%= link_to 'Setup', new_project_stage_deployment_path(current_project, @stage) + '?task=deploy:setup', :class => 'arrow_link' %></p>
+ <p>
+ <%%= select_tag('task', options_for_select(@task_list)) %>
+ </p>
+ <p>
+ <%%= link_to 'Execute', new_project_stage_deployment_path(current_project, @stage), :class => 'arrow_link',
+ :onclick => "location.href='#{new_project_stage_deployment_path(current_project, @stage)}?task=' + $F('task'); return false" %> |
+ <%%= link_to 'Info', tasks_project_stage_path(current_project, @stage), :class => 'arrow_link',
+ :onclick => "location.href='#{tasks_project_stage_path(current_project, @stage)}#' + $F('task'); return false" %>
+ </p>
+ </div>
+
+ <div class="special_box_bottom"></div>
+ <!--alimaher-->
+ <%%end%>
+ <!--end alimaher-->
+</div>
+
+<div class="box">
+ <div class="box_top"></div>
+ <div class="box_middle">
+ <p>
+ <b>Name:</b>
+ <%%=h @stage.name %>
+ </p>
+ <p>
+ <b>Project:</b>
+ <%%= link_to h(@stage.project.name), project_url(current_project) %>
+ </p>
+ <p>
+ <b>Alert on deploy:</b>
+ <%%=h @stage.alert_emails %>
+ </p>
+ <p>
+ <b>#Hosts:</b>
+ <%%=h @stage.hosts.count %>
+ </p>
+ <!--alimaher-->
+ <%%if !current_user.read_only(@stage) || current_user.admin? %>
+ <!--end alimaher-->
+ <br />
+ <%%= link_to 'Edit stage', edit_project_stage_path(current_project, @stage), :class => 'arrow_link' %> |
+ <%%= link_to 'Delete stage', project_stage_path(current_project, @stage), :confirm => 'Are you sure?', :method => :delete, :class => 'arrow_link' %> |
+ <%%= link_to 'Export capfile', {:action => 'capfile', :project_id => current_project, :id => @stage}, {:onclick => "loadWindow('#{url_for(:action => 'capfile', :project_id => current_project, :id => @stage)}'); return false", :class => 'arrow_link'} %>
+ <!--alimaher-->
+ <%%end%>
+ <!--end alimaher-->
+ </div>
+ <div class="box_bottom"></div>
+</div>
+
+
+<div class="clear"></div>
+<br>
+
+<fieldset class="fieldset">
+ <legend>Stage specific configuration</legend>
+ <%%= render(:partial => 'configs')%>
+ <br />
+ <div id="effective_config" style="display:none;">
+ <%%= render(:partial => 'effective_config')%>
+ <br />
+ </div>
+ <!--alimaher-->
+ <%%if !current_user.read_only(@stage) || current_user.admin? %>
+ <!--end alimaher-->
+ <%%= link_to 'New configuration', new_project_stage_stage_configuration_path(current_project, @stage), :class => 'arrow_link' %> |
+ <a id="s_e_c" href="#" onclick="show_effective_config(); return false" class="arrow_link">Show effective configuration</a>
+ <a id="h_e_c" href="#" onclick="hide_effective_config(); return false" class="arrow_link" style="display:none;">Hide effective configuration</a>
+ <!--alimaher-->
+ <%%end%>
+ <!--end alimaher-->
+</fieldset>
+
+<br /><br />
+
+<fieldset class="fieldset">
+ <legend>Used recipes</legend>
+ <%%= render(:partial => 'recipes')%>
+ <!--alimaher-->
+ <%%if !current_user.read_only(@stage) || current_user.admin? %>
+ <!--end alimaher-->
+ <br />
+ <%%= link_to 'Manage stage recipes', {:action => 'recipes', :project_id => current_project, :id => @stage} , :class => 'arrow_link'%>
+ <!--alimaher-->
+ <%%end%>
+ <!--end alimaher-->
+</fieldset>
+
+<br /><br />
+
+<fieldset class="fieldset">
+ <legend>Deployed hosts</legend>
+ <%%= render(:partial => 'roles')%>
+ <!--alimaher-->
+ <%%if !current_user.read_only(@stage) || current_user.admin? %>
+ <!--end alimaher-->
+ <br />
+ <%%= link_to 'Add host', new_project_stage_role_path(current_project, @stage) , :class => 'arrow_link'%>
+ <!--alimaher-->
+ <%%end%>
+ <!--end alimaher-->
+</fieldset>
+
+<br /><br />
+
+<fieldset class="fieldset">
+ <legend>Recent deployment history</legend>
+ <%%= render(:partial => 'deployments')%>
+</fieldset>
+
+<!--alimaher-->
+<br /><br />
+<fieldset class="fieldset">
+ <legend>Privileged users</legend>
+ <%%= render(:partial => 'users')%>
+ <br />
+</fieldset>
+<!--end alimaher-->
+
+<br />
+<%% content_for(:page_scripts) do %>
+ <script type="text/javascript">
+
+ function show_effective_config(){
+ $('h_e_c').show();
+ $('s_e_c').hide();
+ $('effective_config').show();
+ }
+
+ function hide_effective_config(){
+ $('h_e_c').hide();
+ $('s_e_c').show();
+ $('effective_config').hide();
+ }
+ </script>
+<%% end %>
+
+<%% content_for(:breadcrumb) do %>
+ <%% breadcrumb_box do %>
+ <%%= link_to "Back to project", project_path(@project), :style => "float:right", :class => "arrow_link" %>
+ <%%= link_to "Projects", projects_path %> &gt;
+ Project <%%= link_to current_project.name, project_path(current_project) %> &gt;
+ Stage <%%= link_to current_stage.name, project_stage_path(current_project, current_stage) %>
+ <%% end %>
+<%% end %>
+
+<%% content_for(:page_title) do %>
+ <%% @page_title = "Project #{h(current_project.name)} - Stage #{h(@stage.name)}"%>
+ <h2>Stage <%%= link_to h(@stage.name), project_stage_path(current_project, @stage) %></h2>
+<%% end %>
+
View
1 vendor/plugins/webistrano_stage_privileges/init.rb
@@ -0,0 +1 @@
+require "#{RAILS_ROOT}/vendor/plugins/webistrano_stage_privileges/lib/webistrano_stage_privileges.rb"
View
0 vendor/plugins/webistrano_stage_privileges/install.rb
No changes.
View
9 vendor/plugins/webistrano_stage_privileges/lib/webistrano_stage_privileges.rb
@@ -0,0 +1,9 @@
+module WebistranoStagePrivileges
+
+ module ControllerExtensions
+ def setup_stage_privileges
+
+ end
+ end
+
+end
View
4 vendor/plugins/webistrano_stage_privileges/tasks/webistrano_stage_privileges_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :webistrano_stage_privileges do
+# # Task goes here
+# end
View
8 vendor/plugins/webistrano_stage_privileges/test/webistrano_stage_privileges_test.rb
@@ -0,0 +1,8 @@
+require 'test/unit'
+
+class WebistranoStagePrivilegesTest < Test::Unit::TestCase
+ # Replace this with your real tests.
+ def test_this_plugin
+ flunk
+ end
+end
View
0 vendor/plugins/webistrano_stage_privileges/uninstall.rb
No changes.

0 comments on commit 4e88a55

Please sign in to comment.