QuickBlox / quickblox-ios-sdk

QuickBlox iOS SDK for messaging and video calling
https://quickblox.com/developers/IOS
MIT License
397 stars 358 forks source link

Updating a custom object failed #879

Closed kuangzq closed 7 years ago

kuangzq commented 7 years ago

Hi there,

I was trying to update the value of a field for a custom object but it was always returning a failure by "You don't have appropriate permissions to do this operation". I checked up my code and added

qbcoCustomObject.permissions.deleteAccess = QBCOPermissionsAccessOpen;
qbcoCustomObject.permissions.updateAccess = QBCOPermissionsAccessOpen;

when creating the object but it still refuses to update by returning the same permission error message.

The snippet of my creating and updating the custom object is like following.

// create
QBCOCustomObject *qbcoCustomObject = [QBCOCustomObject customObject];
qbcoCustomObject.permissions.deleteAccess = QBCOPermissionsAccessOpen;
qbcoCustomObject.permissions.updateAccess = QBCOPermissionsAccessOpen;
qbcoCustomObject.className = MY_CUSTOM_CLASS;
// (populate qbcoCustomObject.fields ...)
[QBRequest createObject:qbcoCustomObject successBlock:^(QBResponse *response, QBCOCustomObject *object) {
    // success_callback(...);
} errorBlock:^(QBResponse *response) {
    // failure_callback(...);
}];
// update
QBCOCustomObject *qbcoCustomObject = [QBCOCustomObject customObject];
qbcoCustomObject.className = MY_CUSTOM_CLASS;
qbcoCustomObject.ID = sID;
// (populate the qbcoCustomObject.fields to be updated)
[QBRequest updateObject:qbcoCustomObject successBlock:^(QBResponse *response, QBCOCustomObject *object) {
    // success_callback(...);
} errorBlock:^(QBResponse *response) {
    // failure_callback(...);
}];

New Issue Checklist

Environment details

Info Value
iOS Version e.g. 10.3.3
Quickblox iOS SDK version e.g. 2.9.2
QuickbloxWebRTC SDK version N/A
Xcode Version e.g. Xcode 9.0
Repro with our demo sample N/A

Did this work before? No.

Expected behavior The custom object shall be updated.

Actual behavior The custom object was not updated and an error message of "You don't have appropriate permissions to do this operation" was returned.

Logs

Please use the following template for logs:

QBResponse by errorBlock of [QBRequest updateObject:...] ```logos 2017-10-02 06:05:00.811702-0600 App[6284:2291092] [QBCore] Request URL:https://api.quickblox.com/data/MY_CUSTOM_CLASS/59cf9431f2ba08d8a0eb477d.json 2017-10-02 06:05:00.812090-0600 App[6284:2291092] [QBCore] Request method: PUT 2017-10-02 06:05:00.812328-0600 App[6284:2291092] [QBCore] Request parameters:{ confirmed = 1; } 2017-10-02 06:05:00.812795-0600 App[6284:2291092] [QBCore] Request headers: { "Accept-Language" = "en-CA;q=1, zh-Hans-CA;q=0.9, en;q=0.8, en-US;q=0.7"; "Content-Type" = "application/x-www-form-urlencoded"; "QB-OS" = "iOS 10.3.3"; "QB-SDK" = "iOS 2.9.2"; "QB-Token" = ...; "QuickBlox-REST-API-Version" = "0.1.1"; "User-Agent" = "App/2.0 (iPhone; iOS 10.3.3; Scale/2.00)"; } 2017-10-02 06:05:01.037442-0600 App[6284:2291092] [QBCore] Response error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: forbidden (403)" UserInfo={com.alamofire.serialization.response.error.response= { URL: https://api.quickblox.com/data/MY_CUSTOM_CLASS/59cf9431f2ba08d8a0eb477d.json } { status code: 403, headers { "Access-Control-Allow-Origin" = "*"; "Cache-Control" = "no-cache"; Connection = "keep-alive"; "Content-Length" = 74; "Content-Type" = "application/json; charset=utf-8"; Date = "Mon, 02 Oct 2017 12:05:00 GMT"; "QB-Token-ExpirationDate" = "2017-10-02 14:03:50 +0000"; "QuickBlox-REST-API-Version" = "0.1.1"; Server = "openresty/1.9.15.1"; "Set-Cookie" = "_mkra_ctxt=3b35e10721d6e99b866ee4674c2fe7c3--403; path=/; max-age=5; HttpOnly; secure"; Status = "403 Forbidden"; "Strict-Transport-Security" = "max-age=31536000"; "X-Content-Type-Options" = nosniff; "X-Frame-Options" = SAMEORIGIN; "X-Request-Id" = "5814d8ac-aadf-45ff-aa63-a6366a874142"; "X-Runtime" = "0.023299"; "X-XSS-Protection" = "1; mode=block"; } }, NSErrorFailingURLKey=https://api.quickblox.com/data/MY_CUSTOM_CLASS/59cf9431f2ba08d8a0eb477d.json, com.alamofire.serialization.response.error.data=<7b226572 726f7273 223a5b22 596f7520 646f6e27 74206861 76652061 7070726f 70726961 74652070 65726d69 7373696f 6e732074 6f20646f 20746869 73206f70 65726174 696f6e22 5d7d>, NSLocalizedDescription=Request failed: forbidden (403)} 2017-10-02 06:05:01.038780-0600 App[6284:2291092] [QBCore] Response error reasons: { errors = ( "You don't have appropriate permissions to do this operation" ); } ```

To enable full logs use the following code:

[QBSettings setLogLevel:QBLogLevelDebug];
[QBSettings enableXMPPLogging];

Steps to reproduce the behavior (1) Create a custom object according to the "// create" snippet above (2) Update the same object just created according to the "// update" snippet above

Any others comments No

ghost commented 7 years ago

Hi @kuangzq, Could you please provide logs for create / update object?

Thanks.

kuangzq commented 7 years ago

Hi there, @Pro100Andrey

I figured out finally that I did not turn on the update permission for the custom class. My bad. Sorry. Please close this issue.

Thanks.

P. S. For other people's reference, steps to turn on update permission is as follows. (1) Access your app administration at https://admin.quickblox.com/ (2) Select your custom class on Custom page (3) There is a light blue button "Edit permission" beside "Add" and "Remove" buttons on top-right of the screen, click on it (4) On the pop-up window, set "Permission level" to "Open" for the actions needed (e.g. delete and/or update) and don't forget to check the corresponding "Use class permissions"