<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[2777] sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory: Plugin Directory: Introduce the Plugin Committer/Review & Admin roles.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/2777">2777</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/2777","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dd32</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-03-22 06:21:26 +0000 (Tue, 22 Mar 2016)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Plugin Directory: Introduce the Plugin Committer/Review & Admin roles. Use the capabilities throughout the core flows of the admin.
This also has a few hacks to make plugin committers/authors only see plugins which they can manage, although a few core bugs remain which cause non-owner committers not to be able to edit plugins properly.

See <a href="http://meta.trac.wordpress.org/ticket/1571">#1571</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminclasscustomizationsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminlisttableclasscommittersphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/list-table/class-committers.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminmetaboxclasscommittersphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-committers.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclassplugindirectoryphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclasstoolsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclasscapabilitiesphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-capabilities.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminclasscustomizationsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php  2016-03-21 22:41:10 UTC (rev 2776)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php    2016-03-22 06:21:26 UTC (rev 2777)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,6 +1,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> namespace WordPressdotorg\Plugin_Directory\Admin;
</span><span class="cx" style="display: block; padding: 0 10px"> use \WordPressdotorg\Plugin_Directory;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use \WordPressdotorg\Plugin_Directory\Tools;
</ins><span class="cx" style="display: block; padding: 0 10px"> use \WordPressdotorg\Plugin_Directory\Admin\List_Table\Plugin_Posts;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -27,7 +28,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                add_action( 'add_meta_boxes', array( $this, 'register_admin_metaboxes' ), 10, 1 );
</span><span class="cx" style="display: block; padding: 0 10px">                add_action( 'do_meta_boxes', array( $this, 'replace_title_global' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 add_action( 'save_post_plugin', array( $this, 'save_plugin_post' ), 10, 2 );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                add_filter( 'views_edit-plugin', array( $this, 'list_table_views' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'admin_head-edit.php', array( $this, 'plugin_posts_list_table' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -39,6 +42,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'postbox_classes_plugin_plugin-committers', array( __NAMESPACE__ . '\Metabox\Committers',     'postbox_classes' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'wp_ajax_add-committer',    array( __NAMESPACE__ . '\Metabox\Committers', 'add_committer'    ) );
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'wp_ajax_delete-committer', array( __NAMESPACE__ . '\Metabox\Committers', 'remove_committer' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                add_action( 'admin_menu', array( $this, 'admin_menu' ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -83,7 +88,74 @@
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function admin_menu() {
+               // WordPress requires that the plugin post_type have at least one submenu accessible *other* than itself.
+               // If it doesn't have at least one submenu then users who cannot also publish posts will not be able to access the post type.
+               add_submenu_page( 'edit.php?post_type=plugin', 'Plugin Handbook', 'Plugin Handbook', 'read', 'handbook', function() {} );
+               add_submenu_page( 'edit.php?post_type=plugin', 'Readme Validator', 'Readme Validator', 'read', 'readme_validator', function() {} );
+
+               remove_menu_page( 'index.php' );
+               remove_menu_page( 'profile.php' );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Filter the query in wp-admin to list only 
+        */
+       public function pre_get_posts( $query ) {
+               global $wpdb;
+               if ( ! $query->is_main_query() ) {
+                       return;
+               }
+
+               if ( ! current_user_can( 'plugin_edit_others' ) || ( isset( $query->query['author'] ) && $query->query['author'] == get_current_user_id() ) ) {
+                       $query->query_vars['author'] = get_current_user_id();
+                       $plugins = Tools::get_users_write_access_plugins( get_current_user_id() );
+                       if ( $plugins ) {
+                               $query->query_vars['post_name__in'] = $plugins;
+                               add_filter( 'posts_where', array( $this, 'pre_get_posts_sql_name_or_user' ) );
+                       }
+               }
+       }
+
+       /**
+        * Custom callback for pre_get_posts to use an OR query between post_name & post_author
+        *
+        * @ignore
+        */
+       public function pre_get_posts_sql_name_or_user( $where ) {
+               remove_filter( 'posts_where', array( $this, 'pre_get_posts_sql_name_or_user' ) );
+
+               // Replace `post_name IN(..) AND post_author IN (..)`
+               // With `( post_name IN() OR post_author IN() )`
+
+               $where = preg_replace( "!\s(\S+\.post_name IN .+?)\s*AND\s*(\s\S+\.post_author.+?)AND!i", ' ( $1 OR $2 ) AND', $where );
+               return $where;
+       }
+
+       public function list_table_views( $views ) {
+               global $wp_query;
+               if ( current_user_can( 'plugin_edit_others' ) ) {
+                       return $views;
+               }
+               // The only view the user needs, is their own.
+               return array(
+                       sprintf(
+                               '<a href="#" class="current">%s</a>',
+                               sprintf(
+                                       _nx(
+                                               'Mine <span class="count">(%s)</span>',
+                                               'Mine <span class="count">(%s)</span>',
+                                               $wp_query->found_posts,
+                                               'posts',
+                                               'wporg-posts'
+                                       ),
+                                       number_format_i18n( $wp_query->found_posts )
+                               )
+                       )
+               );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Replaces the WP_Posts_List_Table object with the extended Plugin_Posts list table object.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @global string               $post_type     The current post type.
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminlisttableclasscommittersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/list-table/class-committers.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/list-table/class-committers.php   2016-03-21 22:41:10 UTC (rev 2776)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/list-table/class-committers.php     2016-03-22 06:21:26 UTC (rev 2777)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -32,7 +32,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return bool
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function ajax_user_can() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                return current_user_can( 'manage_committers' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         return current_user_can( 'plugin_remove_committer' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -149,8 +149,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $actions = array();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Check if the committer for this row is removable.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( current_user_can( 'list_users' ) ) {
-                       $post_id = get_post()->ID;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $post_id = get_post()->ID;
+               if ( current_user_can( 'plugin_remove_committer', $post_id ) && $user_object->ID != get_current_user_id() ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $actions['delete'] = "<a class='submitremove' data-wp-lists='delete:the-committer-list:committer-{$user_object->ID}:faafaa:post_id={$post_id}' href='" . wp_nonce_url( 'users.php?action=remove&amp;committer=' . $user_object->ID, "remove-committer-{$user_object->ID}" ) . "'>" . __( 'Remove', 'wporg-plugins' ) . "</a>";
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminmetaboxclasscommittersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-committers.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-committers.php      2016-03-21 22:41:10 UTC (rev 2776)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-committers.php        2016-03-22 06:21:26 UTC (rev 2777)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,6 +1,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> namespace WordPressdotorg\Plugin_Directory\Admin\Metabox;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Admin\List_Table;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use WordPressdotorg\Plugin_Directory\Tools;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px">  * The Plugin Committers admin metabox.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -34,12 +35,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * Ajax handler for adding a new committer.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public static function add_committer() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                check_ajax_referer( 'add-committer' );
-
</del><span class="cx" style="display: block; padding: 0 10px">                 $login    = isset( $_POST['add_committer'] ) ? sanitize_user( $_POST['add_committer'] ) : '';
</span><span class="cx" style="display: block; padding: 0 10px">                $post_id  = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response = new \WP_Ajax_Response();
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                check_ajax_referer( 'add-committer' );
+
+               $response    = new \WP_Ajax_Response();
+               $plugin_slug = get_post( $post_id )->post_name;
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( ! $committer = get_user_by( 'login', $login ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $response->add( array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'what' => 'committer',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -48,24 +51,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $response->send();
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // @todo: Capabilities.
-               if ( ! current_user_can( 'add_committers', $post_id ) ) {
-                       //      wp_die( -1 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! current_user_can( 'plugin_add_committer', $post_id ) ) {
+                               wp_die( -1 );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                global $post, $wpdb;
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $post   = get_post( $post_id );
-               $result = $wpdb->insert( PLUGINS_TABLE_PREFIX . 'svn_access', array(
-                       'path'   => "/{$post->post_name}",
-                       'user'   => $login,
-                       'access' => 'rw',
-               ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $result = Tools::grant_plugin_committer( $plugin_slug, $committer );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( ! $result ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( 'Duplicate entry' === substr( $wpdb->last_error, 0, 15 ) ) {
-                               $message = __( 'Duplicate committer detected.', 'wporg-plugins' );
-                       } else {
-                               $message = __( 'An error has occurred. Please reload the page and try again.', 'wporg-plugins' );
-                       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $message = __( 'An error has occurred. Please reload the page and try again.', 'wporg-plugins' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        $response->add( array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'what' => 'committer',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -94,7 +87,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                check_ajax_referer( "remove-committer-$id" );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $response = new \WP_Ajax_Response();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $response    = new \WP_Ajax_Response();
+               $plugin_slug = get_post( $post_id )->post_name;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! $committer = get_user_by( 'id', $id ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $response->add( array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -104,18 +98,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $response->send();
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // @todo: Capabilities.
-               if ( ! current_user_can( 'remove_committers', $post_id ) ) {
-                       //      wp_die( -1 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! current_user_can( 'plugin_remove_committer', $post_id ) ) {
+                               wp_die( -1 );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $plugin_slug = get_post( $post_id )->post_name;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $result = Tools::revoke_plugin_committer( $plugin_slug, $committer );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $result = $GLOBALS['wpdb']->delete( PLUGINS_TABLE_PREFIX . 'svn_access', array(
-                       'path' => "/{$plugin_slug}",
-                       'user' => $committer->user_login,
-               ) );
-
</del><span class="cx" style="display: block; padding: 0 10px">                 wp_die( $result );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclasscapabilitiesphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-capabilities.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-capabilities.php                          (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-capabilities.php    2016-03-22 06:21:26 UTC (rev 2777)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,119 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory;
+use WordPressdotorg\Plugin_Directory\Tools;
+/**
+ * Manages the capabilities for the WordPress.org plugins directory.
+ *
+ * @package WordPressdotorg\Plugin_Directory
+ */
+class Capabilities {
+
+       public static function map_meta_cap( $required_caps, $cap, $user_id, $context ) {
+               switch( $cap ) {
+
+                       case 'plugin_add_committer':
+                       case 'plugin_remove_committer':
+                       case 'plugin_edit':
+                               $required_caps = array();
+                               $post = self::get_post_from_context( $context );
+                               if ( ! $post ) {
+                                       $required_caps[] = 'do_not_allow';
+                                       break;
+                               }
+
+                               $user = new \WP_User( $user_id );
+                               $committers = Tools::get_plugin_committers( $post->post_name );
+
+                               if ( $post->post_author === $user_id ) {
+                                       $required_caps[] = 'plugin_edit_own';
+                               } elseif ( in_array( $user->user_login, $committers, true ) ) {
+                                       $required_caps[] = 'plugin_edit_own';
+                               } else {
+                                       if ( 'pending' == $post->post_status ) {
+                                               $required_caps[] = 'plugin_edit_pending';
+                                       } else {
+                                               $required_caps[] = 'plugin_edit_others';
+                                       }
+                               }
+                               break;
+
+                       // Don't allow any users to alter the post meta for plugins
+                       case 'add_post_meta':
+                       case 'edit_post_meta':
+                       case 'delete_post_meta':
+                               $post = get_post( $context );
+                               if ( $post && 'plugin' == $post->post_type ) {
+                                       $required_caps[] = 'do_not_allow';
+                                       break;
+                               }
+                               break;
+
+                       case 'plugin_transition':
+                               /*
+                                Handle the transition between
+                                pending -> publish
+                                publish -> rejected
+                                publish -> closed
+                                etc
+                               */
+                               break;
+               }
+
+               return $required_caps;
+       }
+
+       protected static function get_post_from_context( $context ) {
+               if ( ! $context ) {
+                       return false;
+               }
+               $context = $context[0];
+
+               $post = false;
+               if ( is_int( $context ) ) {
+                       $post = get_post( $context );
+               } elseif ( $context instanceof \WP_Post ) {
+                       $post = $context;
+               } elseif ( is_string( $context ) ) {
+                       $post = Plugin_Directory::get_plugin_post( $context );
+               }
+               if ( ! $post || 'plugin' != $post->post_type ) {
+                       return false;
+               }
+               return $post;
+       }
+
+       public static function add_roles() {
+               $committer = array(
+                       'read' => true,
+                       'plugin_dashboard_access' => true,
+                       'plugin_edit_own' => true,
+                       'plugin_set_tags' => true,
+                       'plugin_add_committer' => true,
+               );
+
+               $reviewer = array(
+                       'read' => true,
+                       'plugin_dashboard_access' => true,
+                       'plugin_edit_pending' => true,
+                       'plugin_approve' => true,
+                       'plugin_reject' => true,
+               );
+
+               $admin = array_merge( $reviewer, array(
+                       'plugin_add_committer' => true,
+                       'plugin_edit_others' => true,
+                       'plugin_disable' => true,
+                       'plugin_close' => true,
+                       'plugin_set_category' => true, // Special categories
+               ) );
+
+               // Remove the roles first, incase we've changed the permission set.
+               remove_role( 'plugin_committer' );
+               remove_role( 'plugin_reviewer' );
+               remove_role( 'plugin_admin' );
+               add_role( 'plugin_committer', 'Plugin Committer', $committer );
+               add_role( 'plugin_reviewer',  'Plugin Reviewer',  $reviewer );
+               add_role( 'plugin_admin',     'Plugin Admin',     $admin );
+       }
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-capabilities.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclassplugindirectoryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php      2016-03-21 22:41:10 UTC (rev 2776)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php        2016-03-22 06:21:26 UTC (rev 2777)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -25,8 +25,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                add_action( 'pre_get_posts', array( $this, 'use_plugins_in_query' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'the_content', array( $this, 'filter_post_content_to_correct_page' ), 1 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                add_filter( 'map_meta_cap', array( __NAMESPACE__ . '\Capabilities', 'map_meta_cap' ), 10, 4 );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // Load all Admin-specific items.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                add_action( 'admin_init', array( __NAMESPACE__ . '\Admin\Customizations', 'instance' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Cannot be included on `admin_init` to allow access to menu hooks
+               if ( defined( 'WP_ADMIN' ) && WP_ADMIN ) {
+                       Admin\Customizations::instance();
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                register_activation_hook( PLUGIN_FILE, array( $this, 'activate' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                register_deactivation_hook( PLUGIN_FILE, array( $this, 'deactivate' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -59,10 +64,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'has_archive'     => true,
</span><span class="cx" style="display: block; padding: 0 10px">                        'rewrite'         => false,
</span><span class="cx" style="display: block; padding: 0 10px">                        'menu_icon'       => 'dashicons-admin-plugins',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'capability_type' => array( 'post', 'posts' ), // TODO roles & capabilities
-                       'map_meta_cap'    => true,
</del><span class="cx" style="display: block; padding: 0 10px">                         'capabilities'    => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'create_posts' => 'do_not_allow'
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'edit_post'          => 'plugin_edit',
+                               'read_post'          => 'read',
+                               'edit_posts'         => 'plugin_dashboard_access',
+                               'edit_others_posts'  => 'plugin_edit_others',
+                               'read_private_posts' => 'do_not_allow',
+                               'delete_posts'       => 'do_not_allow',
+                               'create_posts'       => 'do_not_allow'
</ins><span class="cx" style="display: block; padding: 0 10px">                         )
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -70,9 +79,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'hierarchical'      => true,
</span><span class="cx" style="display: block; padding: 0 10px">                        'query_var'         => 'plugin_category',
</span><span class="cx" style="display: block; padding: 0 10px">                        'rewrite'           => false,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'public'            => true,
-                       'show_ui'           => true,
-                       'show_admin_column' => true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'public'            => false,
+                       'show_ui'           => current_user_can( 'plugin_set_category' ),
+                       'show_admin_column' => current_user_can( 'plugin_set_category' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         'meta_box_cb'       => 'post_categories_meta_box',
</span><span class="cx" style="display: block; padding: 0 10px">                        'capabilities'      => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'assign_terms' => 'manage_categories',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -101,31 +110,33 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'show_ui'           => true,
</span><span class="cx" style="display: block; padding: 0 10px">                        'show_admin_column' => true,
</span><span class="cx" style="display: block; padding: 0 10px">                        'meta_box_cb'       => array( __NAMESPACE__ . '\Admin\Metabox\Plugin_Tags', 'display' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'capabilities'      => array()
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'capabilities'      => array(
+                               'assign_terms' => 'plugin_set_tags'
+                       )
</ins><span class="cx" style="display: block; padding: 0 10px">                 ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                register_post_status( 'pending', array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'label'                     => _x( 'Pending', 'plugin status', 'wporg-plugins' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'public'                    => false,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'show_in_admin_status_list' => true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'show_in_admin_status_list' => current_user_can( 'plugin_approve' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         'label_count'               => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'wporg-plugins' ),
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><span class="cx" style="display: block; padding: 0 10px">                register_post_status( 'disabled', array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'label'                     => _x( 'Disabled', 'plugin status', 'wporg-plugins' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'public'                    => false,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'show_in_admin_status_list' => true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'show_in_admin_status_list' => current_user_can( 'plugin_disable' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         'label_count'               => _n_noop( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', 'wporg-plugins' ),
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><span class="cx" style="display: block; padding: 0 10px">                register_post_status( 'closed', array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'label'                     => _x( 'Closed', 'plugin status', 'wporg-plugins' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'public'                    => false,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'show_in_admin_status_list' => true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'show_in_admin_status_list' => current_user_can( 'plugin_close' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         'label_count'               => _n_noop( 'Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'wporg-plugins' ),
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><span class="cx" style="display: block; padding: 0 10px">                register_post_status( 'rejected', array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'label'                     => _x( 'Rejected', 'plugin status', 'wporg-plugins' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'public'                    => false,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'show_in_admin_status_list' => true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'show_in_admin_status_list' => current_user_can( 'plugin_reject' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         'label_count'               => _n_noop( 'Rejected <span class="count">(%s)</span>', 'Rejected <span class="count">(%s)</span>', 'wporg-plugins' ),
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -141,6 +152,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                add_rewrite_endpoint( 'developers',   EP_PERMALINK );
</span><span class="cx" style="display: block; padding: 0 10px">                add_rewrite_endpoint( 'other_notes',  EP_PERMALINK );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // If changing capabilities around, uncomment this.
+               //Capabilities::add_roles();
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // When this plugin is used in the context of a Rosetta site, handle it gracefully
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'wordpress.org' != $_SERVER['HTTP_HOST'] && defined( 'WPORG_PLUGIN_DIRECTORY_BLOGID' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        add_filter( 'option_home',    array( $this, 'rosetta_network_localize_url' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -277,11 +291,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @param \WP_Query $wp_query The WordPress Query object.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function use_plugins_in_query( $wp_query ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! $wp_query->is_main_query() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( is_admin() || ! $wp_query->is_main_query() ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         return;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( empty( $wp_query->query_vars['pagename'] ) && ( empty( $wp_query->query_vars['post_type'] ) || 'posts' == $wp_query->query_vars['post_type'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( empty( $wp_query->query_vars['pagename'] ) && ( empty( $wp_query->query_vars['post_type'] ) || 'post' == $wp_query->query_vars['post_type'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $wp_query->query_vars['post_type'] = array( 'plugin' );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclasstoolsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php 2016-03-21 22:41:10 UTC (rev 2776)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php   2016-03-22 06:21:26 UTC (rev 2777)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -40,6 +40,22 @@
</span><span class="cx" style="display: block; padding: 0 10px">                return $wpdb->get_col( $wpdb->prepare( 'SELECT user FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE path = %s', "/{$plugin_slug}" ) );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public static function get_users_write_access_plugins( $user ) {
+               global $wpdb;
+               if ( ! $user instanceof \WP_User ) {
+                       $user = new \WP_User( $user );
+               }
+               if ( ! $user->exists() ) {
+                       return false;
+               }
+
+               $plugins = $wpdb->get_col( $wpdb->prepare( 'SELECT path FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE user = %s', $user->user_login ) );
+               $plugins = array_map( function( $plugin ) { return trim( $plugin, '/' ); }, $plugins );
+
+               return $plugins;
+
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         /**
</span><span class="cx" style="display: block; padding: 0 10px">         * Grant a user RW access to a plugin.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -54,11 +70,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $user = new \WP_User( $user );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! $user->exists() || ! Plugin_Directory::instance()->get_plugin_post( $plugin_slug ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! $user->exists() || ! Plugin_Directory::get_plugin_post( $plugin_slug ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         return false;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $existing_committers = wp_list_pluck( self::get_plugin_committers( $plugin_slug ), 'user_login' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $existing_committers = self::get_plugin_committers( $plugin_slug );
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( in_array( $user->user_login, $existing_committers, true ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        // User already has write access
</span><span class="cx" style="display: block; padding: 0 10px">                        return true;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -88,7 +104,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $user = new \WP_User( $user );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! $user->exists() || ! Plugin_Directory::instance()->get_plugin_post( $plugin_slug ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! $user->exists() || ! Plugin_Directory::get_plugin_post( $plugin_slug ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         return false;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre>
</div>
</div>

</body>
</html>