[Xfce4-commits] <moka:master> Allow changing permission for the interface.
Nick Schermer
noreply at xfce.org
Sun Nov 20 14:30:18 CET 2011
Updating branch refs/heads/master
to fac1d0a4a163defe1f6299a66f779dacfda85015 (commit)
from ca866704c8b17d5565bec84f407eb82795f5d323 (commit)
commit fac1d0a4a163defe1f6299a66f779dacfda85015
Author: Nick Schermer <nick at xfce.org>
Date: Sat Jul 9 22:24:48 2011 +0200
Allow changing permission for the interface.
examples/one-man-one-project/config.ru | 42 ++++++++++++++++++++++++++++++-
lib/controllers/maintainers.rb | 34 +++++++++++++++++++++++++
lib/controllers/projects.rb | 9 ++++++-
lib/models/role.rb | 3 +-
lib/views/maintainer_profile.haml | 37 ++++++++++++++++++++++++++++
lib/views/project_list.haml | 15 +++++++++++
6 files changed, 136 insertions(+), 4 deletions(-)
diff --git a/examples/one-man-one-project/config.ru b/examples/one-man-one-project/config.ru
index e47cd1d..384108d 100755
--- a/examples/one-man-one-project/config.ru
+++ b/examples/one-man-one-project/config.ru
@@ -89,10 +89,22 @@ DataMapper.auto_upgrade!
DataMapper.finalize
# create dummy roles
-admin = Moka::Models::Role.first_or_create(:name => 'admin')
+#admin = Moka::Models::Role.first_or_create(:name => 'admin')
+#admin.save
+
+#goodies = Moka::Models::Role.first_or_create(:name => 'goodies')
+#goodies.save
+
+admin = Moka::Models::Role.first_or_create(
+ { :name => 'admin' },
+ { :description => "Administrator" }
+)
admin.save
-goodies = Moka::Models::Role.first_or_create(:name => 'goodies')
+goodies = Moka::Models::Role.first_or_create(
+ { :name => 'goodies' },
+ { :description => "Goodies Maintainer" }
+)
goodies.save
# create dummy user
@@ -141,6 +153,32 @@ thunar.maintainers << nick
thunar.maintainers << jannis
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.save
+
+tumbler = Moka::Models::Project.first_or_create(
+ { :name => 'tumbler' },
+ { :website => 'http://www.xfce.org',
+ :description => 'Thumbnail generator' }
+)
+tumbler.maintainers << jannis
+tumbler.save
+
+libxfce4ui = Moka::Models::Project.first_or_create(
+ { :name => 'libxfce4ui' },
+ { :website => 'http://www.xfce.org',
+ :description => 'Xfce Widgets Library' }
+)
+libxfce4ui.maintainers << jannis
+libxfce4ui.maintainers << nick
+libxfce4ui.maintainers << jeromeg
+libxfce4ui.save
+
# create dummy classification
collection = Moka::Models::Collection.first_or_create(
{ :name => 'xfce' },
diff --git a/lib/controllers/maintainers.rb b/lib/controllers/maintainers.rb
index 3c78d67..f55cb34 100755
--- a/lib/controllers/maintainers.rb
+++ b/lib/controllers/maintainers.rb
@@ -61,6 +61,40 @@ module Moka
view :maintainer_profile
end
+
+ app.post '/maintainer/:name/permissions' do
+ @maintainer = Maintainer.get(params[:name])
+
+ authentication_required
+
+ @maintainer.roles.clear
+ if params[:roles]
+ for name in params[:roles].keys do
+ role = Role.get(name)
+ @maintainer.roles << role
+ end
+ end
+
+ @maintainer.collections.clear
+ if params[:collections]
+ for name in params[:collections].keys do
+ collection = Collection.get(name)
+ @maintainer.collections << collection
+ end
+ end
+
+ @maintainer.projects.clear
+ if params[:projects]
+ for name in params[:projects].keys do
+ project = Project.get(name)
+ @maintainer.projects << project
+ end
+ end
+
+ @maintainer.save
+
+ redirect "/maintainer/#{@maintainer.username}"
+ end
end
end
end
diff --git a/lib/controllers/projects.rb b/lib/controllers/projects.rb
index 14d7757..a2a0e24 100755
--- a/lib/controllers/projects.rb
+++ b/lib/controllers/projects.rb
@@ -4,6 +4,13 @@ module Moka
include Moka::Models
def self.registered(app)
+ app.get '/project' do
+
+ authentication_required
+
+ view :project_list
+ end
+
app.get '/project/:name' do
@project = Project.get(params[:name])
@@ -193,7 +200,7 @@ module Moka
if env['feeds']
if env['identica'] and params[:identica]
url = env['feeds'].get_project_feed_url(@project)
-
+
if env['identica'].group.nil?
@announcement_status = "#{@project.name} #{@release.version} released: #{url}"
else
diff --git a/lib/models/role.rb b/lib/models/role.rb
index c736974..2c0fd85 100644
--- a/lib/models/role.rb
+++ b/lib/models/role.rb
@@ -3,7 +3,8 @@ module Moka
class Role
include DataMapper::Resource
- property :name, String, :key => true
+ property :name, String, :key => true
+ property :description, String
has n, :maintainers, :through => Resource
end
diff --git a/lib/views/maintainer_profile.haml b/lib/views/maintainer_profile.haml
index beb42cc..a85482f 100644
--- a/lib/views/maintainer_profile.haml
+++ b/lib/views/maintainer_profile.haml
@@ -29,4 +29,41 @@
%input{:type => "submit", :value => "Save"}
%h2 Permissions
+%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}]", :checked => @maintainer.roles.include?(role), :disabled => !authentication_user.is_admin}
+ %label{:for => "roles[#{role.name}]"} #{role.description}
+ - if !visible_roles
+ %p This user has no roles.
+ %h3 Collections
+ - visible_collections = false
+ - for collection in Collection.all
+ - if authentication_user.is_admin or @maintainer.collections.include?(collection)
+ - visible_collections = true
+ %p
+ %input{:type => "checkbox", :name => "collections[#{collection.name}]", :checked => @maintainer.collections.include?(collection), :disabled => !authentication_user.is_admin}
+ %label{:for => "collections[#{collection.name}]"} #{collection.display_name}
+ - if !visible_collections
+ %p This user is not maintaining a collection.
+
+ %h3 Projects
+ - visible_projects = false
+ - for project in Project.all.sort
+ - if authentication_user.is_admin or @maintainer.projects.include?(project)
+ - visible_projects = true
+ %p
+ %input{:type => "checkbox", :name => "projects[#{project.name}]", :checked => @maintainer.projects.include?(project), :disabled => !authentication_user.is_admin}
+ %label{:for => "projects[#{project.name}]"}
+ %a{:href => "/project/#{project.name}" } #{project.name}
+ - if !visible_projects
+ %p This users is not maintaining a project.
+
+ - if authentication_user.is_admin
+ %p
+ %input{:type => "submit", :value => "Save"}
diff --git a/lib/views/project_list.haml b/lib/views/project_list.haml
new file mode 100644
index 0000000..a914bf7
--- /dev/null
+++ b/lib/views/project_list.haml
@@ -0,0 +1,15 @@
+%h2 Projects
+
+%table
+ %tr
+ %th Name
+ %th Description
+ %th Maintainers
+ - for project in Project.all.sort
+ %tr
+ %td
+ %a{:href => "/project/#{project.name}"} #{project.name}
+ %td
+ #{project.description}
+ %td
+ #{maintainer_names(project)}
More information about the Xfce4-commits
mailing list