As the title says - previously you could have options on each and every resource method. This was removed when ctools ui was introduced. I've tried to bring back parts of it - the UI works, but I don't think anything is saved correctly :/

Any help on finishing this patch would be appreciated.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

voxpelli’s picture

Assigned: Unassigned » kylebrowning
voxpelli’s picture

Priority: Normal » Major

This should probably be a major as it's a pretty serious regression? The usefulness of the Services OAuth module is very limited without this - if it at all works like expected.

kylebrowning’s picture

Status: Needs work » Closed (won't fix)

Actually I'm not so sure this is true. You now set controller settings via the authentication tab.
I tested this with oath and it worked as expected

voxpelli’s picture

Status: Closed (won't fix) » Active

You can set resource level authentication in the authentication tab now? You couldn't before and I'm not very sure that it would be wise to duplicate the entire list of resources in the authentication tab.

Also - I must insist on the priority of this - it severely hampers the usefulness of the OAuth module (and other advanced authentication modules).

kylebrowning’s picture

Can you refer me to the code where it WAS working that way?

I went through all the way back to last Summer(July 1st) and scoured through the code to find a working version of this. I know you mentioned it was before the Resource UI switch, but I havnt been able to see this.

The patch that you posted seems to add a CONTROLLER SETTINGS to each endpoint. If you look at services_oauth the controller settings refer to this

function _services_oauth_controller_settings($settings, $controller, $endpoint, $class, $name) {
  $form = array();

  $cc = $controller['endpoint']['services_oauth'];
  $auth_levels = array();
  $context = oauth_common_context_load($settings['oauth_context']);
  foreach ($context->authorization_levels as $name => $level) {
    $auth_levels[$name] = t($level['title']);
  }

  $form['credentials'] = array(
    '#type'          => 'select',
    '#options'       => array(
      'none'              => t('None'),
      'unsigned_consumer' => t('Unsigned with consumer key'),
      'consumer'          => t('Consumer key'),
      'token'             => t('Consumer key and access token'),
    ),
    '#default_value' => !empty($cc['credentials']) ? $cc['credentials'] : 'token',
    '#title'         => t('Required authentication'),
    '#description'   => t('Authorization levels will <em>not</em> be applied if the consumer isn\'t required to supply a access token.'),
  );

  $form['authorization'] = array(
    '#type'          => 'select',
    '#options'       => $auth_levels,
    '#default_value' => !empty($cc['authorization']) ? $cc['authorization'] : '*',
    '#title'         => t('Required authorization'),
  );

  return $form;
}

So, your adding settings to every single method about whether it should be authorized or not? Thats what confused and made me think that that code should be on the Authroization settings tab, not per resource method.

I could be wrong and am happy to get this in before the next RC, i just need to know what specifically it is that is needed by services_oauth.

Can you help me help you?

voxpelli’s picture

it was broken when you rewrote the UI to use CTools' Export UI - so any version before that should work (at least on D6 - if it doesn't on D7 then something else has been broken there in either OAuth.module or Services.module)

Use of the authentication modules 'controller_settings' has at least been around since march this year at least: http://drupalcode.org/project/services.git/blob/b8ec687d0874599f76402b4a...

I don't really care where's it is added - but the authentication mechanisms need the 'controller_settings' option since different Services resources and methods may require different access levels. You don't want to give write access to everyone who only needs read access - eg. Twitter has three levels and others has even more.

Seems easier to add it to the existing list of resources and methods instead of having to duplicate that list. If I remember correctly my patch adds the UI elements (to show how this can be solved), but doesn't deal with fixing the data of the changed structure.

kylebrowning’s picture

Ok heres an updated patch that brings the functionality full circle and fixes the settings for services oauth.
I have no idea if services authenticated call is working, but that to me is a separate bug/patch.

The reason you see changes to the services_oauth.inc is because I wanted to prove the settings save and show per endpoint.

kylebrowning’s picture

Status: Active » Needs review
kylebrowning’s picture

Status: Needs review » Needs work

Doesn't apply, but this is pretty major for oauth to work

kylebrowning’s picture

Category: feature » task
kylebrowning’s picture

Status: Needs work » Needs review
FileSize
11.57 KB

Heres an updated version of this that i THINK fully covers the scope of this task.

Please review

ygerasimov’s picture

Status: Needs review » Needs work

I can't apply the patch. Also some trailing spaces have been added.

error: patch failed: plugins/export_ui/services_ctools_export_ui.class.php:232
error: plugins/export_ui/services_ctools_export_ui.class.php: patch does not apply
error: patch failed: services.admin.inc:12
error: services.admin.inc: patch does not apply
kylebrowning’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Needs work » Needs review

Forgive me this patch is for 6.x right now as oAuth really only works in 6.x

kylebrowning’s picture

kylebrowning’s picture

updated patch.

ksenzee’s picture

Status: Needs review » Needs work

The default values for the resources form don't seem to be loading correctly. When I hit admin/build/services/list//resources, none of the checkboxes are checked. If I make changes to the form and hit Save, none of my changes are reflected when the page reloads.

kylebrowning’s picture

Ok ill spend a bit more time on this later, anyone else who wants to join in feel free.

teunis’s picture

I'm not entirely sure what it's supposed to do, but I've folded some of the old form into services/authentication form on http://drupal.org/node/1336974#comment-5260612

So, pardon me for being out of the loop - but what is the intent with the above? (I'll gladly help if I understood what it's supposed to do)

kylebrowning’s picture

Basically, it adds rich settings/options to each Resource Method on the REsources page and allows other mothers like oauth to hook into these.

kylebrowning’s picture

Ok boys heres a newly updating patch. AGain this does NOT actually work, it just adds the forms back in.

kylebrowning’s picture

Status: Needs work » Needs review
kylebrowning’s picture

Status: Needs review » Needs work
kylebrowning’s picture

Ok heres a new patch.

This should fix everything and bring it home. Services_oauth still needs work but thats a separate issue.

marcingy’s picture

This is just a code review not an actual test...

function services_get_resource_operation_info($resource, $class, $name = NULL) {
+  $op = NULL;
+  $classes = array(
+    'actions'          => t('Action'),
+    'targeted_actions' => t('Targeted Action'),
+    'relationships'    => t('Relationship'),
+  );
+  if (isset($resource[$class])) {
+    $op = $resource[$class];
+    if (!empty($name)) {
+      $op = isset($op[$name]) ? $op[$name] : NULL;
+    }
+  }
+
+  return $op;
+}

The $classes array is not actually used and wondering if this easier to read

function services_get_resource_operation_info($resource, $class, $name = NULL) {
+  $op = isset($resource[$class]) ? $resource[$class] : NULL;
+  if (!empty($op) && !empty($name)) {
+    $op = isset($op[$name]) ? $op[$name] : NULL;
+  }
+
+  return $op;
+}

This can also be simplified

if (isset($rop['help'])) {
+      $description = $rop['help'];
+    }
+    else {
+      $description = t('No description is available');
+    }

to

$description = isset($rop['help']) ? $rop['help'] : t('No description is available');

Extra line that is not needed

+        //$settings_form['#tree'] = TRUE;
marcingy’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
ygerasimov’s picture

Here is simply rerolled patch of #23. I hold on my testing until Hugo finishes refactoring.

Hugo Wetterberg’s picture

I've kicked off a feature branch instead of doing all this incessant re-rolling: http://drupalcode.org/project/services.git/shortlog/refs/heads/feature/r...

Hugo Wetterberg’s picture

Component: User interface » Code
FileSize
96.67 KB

The current state of feature/rich-options-for-resources. Changing component from "User interface" to "Code" as the scope has changed a bit, one could argue that (re)adding configuration options to controllers was beyond the scope of "User interface" to begin with. Instead of normalizing the resource definitions on the fly for the admin the resource definition format has been updated to be consistent both with the endpoint format and between all operation classes.

http://drupalcode.org/project/services.git/commit/70916426aafca7fcf52f6b...

Updated resource definition format and added versioning of the format for automatic upgrades of old declarations.

The RPC translation layer and the REST server have been updated to work with the new format. The RPC translation functions also logs errors when there are naming collisions between operations in different classes.

Added proper default value handling for the auth module settings.

Updated documentation for hook_services_resources().

Updated documentation for hook_services_authentication_info() with the new properties. It's still somewhat lacking though.

kylebrowning’s picture

Status: Needs work » Needs review
FileSize
98.29 KB

heres an updated patch.

kylebrowning’s picture

Status: Needs review » Needs work
kylebrowning’s picture

Status: Needs work » Needs review
kylebrowning’s picture

Re-queue testing.

Status: Needs review » Needs work

The last submitted patch, 0001-readd-auth-settings-per-endpoint.patch, failed testing.

kylebrowning’s picture

Status: Needs work » Needs review
FileSize
106.17 KB

Lets try this one DRUPAL!

Status: Needs review » Needs work

The last submitted patch, 0001-readd-support-settings-per-auth.patch, failed testing.

kylebrowning’s picture

Status: Needs work » Needs review
FileSize
108.6 KB

Alrighty trying this one more time.

kylebrowning’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Assigned: kylebrowning » cotto
Status: Needs review » Patch (to be ported)
cotto’s picture

As part of the backport to 6.x-3.x (which is in progress), I'd like to change '#api_version' to remove the octothorpe. It's the only key in the resource array that has a leading octothorpe, and I don't see any reason for the inconsistency. Since there hasn't been a release with this patch, hopefully this change can happen without breaking anything important.

Hugo Wetterberg’s picture

Do not mistake the recent #-purge in services for a ban on hash signs. The old hashes were removed because they didn't have any function, they were simply there because the services API mimicked the menu API. The hash you want to remove now does, however, have a semantic function. It separates the attribute api_version from its siblings that are arbitrarily named elemements representing resources. Without the hash sign we would have to add the restriction that resources cannot be named api_version; or we'd have to add another level to our data structure where resources are nested under a "resources" element. The first solution lacks elegance and is potentially backwards incompatible. The second solution would be hard to make backwards compatible and really qualifies as an ugly structure in my eyes.

So, keep the semantic meaning of the # in mind: it separates the attributes of an element from its child elements. If there's no need for such a separation we shouldn't go around adding hashes willy nilly (as was previously done). Neither should you reflexively remove hashes when you encounter them, as some kind of coding style review.

kylebrowning’s picture

Status: Patch (to be ported) » Needs review
FileSize
105.9 KB

here you go, a 6.x version.

kylebrowning’s picture

Status: Needs review » Fixed
ygerasimov’s picture

Wow! Thanks Kyle!

kylebrowning’s picture

yeah big patches, now to get versions in core so we can start making changes to resources!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

bojanz’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Closed (fixed) » Needs work

Unfortunately, the code doesn't work, resource options aren't passed to the authenticate_call callback. You only get the general, endpoint settings.
You can easily confirm this with the current OAuth integration, set "authorization" to "" and "credentials" to "token" in the endpoint settings.
Then, for the current resource, set "authorization" to "basic" (or some other authorization level) and "credentials" to "consumer".
In the authenticate_call (_services_oauth_authenticate_call), you will only get access to the endpoint settings.

I tried to patch this, but couldn't find a clean way of fetching what I need from the $endpoint object in _services_authenticate_user().

bojanz’s picture

Status: Needs work » Needs review
FileSize
2.97 KB

Here's a patch.

Status: Needs review » Needs work

The last submitted patch, 1154420-fix-controller-settings-46.patch, failed testing.

bojanz’s picture

Status: Needs work » Needs review
FileSize
2.86 KB

Rerolled.

Ignore it, it's broken.

Assigned: cotto » Unassigned

The last submitted patch, 1154420-fix-controller-settings-48.patch, failed testing.

Anonymous’s picture

I've re-rolled this patch, and it seems to apply to the current dev.

Please can someone check this through? It should work with both Services OAuth and OAuth2 Server.

Anonymous’s picture

There was an error with the last patch, it was not checking to see if operation-specific settings had been applied to the resource and caused test failures.

This one should pass all tests.

zhangx1a0’s picture

works for me - thanks!

kylebrowning’s picture

Status: Needs review » Needs work
kylebrowning’s picture

Status: Needs work » Needs review
kylebrowning’s picture

RE-upload of patch.

Status: Needs review » Needs work

The last submitted patch, fix_controller_settings-1154420-51.patch, failed testing.

Jaypan’s picture

Is this patch safe to use? It's not passing testing.

Jaypan’s picture

Status: Needs work » Needs review
bojanz’s picture

We have it in production.

Status: Needs review » Needs work

The last submitted patch, 55: fix_controller_settings-1154420-51.patch, failed testing.

dashohoxha’s picture

I am using this patch (https://drupal.org/node/1154420#comment-7842205) and it works very well. Damn the automatic testers, they are not always right, sometimes they may need to be fixed themselves. I think that this patch should be applied.

dashohoxha’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community
kylebrowning’s picture

Status: Reviewed & tested by the community » Needs work

These two errors fail locally with the exact same result as the test bot.

dashohoxha’s picture

How come that I have applied the patch and everything seems to work fine?
I did not blame the bot, I blamed the tests that are giving these errors.

kylebrowning’s picture

You can login, and log out again, using standard session authentication? Thats what appears to be breaking in the bot.

dashohoxha’s picture

First, I have applied the patch against the latest stable version (7.x-3.5), this issue is filed against the 7.x-3.x-dev.

Second, I am using this module (services) to define my own (custom) web resources. I neither need nor use the 'user' resource. For that matter, I don't need or use the other predefined resources as well. So, as far as I am concerned, it is not a problem for me if 'user/logout' resource does not work.

In my opinion, predefined resources should belong to a separate, optional module, because not everybody needs them.

kylebrowning’s picture

We have a ticket for that. but just because it doesn't break for you doesn't mean it works.

Give us time to make sure it all works before we just commit it.

Ill try and figurer out whats going on tomorrow.

dashohoxha’s picture

There is no hurry, I am using it as a patch. But just it should not be pending forever.

marcingy’s picture

@dashohoxha if you want this patch committing help fix the test because unless the tests are fixed the patch will never be committed :( And even if the resources were in a module this would still be the case.

dashohoxha’s picture

@marcingly I am not a maintainer of 'services', I am not a maintainer of 'oauth2_server', I am not the author of the patch, why is it me that should fix the tests? It would take me too much time and I have already spent too much time to fix modules that do not work. I tried to help by giving my testimony that I am using it and in my experience everything is working well. Did you try to use this patch and did it create any problems for you?

So, I find your challenge unjust and dishonest. I may try to fix the tests, but not before you give up being a maintainer of 'services'.

kylebrowning’s picture

dashohoxha, Im already working on it, but it very well may be that the tests are accurate.

Lets move the topic of conversation back to the patch and fixes, rather who should fix what.

I appreciate any time and input you have going forward dashohoxha

kylebrowning’s picture

Heres an updated patch, I hope everyone who's uses it can test as I had to add an if(is array())

There error in question when using regular services authentication is....
<b>Fatal error</b>: Unsupported operand types in <b>/Users/kyle.browning/Sites/d7/sites/all/modules/services/includes/services.runtime.inc</b> on line <b>418</b><br />

This patch address that, and all tests seem to pass now.

Can we verify the settings still work?

dashohoxha’s picture

kylebrowning, thanks for fixing it and for your constructive comments.

I have applied the latest patch to 7.x-3.5 and so far everything seems OK.
I think that a positive review from bojanz will definitely validate it, since I don't really understand what this patch does. I am just interested in using services with oauth2_server. Thanks again for being responsive.

kylebrowning’s picture

Status: Needs review » Fixed
garphy’s picture

bojanz’s picture

Thanks kylebrowning, works nicely.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.