Changeset 596

Show
Ignore:
Timestamp:
09/09/07 19:34:02 (1 year ago)
Author:
duane.johns..@gmail.com
Message:

Marble: Separate application config controllers from individual blog controllers. The 'users' admin section now respects memberships.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • apps/marble/trunk/app/controllers/admin/comments.rb

    r593 r596  
    11module Admin 
    2   class Comments < Application 
     2  class Comments < Base 
    33    self._layout = :admin 
    4  
     4    before :set_nav 
     5    def set_nav() @nav = "comments" end 
    56     
    67    magic_scaffold_here(Comment) { 
  • apps/marble/trunk/app/controllers/admin/posts.rb

    r593 r596  
    11module Admin 
    2   class Posts < Application 
     2  class Posts < Base 
    33    self._layout = :admin 
     4    before :set_nav 
     5    def set_nav() @nav = "posts" end 
    46 
    57    magic_scaffold_here(Post) { 
  • apps/marble/trunk/app/controllers/admin/users.rb

    r593 r596  
    11module Admin 
    2   class Users < Application 
     2  class Users < Base 
    33    self._layout = :admin 
     4    before :set_nav 
     5    def set_nav() @nav = "users" end 
     6 
     7    def index 
     8      @page = User.for_blog(@current_blog.id).paginate((params[:page] || 1).to_i, 10) 
     9      @users = @page.all 
    410     
     11      render :inline => <<-HTML.indent(2) 
     12        <%- if @users.size == 0 -%> 
     13          No users to show 
     14        <%- end -%> 
     15        <table> 
     16          <tr> 
     17            <th>Name</th> 
     18            <th>Email</th> 
     19            <th>Posts</th> 
     20          </tr> 
     21        <%- @users.each do |u| -%> 
     22          <tr> 
     23            <td><%= u.name %></td> 
     24            <td><%= u.email %></td> 
     25            <td><%= u.post_count rescue 0 %></td> 
     26            <td><a href="<%= url(:edit_user, :id => u.id) %>">edit</a></td> 
     27          </tr> 
     28        <%- end -%> 
     29        </table> 
     30        <%= 
     31          links = [] 
     32          links << %|<a href="#{url(:users, :page => @page.prev_page)}">Previous Page</a>| if @page.prev_page 
     33          links << %|<a href="#{url(:users, :page => @page.next_page)}">Next Page</a>| if @page.next_page 
     34          links << %|<a href="#{url(:new_user)}">new user</a>| 
     35          links.join(" | ") 
     36        %> 
     37      HTML 
     38    end 
     39   
    540    magic_scaffold_here(User) { 
    641      # NOTE: DO NOT EDIT the text below.  Instead, cut out the method or 
     
    944      #       actions that already exist in your controller class. 
    1045      module Scaffold 
    11         def index 
    12           @page = User.paginate((params[:page] || 1).to_i, 10) 
    13           @users = @page.all 
    14          
    15           render :inline => <<-HTML.indent(2) 
    16             <%- if @users.size == 0 -%> 
    17               No users to show 
    18             <%- end -%> 
    19             <table> 
    20               <tr> 
    21                 <th>Id</th> 
    22                 <th>First name</th> 
    23                 <th>Surname</th> 
    24                 <th>Email</th> 
    25                 <th>Password</th> 
    26                 <th>Can create blogs</th> 
    27               </tr> 
    28             <%- @users.each do |u| -%> 
    29               <tr> 
    30                 <td><%= u.id %></td> 
    31                 <td><%= u.first_name %></td> 
    32                 <td><%= u.surname %></td> 
    33                 <td><%= u.email %></td> 
    34                 <td><%= u.password %></td> 
    35                 <td><%= u.can_create_blogs %></td> 
    36                 <td><a href="<%= url(:edit_user, :id => u.id) %>">edit</a></td> 
    37               </tr> 
    38             <%- end -%> 
    39             </table> 
    40             <%= 
    41               links = [] 
    42               links << %|<a href="#{url(:users, :page => @page.prev_page)}">Previous Page</a>| if @page.prev_page 
    43               links << %|<a href="#{url(:users, :page => @page.next_page)}">Next Page</a>| if @page.next_page 
    44               links << %|<a href="#{url(:new_user)}">new user</a>| 
    45               links.join(" | ") 
    46             %> 
    47           HTML 
    48         end 
    49  
    5046        def show 
    5147          id = params[:id] 
     
    5753              <li><strong>Id:</strong> <%= @user.id %></li> 
    5854              <li><strong>First name:</strong> <%= @user.first_name %></li> 
    59               <li><strong>Surname:</strong> <%= @user.surname %></li> 
     55              <li><strong>Last name:</strong> <%= @user.last_name %></li> 
    6056              <li><strong>Email:</strong> <%= @user.email %></li> 
    6157              <li><strong>Password:</strong> <%= @user.password %></li> 
     
    7369            <ul> 
    7470              <div class="form-element"><label for="user_first_name">First name:</label><br/><%= control_for @user, :first_name, :text %></div> 
    75               <div class="form-element"><label for="user_surname">Surname:</label><br/><%= control_for @user, :surname, :text %></div> 
     71              <div class="form-element"><label for="user_last_name">Last name:</label><br/><%= control_for @user, :last_name, :text %></div> 
    7672              <div class="form-element"><label for="user_email">Email:</label><br/><%= control_for @user, :email, :text %></div> 
    7773              <div class="form-element"><label for="user_password">Password:</label><br/><%= control_for @user, :password, :text %></div> 
     
    104100              <ul> 
    105101                <div class="form-element"><label for="user_first_name">First name:</label><br/><%= control_for @user, :first_name, :text %></div> 
    106               <div class="form-element"><label for="user_surname">Surname:</label><br/><%= control_for @user, :surname, :text %></div> 
     102              <div class="form-element"><label for="user_last_name">Last name:</label><br/><%= control_for @user, :last_name, :text %></div> 
    107103              <div class="form-element"><label for="user_email">Email:</label><br/><%= control_for @user, :email, :text %></div> 
    108104              <div class="form-element"><label for="user_password">Password:</label><br/><%= control_for @user, :password, :text %></div> 
  • apps/marble/trunk/app/controllers/auth.rb

    r593 r596  
    2121        if @user 
    2222          session[:user_id] = @user.id 
    23           return redirect("/") 
     23          if session[:return_to] 
     24            returning(redirect(session[:return_to])) do 
     25              session[:return_to] = nil 
     26            end 
     27          else 
     28            redirect("/") 
     29          end 
    2430        else 
    2531          params.errors[:auth_failed] = "The email or password was incorrect." 
  • apps/marble/trunk/app/controllers/posts.rb

    r583 r596  
    22  self._layout = :one_column 
    33  def index 
    4     @blog = Blog.filter(:subdomain => request.subdomains.first).first 
     4    @blog = Blog.for_subdomain(request.subdomains.first).first 
    55    if @blog 
    66      @page = Post.filter(:blog_id => @blog.id).paginate((params[:page] || 1).to_i, 10) 
  • apps/marble/trunk/app/helpers/global_helper.rb

    r500 r596  
    11module Merb 
    22  module GlobalHelper 
    3     # helpers deinfed here available to all views.   
     3    # helpers defined here available to all views. 
     4    def nav(key, html) 
     5      %{<li#{key == @nav ? " class=\"selected\"" : ""}>#{html}</li>} 
     6    end 
    47  end 
    58end     
  • apps/marble/trunk/app/models/blog.rb

    r500 r596  
    66  end 
    77   
     8  def self.for_subdomain(subdomain) 
     9    Blog.filter(:subdomain => subdomain) 
     10  end 
     11   
     12  def owners 
     13  end 
     14   
     15  def members 
     16  end 
    817end 
    918 
  • apps/marble/trunk/app/models/membership.rb

    r500 r596  
    1616  when 'test', 'development' 
    1717    recreate_table 
     18    [ 
     19      {:user_id => 1, :blog_id => 1, :owner => true}, 
     20      {:user_id => 2, :blog_id => 1, :owner => false}, 
     21      {:user_id => 3, :blog_id => 1, :owner => false}, 
     22      {:user_id => 4, :blog_id => 2, :owner => true}, 
     23      {:user_id => 5, :blog_id => 2, :owner => false}, 
     24      {:user_id => 6, :blog_id => 2, :owner => false}, 
     25      {:user_id => 7, :blog_id => 3, :owner => true}, 
     26      {:user_id => 8, :blog_id => 3, :owner => false}, 
     27      {:user_id => 1, :blog_id => 3, :owner => false}, 
     28      {:user_id => 2, :blog_id => 2, :owner => false} 
     29    ].each{ |row| insert row } 
     30     
    1831  end 
    1932end 
  • apps/marble/trunk/app/models/user.rb

    r593 r596  
    99  end 
    1010   
     11  def self.for_blog(blog_id) 
     12    dataset.left_outer_join(:memberships, :user_id => :id).filter(:blog_id => blog_id) 
     13  end 
     14   
     15  def name 
     16    [first_name, last_name].compact.join(" ") 
     17  end 
     18   
     19  def this 
     20    model.dataset.filter(:"users__#{primary_key}" => @pkey) 
     21  end 
     22   
     23  def owns_blog?(blog_id) 
     24    this.left_outer_join(:memberships, :user_id => :id).filter(:blog_id => blog_id, :owner => true).first 
     25  end 
    1126end 
    1227 
     
    2843      {:first_name => 'Brianna', :last_name => "Harris", :email => "brianna.harris@gmail.com", :password => "test"} 
    2944    ].each{ |row| insert row } 
    30      
    31     migrate { |m| m.rename_column :last_name => :surname } 
    3245  end 
    3346end 
  • apps/marble/trunk/app/views/exceptions/gone.html.erb

    r583 r596  
    1   <h3>Gone</h3> 
    2   <p>You've found a page that may have been here but is no longer.</p> 
     1<h3>Gone</h3> 
     2<p>You've found a page that may have been here but is no longer.</p> 
    33 
    4   <h3>What Next?</h3> 
    5   <p>If you arrived here from an outside source, please notify the other website that 
    6     their link is no longer valid.</p> 
    7   <p>On the other hand, if we made this mistake ourselves, please let us know how you 
    8     got here and we'll see if we can't remedy the situation.</p> 
     4<h3>What Next?</h3> 
     5<p>If you arrived here from an outside source, please notify the other website that 
     6  their link is no longer valid.</p> 
     7<p>On the other hand, if we made this mistake ourselves, please let us know how you 
     8  got here and we'll see if we can't remedy the situation.</p> 
    99 
    10   <h3 class="red">Exception:</h3> 
    11   <p><%= message %></p> 
    12   <p><%= Merb.html_exception(exception) %></p> 
    13    
    14    
     10<h3 class="red">Exception:</h3> 
     11<p><%= message %></p> 
     12<p><%= Merb.html_exception(exception) %></p> 
  • apps/marble/trunk/app/views/exceptions/internal_server_error.html.erb

    r583 r596  
    1   <h3>Internal Server Error</h3> 
    2   <p>Oops, we goofed up.</p> 
     1<h3>Internal Server Error</h3> 
     2<p>Oops, we goofed up.</p> 
    33 
    4   <h3>What Next?</h3> 
    5   <p>You can use your browser's back button to return to the page you came from and try again or report the bug.</p> 
    6    
    7   <h3 class="red">Exception:</h3> 
    8   <p><%= Merb.html_exception(exception) %></p> 
    9    
     4<h3>What Next?</h3> 
     5<p>You can use your browser's back button to return to the page you came from and try again or report the bug.</p> 
     6 
     7<h3 class="red">Exception:</h3> 
     8<p><%= Merb.html_exception(exception) %></p> 
  • apps/marble/trunk/app/views/exceptions/not_found.html.erb

    r583 r596  
    1   <h3>Page Not Found</h3> 
    2   <p>You've found a page that doesn't exist.</p> 
     1<h3>Page Not Found</h3> 
     2<p>You've found a page that doesn't exist.</p> 
    33 
    4   <h3>What Next?</h3> 
    5   <p>If you arrived here from an outside source, please notify the other website that 
    6     their link is no longer valid.</p> 
    7   <p>On the other hand, if we made this mistake ourselves, please let us know how you 
    8     got here and we'll see if we can't remedy the situation.</p> 
     4<h3>What Next?</h3> 
     5<p>If you arrived here from an outside source, please notify the other website that 
     6  their link is no longer valid.</p> 
     7<p>On the other hand, if we made this mistake ourselves, please let us know how you 
     8  got here and we'll see if we can't remedy the situation.</p> 
    99 
    10   <h3 class="red">Exception:</h3> 
    11   <p><%= message %></p> 
     10<h3 class="red">Exception:</h3> 
     11<p><%= message %></p> 
  • apps/marble/trunk/app/views/layout/admin.html.erb

    r584 r596  
    22<html xmlns="http://www.w3.org/1999/xhtml"> 
    33  <head> 
    4     <title>Marble Admin &mdash; Users</title> 
     4    <title>Marble Admin<%= @title ? " &mdash; #{@title}" : "" %></title> 
    55    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> 
    66    <link rel="stylesheet" href="/stylesheets/master.css" type="text/css" media="screen" charset="utf-8"> 
     
    1414        <hr /> 
    1515        <ul id="admin-menu"> 
    16           <li>&rarr;</li> 
    17           <li><a href="<%= url(:users) %>">Users</a></li> 
    18           <li><a href="<%= url(:blogs) %>">Blogs</a></li> 
    19           <li><a href="<%= url(:posts) %>">Posts</a></li> 
    20           <li><a href="<%= url(:comments) %>">Comments</a></li> 
     16          <%= nav "users", %{<a href="#{url(:users)}" class="partition">Users</a>} %> 
     17          <%= nav "posts", %{<a href="#{url(:posts)}" class="partition">Posts</a>} %> 
     18          <%= nav "comments", %{<a href="#{url(:comments)}" class="partition">Comments</a>} %> 
    2119        </ul> 
    2220        <div style="clear:both"></div> 
     21        <hr /> 
    2322      </div> 
    2423 
  • apps/marble/trunk/config/router.rb

    r593 r596  
    2222puts "Compiling routes.." 
    2323Merb::Router.prepare do |r| 
    24  
     24   
     25  r.match("/config") do |app| 
     26    app.resources(:users, :controller => 'config/users') 
     27    app.resources(:blogs, :controller => 'config/posts') 
     28    # Default admin to Users#index 
     29    app.match(%r[/?]).to(:controller => 'config/users') 
     30  end 
     31   
    2532  r.match("/admin") do |admin| 
    2633    admin.resources(:users, :controller => 'admin/users') 
    27     admin.resources(:blogs, :controller => 'admin/blogs') 
    2834    admin.resources(:posts, :controller => 'admin/posts') 
    2935    admin.resources(:comments, :controller => 'admin/comments') 
  • apps/marble/trunk/public/stylesheets/admin.css

    r583 r596  
    88} 
    99ul#admin-menu li a { 
    10         padding: 2px 5px 2px 5px; 
     10        padding: 2px 12px 2px 12px; 
    1111        display: block; 
    1212        text-decoration: none; 
     13} 
     14ul#admin-menu li a.partition { 
     15        border-right: 2px solid #ddd; 
    1316} 
    1417ul#admin-menu li a:hover {