[Xfce4-commits] <moka:master> Add project groups.

Nick Schermer noreply at xfce.org
Sun Nov 20 14:30:59 CET 2011


Updating branch refs/heads/master
         to cce813c2601f4d8d733579988d909c92a9f2043b (commit)
       from e28a68694cb469a9474a06c70e1c9e84a49e988e (commit)

commit cce813c2601f4d8d733579988d909c92a9f2043b
Author: Nick Schermer <nick at xfce.org>
Date:   Wed Nov 16 20:05:22 2011 +0100

    Add project groups.
    
    This will be used to set the type of project. Only
    an archive project, create git repo or even a public
    git repository.

 examples/xfce/config.ru           |   38 ++++++++++++++++++++++++------------
 lib/controllers/projects.rb       |   23 ++++++++++++++++++++++
 lib/models/{role.rb => group.rb}  |    6 ++--
 lib/models/project.rb             |    1 +
 lib/models/role.rb                |    4 +-
 lib/moka.rb                       |    2 +-
 lib/views/maintainer_profile.haml |   22 +++++++++++---------
 lib/views/project.haml            |   18 ++++++++++++++++-
 lib/views/project_list.haml       |    9 +++++--
 9 files changed, 90 insertions(+), 33 deletions(-)

diff --git a/examples/xfce/config.ru b/examples/xfce/config.ru
index 187e615..7974a77 100755
--- a/examples/xfce/config.ru
+++ b/examples/xfce/config.ru
@@ -57,15 +57,15 @@ end
 # Mailinglist configuration and template handling
 use Moka::Middleware::Mailinglists do |mailer|
   mailer.lists = ['xfce-announce at xfce.org', 'xfce at xfce.org', 'thunar-dev at xfce.org', 'nick at schermer']
-  
+
   mailer.project_subject do |release, message, sender|
     "ANNOUNCE: #{release.project.name} #{release.version} released"
   end
 
-  mailer.project_body do |release, message, sender| 
+  mailer.project_body do |release, message, sender|
     ERB.new(File.read('templates/project_release_mail.erb')).result(binding)
   end
-  
+
   mailer.collection_subject do |release, message, sender|
     "ANNOUNCE: #{release.collection.display_name} #{release.version} released"
   end
@@ -84,15 +84,23 @@ Moka::Models::Configuration.load do |conf|
   conf.set :noreply, 'noreply at xfce.org'
 end
 
+#DataMapper.auto_migrate!
 DataMapper.finalize
+#require 'migrate'
 
 if false
   admin = Moka::Models::Role.first_or_create(
     { :name => 'admin' },
-    { :description => "Administrator" }
+    { :desc => "Administrator" }
   )
   admin.save
-  
+
+  public = Moka::Models::Group.first_or_create(
+    { :name => 'public' },
+    { :desc => "Public GIT repository" }
+  )
+  public.save
+
   # create dummy user
   nick = Moka::Models::Maintainer.first_or_create(
     { :username => 'nick' },
@@ -103,7 +111,7 @@ if false
   )
   nick.roles << admin
   nick.save
-  
+
   jannis = Moka::Models::Maintainer.first_or_create(
     { :username => 'jannis' },
     { :realname => 'Jannis Pohlmann',
@@ -112,7 +120,7 @@ if false
       :active => true }
   )
   jannis.save
-  
+
   jeromeg = Moka::Models::Maintainer.first_or_create(
     { :username => 'jeromeg' },
     { :realname => 'Jérôme Guelfucci',
@@ -121,7 +129,7 @@ if false
       :active => false }
   )
   jeromeg.save
-  
+
   panel = Moka::Models::Project.first_or_create(
     { :name =>           'xfce4-panel' },
     { :website =>        'http://www.xfce.org',
@@ -129,7 +137,7 @@ if false
   )
   panel.maintainers << nick
   panel.save
-  
+
   thunar = Moka::Models::Project.first_or_create(
     { :name =>           'thunar' },
     { :website =>        'http://thunar.xfce.org',
@@ -137,24 +145,27 @@ if false
   )
   thunar.maintainers << nick
   thunar.maintainers << jannis
+  thunar.groups << public
   thunar.save
-  
+
   terminal = Moka::Models::Project.first_or_create(
     { :name =>           'terminal' },
     { :website =>        'http://www.xfce.org',
       :description =>    'Xfce\'s Terminal Emulator' }
   )
   terminal.maintainers << nick
+  terminal.groups << public
   terminal.save
-  
+
   tumbler = Moka::Models::Project.first_or_create(
     { :name =>           'tumbler' },
     { :website =>        'http://www.xfce.org',
       :description =>    'Thumbnail generator' }
   )
   tumbler.maintainers << jannis
+  tumbler.groups << public
   tumbler.save
-  
+
   libxfce4ui = Moka::Models::Project.first_or_create(
     { :name =>           'libxfce4ui' },
     { :website =>        'http://www.xfce.org',
@@ -163,8 +174,9 @@ if false
   libxfce4ui.maintainers << jannis
   libxfce4ui.maintainers << nick
   libxfce4ui.maintainers << jeromeg
+  libxfce4ui.groups << public
   libxfce4ui.save
-  
+
   # create dummy classification
   collection = Moka::Models::Collection.first_or_create(
     { :name => 'xfce' },
diff --git a/lib/controllers/projects.rb b/lib/controllers/projects.rb
index 3d85225..b5dc96e 100755
--- a/lib/controllers/projects.rb
+++ b/lib/controllers/projects.rb
@@ -21,6 +21,12 @@ module Moka
             classification = Classification.find_by_name(params[:classification])
             project.classify_as(classification) if classification
 
+            if param[:defaultsgroups]
+              project.groups << Group.get('archive')
+              project.groups << Group.get('repo')
+              project.groups << Group.get('public')
+            end
+
             project.save
 
             redirect "/project/#{params[:name]}"
@@ -62,6 +68,23 @@ module Moka
           redirect "/project/#{params[:name]}"
         end
 
+        app.post '/project/:name/groups' do
+          project = Project.get(params[:name])
+
+          authentication_required
+
+          project.groups.clear
+          if params[:groups]
+            for name in params[:groups].keys do
+              group = Group.get(name)
+              project.groups << group
+            end
+          end
+          project.save
+
+          redirect "/project/#{params[:name]}"
+        end
+
         app.get '/project/:name/branch/:branch/release/:version/update' do
           @project = Project.get(params[:name])
 
diff --git a/lib/models/role.rb b/lib/models/group.rb
similarity index 56%
copy from lib/models/role.rb
copy to lib/models/group.rb
index 2c0fd85..544d027 100644
--- a/lib/models/role.rb
+++ b/lib/models/group.rb
@@ -1,12 +1,12 @@
 module Moka
   module Models
-    class Role
+    class Group
       include DataMapper::Resource
 
       property :name,        String, :key => true
-      property :description, String
+      property :desc, String
 
-      has n,   :maintainers, :through => Resource
+      has n,   :projects, :through => Resource
     end
   end
 end
diff --git a/lib/models/project.rb b/lib/models/project.rb
index 936b34c..2f7758b 100755
--- a/lib/models/project.rb
+++ b/lib/models/project.rb
@@ -102,6 +102,7 @@ module Moka
       property :owner,       String
 
       has n,   :maintainers, :through => Resource
+      has n,   :groups,      :through => Resource
 
       def classification
         Classification.find_by_project(self)
diff --git a/lib/models/role.rb b/lib/models/role.rb
index 2c0fd85..1b80cea 100644
--- a/lib/models/role.rb
+++ b/lib/models/role.rb
@@ -3,8 +3,8 @@ module Moka
     class Role
       include DataMapper::Resource
 
-      property :name,        String, :key => true
-      property :description, String
+      property :name, String, :key => true
+      property :desc, String
 
       has n,   :maintainers, :through => Resource
     end
diff --git a/lib/moka.rb b/lib/moka.rb
index 818f9f3..b63e932 100755
--- a/lib/moka.rb
+++ b/lib/moka.rb
@@ -4,7 +4,7 @@ require 'sass'
 
 directory = File.expand_path(File.dirname(__FILE__))
 
-models = ['configuration', 'classification', 'role', 'maintainer', 'collection', 'project', 'archive']
+models = ['configuration', 'classification', 'group', 'role', 'maintainer', 'collection', 'project', 'archive']
 for model in models
   require File.join(directory, 'models', model)
 end
diff --git a/lib/views/maintainer_profile.haml b/lib/views/maintainer_profile.haml
index a637f3e..e18c9b7 100644
--- a/lib/views/maintainer_profile.haml
+++ b/lib/views/maintainer_profile.haml
@@ -71,16 +71,18 @@
 %form{:method => "post", :action => "/maintainer/#{@maintainer.username}/permissions" }
   %h3 Roles
   - visible_roles = false
-  - for role in Role.all
-    - if authentication_user.is_admin or @maintainer.roles.include?(role)
-      - visible_roles = true
-      %p
-        %input{:type => "checkbox",
-               :name => "roles[#{role.name}]",
-               :id => "r_#{role.name}",
-               :checked => @maintainer.roles.include?(role),
-               :disabled => !authentication_user.is_admin}
-        %label{:for => "r_#{role.name}"} #{role.description}
+  %div{:class => "columns"}
+    - for role in Role.all
+      - if authentication_user.is_admin or @maintainer.roles.include?(role)
+        - visible_roles = true
+        %p
+          %input{:type => "checkbox",
+                 :name => "roles[#{role.name}]",
+                 :id => "r_#{role.name}",
+                 :checked => @maintainer.roles.include?(role),
+                 :disabled => !authentication_user.is_admin}
+          %label{:for => "r_#{role.name}"} #{role.desc}
+    %div{:class => "clearboth"}
   - if !visible_roles
     %p You don't have special roles.
 
diff --git a/lib/views/project.haml b/lib/views/project.haml
index 4468e8f..9357ac5 100755
--- a/lib/views/project.haml
+++ b/lib/views/project.haml
@@ -1,4 +1,4 @@
-%h2 Project information
+%h2 Project Information
 %fieldset
   %form{:method => "post", :action => "/project/#{@project.name}/information"}
     %p
@@ -38,6 +38,22 @@
     %p.quote
       %input{:type => "submit", :value => "Save"}
 
+- if authentication_user.is_admin
+  %h2 Project Groups
+  %form{:method => "post", :action => "/project/#{@project.name}/groups"}
+    %div{:class => "columns"}
+      - for group in Group.all
+        %p
+          %input{:type => "checkbox",
+                 :name => "groups[#{group.name}]",
+                 :id => "g_#{group.name}",
+                 :checked => @project.groups.include?(group),
+                 :disabled => !authentication_user.is_admin}
+          %label{:for => "g_#{group.name}"} #{group.desc}
+      %div{:class => "clearboth"}
+    %p
+      %input{:type => "submit", :value => "Save"}
+
 %h2 Classification
 %form{:method => "post", :action => "/project/#{@project.name}/classify"}
   %p
diff --git a/lib/views/project_list.haml b/lib/views/project_list.haml
index 81ef6cf..3db99b1 100644
--- a/lib/views/project_list.haml
+++ b/lib/views/project_list.haml
@@ -6,9 +6,12 @@
       %input{:type => "text", :name => "name", :id => "name" }
     %p
       %label{:for => "classification"} Classification:
-      %select{:name => "classification", :id => "classification"}
-        - for classification in Classification.find_all
-          %option{:name => classification.name} #{classification.name}
+      %input{:type => "text", :name => "name", :id => "name" }
+    %p.quote
+      %input{:type => "checkbox",
+             :name => "defaultsgroups",
+             :id => "defaultsgroups"}
+      Set default groups (archive, repo and public)
     %p.quote
       %input{:type => "submit", :value => "Create" }
 


More information about the Xfce4-commits mailing list