Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

NOISSUE - Fix Update user roles, Listing and retrieve users with role #76

Merged
merged 5 commits into from
Nov 29, 2023

Conversation

arvindh123
Copy link
Contributor

@arvindh123 arvindh123 commented Nov 23, 2023

Pull request title should be MG-XXX - description or NOISSUE - description where XXX is ID of issue that this PR relate to.
Please review the CONTRIBUTING.md file for detailed contributing guidelines.

What does this do?

  • Fix : Update user role and Listing and retrieve users with role

Update user role to admin

Request:

curl --location --request PATCH 'http://localhost/users/28cea756-f23b-408d-ab7a-43bf6f3c20cd/role' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data '{
  "role": "admin"
}'

Response:

{
    "id": "28cea756-f23b-408d-ab7a-43bf6f3c20cd",
    "credentials": {
        "identity": "[email protected]"
    },
    "created_at": "2023-11-23T09:03:11.411868Z",
    "updated_at": "2023-11-23T16:35:17.597552Z",
    "updated_by": "8cadfa56-e513-4dd8-b746-073348432054",
    "role": "admin"
}

Listing of users

Request :

curl --location 'http://localhost/users' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <TOKEN>'

Response :

{
    "limit": 10,
    "total": 3,
    "users": [
        {
            "id": "8cadfa56-e513-4dd8-b746-073348432054",
            "name": "admin",
            "credentials": {
                "identity": "[email protected]"
            },
            "metadata": {
                "role": "admin"
            },
            "created_at": "2023-11-23T08:56:44.364784Z",
            "updated_at": "0001-01-01T00:00:00Z",
            "role": "admin"
        },
        {
            "id": "28cea756-f23b-408d-ab7a-43bf6f3c20cd",
            "credentials": {
                "identity": "[email protected]"
            },
            "created_at": "2023-11-23T09:03:11.411868Z",
            "updated_at": "2023-11-23T16:35:17.597552Z",
            "updated_by": "8cadfa56-e513-4dd8-b746-073348432054",
            "role": "admin"
        },
        {
            "id": "aaef1e86-3968-4336-89e9-5b2d01bc416c",
            "credentials": {
                "identity": "[email protected]"
            },
            "created_at": "2023-11-23T09:03:52.378677Z",
            "updated_at": "0001-01-01T00:00:00Z"
        }
    ]
}

Which issue(s) does this PR fix/relate to?

Put here Resolves #XXX to auto-close the issue that your PR fixes (if such)

List any changes that modify/break current functionality

Have you included tests for your changes?

Did you document any new/modified functionality?

Notes

@arvindh123 arvindh123 marked this pull request as draft November 23, 2023 16:53
@arvindh123 arvindh123 marked this pull request as ready for review November 23, 2023 17:09
@@ -1658,13 +1656,13 @@ components:
schema:
$ref: "#/components/schemas/UserSecret"

UserUpdateOwnerReq:
UserUpdateRoleReq:
description: JSON-formated document describing the owner of user to be update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: JSON-formated document describing the owner of user to be update
description: JSON-formated document describing the role of the user to be update

@ianmuchyri
Copy link
Contributor

Update the sdk function to replace updateOwner with UpdateRole https://github.com/absmach/magistrala/blob/f6cf7e0d6bed58120a5ea5234d4b7e183aeae39e/pkg/sdk/go/users.go#L251C1-L271C1

Copy link
Contributor

@ianmuchyri ianmuchyri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In sdk.go change UpdateUserOwner to UpdateUserRole

UserUpdateOwnerReq:
description: JSON-formated document describing the owner of user to be update
UserUpdateRoleReq:
description: JSON-formated document describing the role of the user to be update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: JSON-formated document describing the role of the user to be update
description: JSON-formated document describing the role of the user to be updated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arvindh123 Please address this one.

@ianmuchyri
Copy link
Contributor

In sdk.go change UpdateUserOwner to UpdateUserRole

also update in users_tests.go

@arvindh123 arvindh123 force-pushed the domains_fix_user_role branch 2 times, most recently from 7ef2686 to fd1224f Compare November 29, 2023 10:34
@arvindh123
Copy link
Contributor Author

arvindh123 commented Nov 29, 2023

In sdk.go change UpdateUserOwner to UpdateUserRole

also update in users_tests.go

Fixed in https://github.com/absmach/magistrala/pull/49

@arvindh123 arvindh123 force-pushed the domains_fix_user_role branch from fd1224f to 77805ae Compare November 29, 2023 11:56
Signed-off-by: Arvindh <[email protected]>
@dborovcanin dborovcanin merged commit 6f195f8 into absmach:main Nov 29, 2023
9 of 15 checks passed
@arvindh123 arvindh123 self-assigned this Dec 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants