[MKDoc-commit] PAtch from Sam -- Attached is a patch implementing the admin groups UI

chris at mkdoc.demon.co.uk chris at mkdoc.demon.co.uk
Mon May 16 10:25:07 BST 2005


Log Message:
-----------
PAtch from Sam -- Attached is a patch implementing the admin groups UI and the document
preferences group interface.  You'll need to add the new plugin
(flo::plugin::Admin::Group) to any customized users.conf you have.

Tags:
----
mkdoc-1-6

Modified Files:
--------------
    mkd/conf:
        users.conf
    mkd/flo/plugin/Admin:
        New.pm
        Properties.pm
    mkd/templates/admin/new:
        en.html
    mkd/templates/admin/properties:
        en.html
    mkd/templates/fragments/admin:
        en.html

-------------- next part --------------
Index: users.conf
===================================================================
RCS file: /var/spool/cvs/mkd/conf/Attic/users.conf,v
retrieving revision 1.1.2.36
retrieving revision 1.1.2.37
diff -Lconf/users.conf -Lconf/users.conf -u -r1.1.2.36 -r1.1.2.37
--- conf/users.conf
+++ conf/users.conf
@@ -42,6 +42,7 @@
 flo::plugin::Admin::AudienceInsert
 flo::plugin::Admin::AudienceModify
 flo::plugin::Admin::AudienceDelete
+flo::plugin::Admin::Group
 flo::plugin::Admin::UserCSV
 
 # preferences
Index: Properties.pm
===================================================================
RCS file: /var/spool/cvs/mkd/flo/plugin/Admin/Properties.pm,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -Lflo/plugin/Admin/Properties.pm -Lflo/plugin/Admin/Properties.pm -u -r1.1.2.8 -r1.1.2.9
--- flo/plugin/Admin/Properties.pm
+++ flo/plugin/Admin/Properties.pm
@@ -230,6 +230,70 @@
     return (wantarray) ? @unselected : \@unselected;
 }
 
+##
+# $self->groups;
+# -----------------
+#   Returns all groups related to the current document,
+#   but adds a 'checked' flag for those which are checked and a 
+#   'readonly' flag for those that should not be editable.
+##
+sub groups {
+    my $self = shift;
+    my $dbh = lib::sql::DBH->get();
+    my $results = $dbh->selectall_arrayref(
+      'SELECT ID, Name, Description FROM Grp ORDER BY name');
+
+    my @groups;
+    foreach my $row (@$results) {
+        my %group = (id          => $row->[0],
+                     name        => $row->[1],
+                     description => $row->[2]);
+        $self->_group_selection(\%group);
+        push(@groups, \%group);
+    }
+
+    return wantarray ? @groups : \@groups;
+}
+
+# determine whether a group is selected, marking it readonly if the
+# selection comes from a parent.  Also mark readonly if the editor
+# isn't a member of the group.
+sub _group_selection {
+    my ($self, $group) = @_;
+    my $dbh            = lib::sql::DBH->get();
+    my $document       = flo::Standard::current_document();
+    my $group_id       = $group->{id};
+
+    # get list of all documents to check
+    my @documents = ($document, $document->ancestors);
+    
+    # get results for each document for this group
+    my $this_id    = $document->id;
+    foreach my $doc (@documents) {        
+        my ($exists) = $dbh->selectrow_array(
+          'SELECT 1 FROM Document_Grp WHERE Document_ID = ? AND Grp_ID = ?',
+          undef, $doc->id, $group_id);
+        
+        # got a winner, set it checked and reasonly if this came from
+        # up the line
+        if ($exists) {
+            $group->{checked}  = 1;
+            $group->{readonly} = 1 unless $doc->id == $this_id;
+            last;
+        }
+    }
+
+    # check for group membership if the group isn't already readonly
+    unless ($group->{readonly}) {
+        my ($member) = $dbh->selectrow_array(
+          'SELECT 1 FROM Editor_Grp WHERE Editor_ID = ? AND Grp_ID = ?',
+          undef, $self->user->id, $group_id);
+        $group->{readonly} = 1 unless $member;
+    }
+}
+
+    
+
 
 ##
 # $self->audiences;
@@ -375,6 +439,7 @@
     $document->validate() || return $self->http_get();
     $document->save();
     $self->_set_audiences_from_cgi ($document);
+    $self->_set_groups_from_cgi ($document);
     
     # we have finished changing the properties, let's redirect
     # to the current document
@@ -412,6 +477,36 @@
     $document_audience_table->insert ( Document_ID => $document->id(), Audience_ID => $_ ) for (@valid_ids);
 }
 
+##
+# $self->_set_groups_from_cgi;
+# -------------------------------
+#   Sets the groups in the 'Document_Grp' table from the CGI object.
+##
+sub _set_groups_from_cgi {
+    my $self        = shift;
+    my $document    = shift;
+    my $document_id = $document->id;
+    my $cgi         = flo::Standard::cgi->new;
+    my $dbh         = lib::sql::DBH->get();    
+
+    my %checked = map { $_ => 1 } $cgi->param('group');
+    my %groups  = map { $_->{id} => $_ } $self->groups();
+    foreach my $group_id (keys %groups) {
+        # don't touch readonly settings
+        next if $groups{$group_id}->{readonly};
+
+        # clear the current value
+        $dbh->do('DELETE FROM Document_Grp
+                  WHERE Document_ID = ? AND Grp_ID = ?',
+                 undef, $document_id, $group_id);
+
+        # set if checked
+        $dbh->do('INSERT INTO Document_Grp (Document_ID, Grp_ID) VALUES (?,?)',
+                 undef, $document_id, $group_id)
+          if $checked{$group_id};
+    }
+}
+
 
 ##
 # $self->lang;
Index: New.pm
===================================================================
RCS file: /var/spool/cvs/mkd/flo/plugin/Admin/New.pm,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -Lflo/plugin/Admin/New.pm -Lflo/plugin/Admin/New.pm -u -r1.1.2.8 -r1.1.2.9
--- flo/plugin/Admin/New.pm
+++ flo/plugin/Admin/New.pm
@@ -103,6 +103,7 @@
     flo::RedirectManager->document_added ($document->path());
     
     $self->_set_audiences_from_cgi ($document);
+    $self->_set_groups_from_cgi ($document);
     
     # add content if we passed any
     my $editor = _new flo::Editor (cgi => $cgix);
Index: en.html
===================================================================
RCS file: /var/spool/cvs/mkd/templates/admin/new/Attic/en.html,v
retrieving revision 1.10.2.16
retrieving revision 1.10.2.17
diff -Ltemplates/admin/new/en.html -Ltemplates/admin/new/en.html -u -r1.10.2.16 -r1.10.2.17
--- templates/admin/new/en.html
+++ templates/admin/new/en.html
@@ -239,8 +239,9 @@
           </p>
         </fieldset>
 
- <!--? The audiences are in a seperate file ?-->
+ <!--? The audiences and groups interfaces in seperate files ?-->
  <?include file="/admin/properties/audiences/"?>
+ <?include file="/admin/properties/groups/"?>
   
         <fieldset
           class="optional-metadata"
Index: en.html
===================================================================
RCS file: /var/spool/cvs/mkd/templates/admin/properties/Attic/en.html,v
retrieving revision 1.7.2.25
retrieving revision 1.7.2.26
diff -Ltemplates/admin/properties/en.html -Ltemplates/admin/properties/en.html -u -r1.7.2.25 -r1.7.2.26
--- templates/admin/properties/en.html
+++ templates/admin/properties/en.html
@@ -272,8 +272,9 @@
   
         </fieldset>
  
- <!--? The audiences are in a seperate file ?-->
+ <!--? The audience and group controls are in seperate files ?-->
  <?include file="/admin/properties/audiences/"?>
+ <?include file="/admin/properties/groups/"?>
   
         <fieldset
           class="optional-metadata"
Index: en.html
===================================================================
RCS file: /var/spool/cvs/mkd/templates/fragments/admin/Attic/en.html,v
retrieving revision 1.1.2.18
retrieving revision 1.1.2.19
diff -Ltemplates/fragments/admin/en.html -Ltemplates/fragments/admin/en.html -u -r1.1.2.18 -r1.1.2.19
--- templates/fragments/admin/en.html
+++ templates/fragments/admin/en.html
@@ -19,6 +19,7 @@
     user_add              plugin: flo::plugin::Admin::UserInsert;
     audience_list         plugin: flo::plugin::Admin::AudienceList;
     audience_add          plugin: flo::plugin::Admin::AudienceInsert;
+    group                 plugin: flo::plugin::Admin::Group;
               "
 >
   <a
@@ -47,7 +48,7 @@
     title="List, edit, add and delete audiences."
     petal:attributes="href audience_list/uri"
     petal:omit-tag="false: audience_list/would_activate"
-  >Audiences</a>
+  >Audiences</a> |
 <!--?
   <a
     href="#"
@@ -56,6 +57,12 @@
     petal:omit-tag="false: audience_add/would_activate"
   >Add Audience</a> |
 ?-->
+  <a
+    href="#"
+    title="List, edit, add and delete groups."
+    petal:attributes="href group/uri"
+    petal:omit-tag="false: group/would_activate"
+  >Groups</a>
 </div>
 
 <div


More information about the MKDoc-commit mailing list