Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:google/site-kit-wp into bug/5351…
Browse files Browse the repository at this point in the history
…-hide-goals-cta.
  • Loading branch information
hussain-t committed Jun 21, 2022
2 parents 60c432d + d7d1217 commit 472972e
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 7 deletions.
1 change: 1 addition & 0 deletions assets/js/components/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const Menu = forwardRef(

const menuComponent = new MDCMenu( menuRef.current );
menuComponent.listen( 'MDCMenu:selected', handleMenuSelected );
menuComponent.quickOpen = true;

setMenu( menuComponent );

Expand Down
4 changes: 3 additions & 1 deletion assets/js/components/ViewOnlyMenu/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export default function Service( { module } ) {

return (
<li className="googlesitekit-view-only-menu__service">
<Icon />
<span className="googlesitekit-view-only-menu__service--icon">
<Icon />
</span>
<span className="googlesitekit-view-only-menu__service--name">
{ name }
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ const { useSelect, useDispatch } = Data;
const viewAccessOptions = [
{
value: 'owner',
label: __( 'Only Me', 'google-site-kit' ),
label: __( 'Only me', 'google-site-kit' ),
},
{
value: 'all_admins',
label: __( 'All Admins', 'google-site-kit' ),
label: __( 'Any admin signed in with Google', 'google-site-kit' ),
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ describe( 'DashboardSharingSettings', () => {
).toBeInTheDocument();
} );

it( 'should set sharing management to `All Admins` and disabled if a module has shared ownership', () => {
it( 'should set sharing management to `Any admin signed in with Google` and disabled if a module has shared ownership', () => {
provideModules( registry, modules );
provideModuleRegistrations( registry );
provideSiteConnection( registry, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,28 @@

.googlesitekit-view-only-menu__service {
display: flex;
gap: 8px;
margin-bottom: 10px;

svg {
margin-right: 8px;
padding: 2px;
width: 24px;
}
}

.googlesitekit-view-only-menu__service--icon {
flex: 0 0 24px;
}

.googlesitekit-view-only-menu__service--name {
flex: 1;
flex: 0 0 100px;
font-size: 14px;
margin-right: 8px;
}

.googlesitekit-view-only-menu__service--owner {
color: $c-primary;
flex: 1;
font-size: 12px;
margin-left: auto;
}
Expand Down
28 changes: 27 additions & 1 deletion includes/Core/Modules/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,17 @@ private function get_oauth_client_for_datapoint( Datapoint $datapoint ) {
&& $this->is_shareable()
&& $datapoint->is_shareable()
&& $this->get_owner_id() !== get_current_user_id()
&& ! $this->is_recoverable()
&& current_user_can( Permissions::READ_SHARED_MODULE_DATA, $this->slug )
) {
return $this->get_owner_oauth_client();
$oauth_client = $this->get_owner_oauth_client();

try {
$this->validate_base_scopes( $oauth_client );
return $oauth_client;
} catch ( Exception $exception ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
// Fallthrough to default oauth client if scopes are unsatisfied.
}
}

return $this->authentication->get_oauth_client();
Expand Down Expand Up @@ -836,4 +844,22 @@ public function is_shareable() {

return false;
}

/**
* Checks whether the module is recoverable.
*
* @since n.e.x.t
*
* @return bool
*/
public function is_recoverable() {
/**
* Filters the recoverable status of the module.
*
* @since n.e.x.t
* @param bool $_ Whether or not the module is recoverable. Default: false
* @param string $slug Module slug.
*/
return (bool) apply_filters( 'googlesitekit_is_module_recoverable', false, $this->slug );
}
}
9 changes: 9 additions & 0 deletions includes/Core/Modules/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ function ( $data ) {
}
);

add_filter(
'googlesitekit_is_module_recoverable',
function ( $recoverable, $slug ) {
return $this->is_module_recoverable( $slug );
},
10,
2
);

add_filter( 'option_' . Module_Sharing_Settings::OPTION, $this->get_method_proxy( 'filter_shared_ownership_module_settings' ) );
add_filter( 'default_option_' . Module_Sharing_Settings::OPTION, $this->get_method_proxy( 'filter_shared_ownership_module_settings' ), 20 );

Expand Down
21 changes: 21 additions & 0 deletions tests/phpunit/integration/Core/Modules/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,27 @@ public function test_is_shareable() {
$this->assertFalse( $module->is_shareable() );
}

public function test_is_recoverable() {
remove_all_filters( 'googlesitekit_is_module_recoverable' );
$module = new FakeModule( new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) );
$invocations = array();
$spy = function ( ...$args ) use ( &$invocations ) {
$invocations[] = $args;
return $args[0];
};

// is_recoverable is a proxy through this filter which is handled by
// Modules::is_module_recoverable. @see \Google\Site_Kit\Tests\Core\Modules\ModulesTest::test_is_module_recoverable
add_filter( 'googlesitekit_is_module_recoverable', $spy, 10, 2 );

$module->is_recoverable();

$this->assertCount( 1, $invocations );
list ( $given, $slug ) = $invocations[0];
$this->assertFalse( $given );
$this->assertEquals( $module->slug, $slug );
}

/**
* Determine the difference between the expected and the returned date.
*
Expand Down

0 comments on commit 472972e

Please sign in to comment.