[PATCH portal] Add specs for user model.
by Tomas Sedovic
From: Tomas Sedovic <tsedovic(a)redhat.com>
---
src/spec/models/user_spec.rb | 40 +++++++++++++++++++++++++++++++++++++---
1 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/src/spec/models/user_spec.rb b/src/spec/models/user_spec.rb
index 2d9b875..af88688 100644
--- a/src/spec/models/user_spec.rb
+++ b/src/spec/models/user_spec.rb
@@ -2,11 +2,45 @@ require 'spec_helper'
describe User do
before(:each) do
- @valid_attributes = {
- }
end
it "should create a new user 'tuser'" do
- Factory.create(:tuser)
+ user = Factory.create(:tuser)
+ user.should be_valid
end
+
+ it "should require password confirmation" do
+ user = User.new(Factory.attributes_for(:tuser))
+ user.should be_valid
+ user.password_confirmation = "different password"
+ user.should_not be_valid
+ end
+
+ it "should require unique login" do
+ user1 = Factory.create(:tuser)
+ user2 = Factory.create(:tuser)
+ user1.should be_valid
+ user2.should be_valid
+
+ user2.login = user1.login
+ user2.should_not be_valid
+ end
+
+ it "should require unique email" do
+ user1 = Factory.create(:tuser)
+ user2 = Factory.create(:tuser)
+ user1.should be_valid
+ user2.should be_valid
+
+ user2.email = user1.email
+ user2.should_not be_valid
+ end
+
+ it "should requive valid email" do
+ user = User.new(Factory.attributes_for(:tuser))
+
+ user.email = "invalid-email"
+ user.should_not be_valid
+ end
+
end
--
1.6.6.1
14 years, 2 months
gitignore and updated model specs
by Tomas Sedovic
The first patch adds the autogenerated sqlite3 files to .gitignore.
The second adds some more requirements to the Task model spec. They make the
`rake spec` tests fail.
The third one makes the tests pass again.
And the last patch adds requirements for the Provider model. These do pass
right away.
14 years, 2 months
[PATCH docs] Add table of supported providers/features.
by Tomas Sedovic
From: Tomas Sedovic <tsedovic(a)redhat.com>
---
deltacloud.org/content/drivers.haml | 53 +++++++++++++++++++++++++++++-
deltacloud.org/content/styles/dcloud.css | 53 +++++++++++++++++++++++++++++-
deltacloud.org/lib/data.rb | 31 +++++++++++++++++
docs/drivers.mdown | 13 +++----
4 files changed, 141 insertions(+), 9 deletions(-)
create mode 100644 deltacloud.org/lib/data.rb
diff --git a/deltacloud.org/content/drivers.haml b/deltacloud.org/content/drivers.haml
index 02c5369..83935d8 100644
--- a/deltacloud.org/content/drivers.haml
+++ b/deltacloud.org/content/drivers.haml
@@ -9,4 +9,55 @@ filter:
---
<toc numbering="off" toc_style="ul" toc_range="h2-h3" />
-= File.open('../docs/drivers.mdown').read
+- page = File.open('../docs/drivers.mdown').read
+- header, rest = page.split("<table providers />")
+
+= header
+
+%table#providers
+ %tr
+ %th.emptycell
+ %th
+ %strong Create
+ new instances
+ %th
+ %strong Start
+ stopped instances
+ %th
+ %strong Stop
+ running instances
+ %th
+ %strong Reboot
+ running instances
+ %th
+ %strong Destroy
+ instances
+ %th
+ List all/get details about
+ %strong hardware profiles
+ %th
+ List all/get details about
+ %strong realms
+ %th
+ List all/get details about
+ %strong images
+ %th
+ List all/get details about
+ %strong instances
+ - provider_support.each do |provider|
+ %tr
+ %td.provider
+ = provider[:name]
+ - if not provider[:driver]
+ %span coming soon
+ = support_indicator(provider[:instance][:create])
+ = support_indicator(provider[:instance][:start])
+ = support_indicator(provider[:instance][:stop])
+ = support_indicator(provider[:instance][:reboot])
+ = support_indicator(provider[:instance][:destroy])
+ = support_indicator(provider[:list][:hardware_profiles])
+ = support_indicator(provider[:list][:realms])
+ = support_indicator(provider[:list][:images])
+ = support_indicator(provider[:list][:instances])
+
+= rest
diff --git a/deltacloud.org/content/styles/dcloud.css b/deltacloud.org/content/styles/dcloud.css
index f509f0b..ca08de6 100644
--- a/deltacloud.org/content/styles/dcloud.css
+++ b/deltacloud.org/content/styles/dcloud.css
@@ -303,4 +303,55 @@ head:first-child+body #projects dl {
color: white;
text-decoration: inherit;
font-weight: bold;
-}
\ No newline at end of file
+}
+
+table#providers {
+ margin-bottom: 1em;
+ border: 1px solid #efefef;
+ padding: 1em;
+ width: 100%;
+}
+
+table#providers th {
+ font-weight: normal;
+ padding: 0.5em;
+ vertical-align: top;
+ color: #242829;
+ background: #E4EBEF;
+}
+
+table#providers th.emptycell {
+ background: #FFF;
+}
+
+table#providers td {
+ padding: 0.5em;
+ width: 10%;
+ height: 3em;
+ background: #E4EBEF;
+}
+
+table#providers td.provider {
+ font-weight: bold;
+ color: #242829;
+ padding: 0 0.5em;
+}
+
+table#providers td.provider span {
+ color: #738389;
+ font-style: italic;
+ font-weight: normal;
+ font-size: .95em;
+}
+
+table#providers td.not-supported {
+ text-align: center;
+ background: #E4EBEF;
+ color: #738389;
+}
+
+table#providers td.supported {
+ text-align: center;
+ background: #a4c3d4;
+ color: #242829;
+}
diff --git a/deltacloud.org/lib/data.rb b/deltacloud.org/lib/data.rb
new file mode 100644
index 0000000..f3e7f0f
--- /dev/null
+++ b/deltacloud.org/lib/data.rb
@@ -0,0 +1,31 @@
+module DataHelper
+ def provider_support
+ [
+ {:name => "Amazon EC2", :driver => true, :instance => { :create => true, :start => false, :stop => true, :reboot => true, :destroy => true },
+ :list => { :hardware_profiles => true, :realms => true, :images => true, :instances => true} },
+ {:name => "GoGrid", :driver => false, :instance => { :create => true, :start => false, :stop => true, :reboot => true, :destroy => true },
+ :list => { :hardware_profiles => true, :realms => true, :images => true, :instances => true} },
+ {:name => "OpenNebula", :driver => true, :instance => { :create => true, :start => true, :stop => true, :reboot => false, :destroy => true },
+ :list => { :hardware_profiles => true, :realms => true, :images => true, :instances => true} },
+ {:name => "Rackspace", :driver => true, :instance => { :create => true, :start => false, :stop => true, :reboot => true, :destroy => true },
+ :list => { :hardware_profiles => true, :realms => true, :images => true, :instances => true} },
+ {:name => "RHEV-M", :driver => true, :instance => { :create => true, :start => true, :stop => true, :reboot => true, :destroy => true },
+ :list => { :hardware_profiles => true, :realms => true, :images => true, :instances => true} },
+ {:name => "RimuHosting", :driver => true, :instance => { :create => true, :start => true, :stop => true, :reboot => true, :destroy => true },
+ :list => { :hardware_profiles => true, :realms => true, :images => true, :instances => true} },
+ {:name => "Terremark", :driver => false, :instance => { :create => true, :start => true, :stop => true, :reboot => true, :destroy => true },
+ :list => { :hardware_profiles => true, :realms => true, :images => true, :instances => true} },
+ {:name => "vCloud", :driver => false, :instance => { :create => true, :start => true, :stop => true, :reboot => true, :destroy => true },
+ :list => { :hardware_profiles => true, :realms => true, :images => true, :instances => true} },
+ ]
+ end
+
+ def support_indicator(value)
+ text = value ? "yes" : "no"
+ cls = value ? "supported" : "not-supported"
+ "<td class=\"#{cls}\">#{text}</td>"
+ end
+
+end
+
+Webby::Helpers.register(DataHelper)
diff --git a/docs/drivers.mdown b/docs/drivers.mdown
index 4296b21..e579a5e 100644
--- a/docs/drivers.mdown
+++ b/docs/drivers.mdown
@@ -1,13 +1,12 @@
# Deltacloud Drivers
-The Deltacloud project current delivers two functional drivers, plus
-a mock driver for testing without a cloud provider.
-
-- Amazon EC2
-- Red Hat Enterprise Virtualization Manager (RHEV-M)
-- Rackspace Cloud
-- RimuHosting Cloud
-- OpenNebula
+Deltacloud provides drivers for a growing number of popular clouds. All drivers
+can handle a set of standard operations, some of them also support a number of
+optional operations to expose the features of specific clouds more closely. The
+drivers and their capabilities are:
+
+<table providers />
+
## Setting up the code
--
1.6.6.1
14 years, 2 months
Removed Rails code from core
by Michal Fojtik
Hi,
These patches will remove unused or obsolete code from 'core'.
Also this patch fixes RAILS_ROOT variable usage and removing some
unused/obsolete helpers).
Some of deltacloud includes (drivers.rb, deltacloud.rb) movedinto
lib/deltacloud directory, so root directory is now cleaner.
- Michal
14 years, 2 months
Contribute page redesign by Jeremy Perry
by Tomas Sedovic
This patch features Jeremy Perry's redesign of the Contribute page. It's
communicates much better to the potential contributors.
However, the required HTML changes caused a problem with the webby plugin
that generates Table of Contents. I've used a temporary workaround.
When Jeremy changes the layout not to require <h3> tags in the Contribute
list, we can clean it up again.
14 years, 2 months
[PATCH core] Fix gemspec
by Jason Guiditta
This was missing a couple deps and failed when
I built and installed on a new machine.
---
server/deltacloud-core.gemspec | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/server/deltacloud-core.gemspec b/server/deltacloud-core.gemspec
index 90ce52a..9c75302 100644
--- a/server/deltacloud-core.gemspec
+++ b/server/deltacloud-core.gemspec
@@ -60,6 +60,8 @@ require 'rake'
s.add_dependency('sinatra', '>= 0.9.4')
s.add_dependency('rack', '>= 1.0.0')
s.add_dependency('thin', '>= 1.2.5')
+ s.add_dependency('rerun', '>= 0.5.2')
+ s.add_dependency('rack-accept-media-types', '>= 0.9')
s.add_development_dependency('compass', '>= 0.8.17')
s.add_development_dependency('nokogiri', '>= 1.4.1')
s.add_development_dependency('rack-test', '>= 0.5.3')
--
1.6.2.5
14 years, 2 months
REXML replaced by Nokogiri
by Michal Fojtik
Hi,
This patch will replace REXML with Nokogiri. Converter was reworked
in way which will allow us in future easy 'rewriting' methods / adding new methods.
Nokogiri is already packaged for Fedora, so there is no new dependency.
Question:
Why we have convert_to_xml defined twice ? (conversion_helper.rb / driver_helper.rb)
- Michal
14 years, 2 months
[PATCH portal 2/2] permissions UI to view/add permission records.(revised)
by Scott Seago
The views will change with the coming redesign, and backlinks _from_ the permission pages back to the pool/account/etc pages are not yet defined.
Signed-off-by: Scott Seago <sseago(a)redhat.com>
---
src/app/controllers/application_controller.rb | 2 +
src/app/controllers/permissions_controller.rb | 90 +++++++++++++++++++++++++
src/app/models/cloud_account.rb | 4 +
src/app/views/layouts/_main_nav.html.erb | 1 +
src/app/views/permissions/list.html.erb | 34 +++++++++
src/app/views/permissions/new.html.erb | 17 +++++
src/app/views/portal_pool/accounts.html.erb | 8 ++
src/app/views/portal_pool/show.html.erb | 3 +-
src/app/views/provider/show.html.erb | 1 +
9 files changed, 159 insertions(+), 1 deletions(-)
create mode 100644 src/app/controllers/permissions_controller.rb
create mode 100644 src/app/views/permissions/list.html.erb
create mode 100644 src/app/views/permissions/new.html.erb
diff --git a/src/app/controllers/application_controller.rb b/src/app/controllers/application_controller.rb
index d7b135b..a71f53d 100644
--- a/src/app/controllers/application_controller.rb
+++ b/src/app/controllers/application_controller.rb
@@ -61,6 +61,8 @@ class ApplicationController < ActionController::Base
end
master_helper_module.module_eval perm_helper_string
+ helper_method :check_privilege
+
protected
# permissions checking
diff --git a/src/app/controllers/permissions_controller.rb b/src/app/controllers/permissions_controller.rb
new file mode 100644
index 0000000..257f2b1
--- /dev/null
+++ b/src/app/controllers/permissions_controller.rb
@@ -0,0 +1,90 @@
+#
+# Copyright (C) 2009 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+class PermissionsController < ApplicationController
+ before_filter :require_user
+
+ def show
+ @permission = Permission.find(params[:id])
+ require_privilege(Privilege::PERM_VIEW, @permission.permission_object)
+ end
+
+ def list
+ set_permission_object Privilege::PERM_VIEW
+ end
+
+ def new
+ set_permission_object Privilege::PERM_SET
+ @permission = Permission.new(:permission_object_type => @permission_object.class,
+ :permission_object_id => @permission_object.id)
+ @users = User.all
+ @roles = Role.find_all_by_scope((a)permission_object.class.name)
+ end
+
+ def create
+ @permission = Permission.new(params[:permission])
+ require_privilege(Privilege::PERM_SET, @permission.permission_object)
+ if request.post? && @permission.save
+ flash[:notice] = "Permission record added."
+ redirect_to :action => "list",
+ :permission_object_type => @permission.permission_object_type,
+ :permission_object_id => @permission.permission_object_id
+ else
+ @permission_object = @permission.permission_object
+ render :action => 'new'
+ end
+ end
+
+ def destroy
+ if request.post?
+ p =Permission.find(params[:permission][:id])
+ require_privilege(Privilege::PERM_SET, p.permission_object)
+ p.destroy
+ end
+ redirect_to :action => "list",
+ :permission_object_type => p.permission_object_type,
+ :permission_object_id => p.permission_object_id
+ end
+
+ private
+
+ def set_permission_object(privilege)
+ if !params[:permission_object_type].nil?
+ @permission_object =
+ params[:permission_object_type].constantize.find(params[:permission_object_id])
+ elsif !params[:portal_pool_id].nil?
+ @permission_object = PortalPool.find params[:portal_pool_id]
+ elsif !params[:provider_id].nil?
+ @permission_object = Provider.find params[:provider_id]
+ elsif !params[:cloud_account_id].nil?
+ @permission_object = CloudAccount.find params[:cloud_account_id]
+ elsif !params[:base_portal_object_id].nil?
+ @permission_object = BasePortalObject.find params[:base_portal_object_id]
+ else
+ @permission_object = BasePortalObject.general_permission_scope
+ end
+
+ raise ActiveRecord::RecordNotFound if @permission_object.nil?
+
+ require_privilege(privilege, @permission_object)
+ end
+
+end
diff --git a/src/app/models/cloud_account.rb b/src/app/models/cloud_account.rb
index 6d44b64..da7e8dd 100644
--- a/src/app/models/cloud_account.rb
+++ b/src/app/models/cloud_account.rb
@@ -56,4 +56,8 @@ class CloudAccount < ActiveRecord::Base
def account_prefix_for_realm
provider.name + Realm::AGGREGATOR_REALM_PROVIDER_DELIMITER + username
end
+
+ def name
+ username
+ end
end
diff --git a/src/app/views/layouts/_main_nav.html.erb b/src/app/views/layouts/_main_nav.html.erb
index 1894cb4..e53af7f 100644
--- a/src/app/views/layouts/_main_nav.html.erb
+++ b/src/app/views/layouts/_main_nav.html.erb
@@ -1,6 +1,7 @@
<%=link_to "Add a provider", {:controller => "provider", :action => "new"}, :class => "actionlink" %>
<%=link_to "Add a pool", {:controller => "portal_pool", :action => "new"}, :class => "actionlink" %>
+<%= link_to "User access", {:controller => "permissions", :action => "list"}, :class=>"actionlink" if has_view_perms?(BasePortalObject.general_permission_scope) %>
<h3>Providers</h3>
<ul id="providers">
<% cur_id = params[:id].to_i %>
diff --git a/src/app/views/permissions/list.html.erb b/src/app/views/permissions/list.html.erb
new file mode 100644
index 0000000..585e6d3
--- /dev/null
+++ b/src/app/views/permissions/list.html.erb
@@ -0,0 +1,34 @@
+<% if @permission_object.permissions.size == 0 %>
+<h1>There are no permissions defined on <%= @permission_object.name%></h1>
+<% else %>
+ <table>
+ <thead>
+ <tr>
+ <th scope="col">User</th>
+ <th scope="col">Role</th>
+ <th scope="col">Action</th>
+ </tr>
+ </thead>
+ <tbody>
+ <%(a)permission_object.permissions.each {|permission| %>
+ <tr>
+ <td><%= permission.user.login %></td>
+ <td><%= permission.role.name %></td>
+ <td>
+ <% if has_set_perms? %>
+ <% form_tag :action => 'destroy' do %>
+ <%= hidden_field :permission, :id, :value => permission.id %>
+ <%= submit_tag "delete", :class => "submit_link" %>
+ <% end %>
+ <% end %>
+ </td>
+ </tr>
+ <% } %>
+ </tbody>
+ </table>
+<% end %>
+<%= link_to "Add a new permission record",
+ {:action => "new",
+ :permission_object_type => @permission_object.class,
+ :permission_object_id => @permission_object.id},
+ :class=>"actionlink" if has_set_perms? %>
diff --git a/src/app/views/permissions/new.html.erb b/src/app/views/permissions/new.html.erb
new file mode 100644
index 0000000..dd102ce
--- /dev/null
+++ b/src/app/views/permissions/new.html.erb
@@ -0,0 +1,17 @@
+<div class="dcloud_form">
+ <%= error_messages_for 'permission' %>
+
+ <h2>Add new Permission for <%= @permission_object.name %></h2><br />
+ <% form_tag :action => 'create' do-%>
+ <ul>
+ <li><label>User<span>User to receive permission grant</span></label>
+ <%= select("permission", "user_id", @users.collect {|u| [ u.login, u.id ] }, { :include_blank => true }) %>
+ </li>
+ <li><label>Role</label>
+ <%= select("permission", "role_id", @roles.collect {|r| [ r.name, r.id ] }, { :include_blank => true }) %>
+ </li>
+ <%= hidden_field :permission, :permission_object_type %>
+ <%= hidden_field :permission, :permission_object_id %>
+ <%= submit_tag "Save", :class => "submit" %>
+ <% end %>
+</div>
diff --git a/src/app/views/portal_pool/accounts.html.erb b/src/app/views/portal_pool/accounts.html.erb
index e6b4f1c..3a95eae 100644
--- a/src/app/views/portal_pool/accounts.html.erb
+++ b/src/app/views/portal_pool/accounts.html.erb
@@ -6,6 +6,7 @@
<tr>
<th scope="col">Provider</th>
<th scope="col">Username</th>
+ <th scope="col">Actions</th>
</tr>
</thead>
<tbody>
@@ -13,6 +14,13 @@
<tr>
<td><%= account.provider.name %></td>
<td><%= account.username %></td>
+ <td>
+ <%= link_to "User access",
+ {:controller => "permissions",
+ :action => "list",
+ :cloud_account_id => account.id},
+ :class=>"actionlink" if has_view_perms?(account) %>
+ </td>
</tr>
<% } %>
</tbody>
diff --git a/src/app/views/portal_pool/show.html.erb b/src/app/views/portal_pool/show.html.erb
index 128d74c..31e2d7c 100644
--- a/src/app/views/portal_pool/show.html.erb
+++ b/src/app/views/portal_pool/show.html.erb
@@ -36,7 +36,8 @@
</table>
<% end %>
<%= link_to "Add a new instance", {:controller => "instance", :action => "new", :id => @pool}, :class=>"actionlink"%>
-<%= link_to "Accounts", {:action => "accounts", :id => @pool.id}, :class=>"actionlink"%>
+<%= link_to "Back end Accounts", {:action => "accounts", :id => @pool.id}, :class=>"actionlink"%>
+<%= link_to "User access", {:controller => "permissions", :action => "list", :portal_pool_id => @pool.id}, :class=>"actionlink" if has_view_perms? %>
<%= link_to "Hardware Profiles", {:action => "hardware_profiles", :id => @pool.id}, :class=>"actionlink"%>
<%=link_to "View Images", {:controller => "portal_pool", :action => "images", :portal_pool => @pool}, :class => "actionlink" %>
<%= link_to "Realms", {:action => "realms", :id => @pool.id}, :class=>"actionlink"%>
diff --git a/src/app/views/provider/show.html.erb b/src/app/views/provider/show.html.erb
index c00cfbf..2ec5f62 100644
--- a/src/app/views/provider/show.html.erb
+++ b/src/app/views/provider/show.html.erb
@@ -21,6 +21,7 @@
<%= link_to "Add a pool", {:controller => "portal_pool", :action => "new", :provider => @provider}, :class => "actionlink" %>
<%= link_to "Realms", {:action => "realms", :id => @provider.id}, :class=>"actionlink"%>
<%= link_to "Accounts", {:action => "accounts", :id => @provider.id}, :class=>"actionlink"%>
+<%= link_to "User access", {:controller => "permissions", :action => "list", :provider_id => @provider.id}, :class=>"actionlink" if has_view_perms? %>
<% form_tag :action => 'destroy' do %>
<%=hidden_field :provider, :id %>
<%= submit_tag "Delete Provider", :class => "submit_link" %>
--
1.6.2.5
14 years, 2 months