Skip to content

Commit

Permalink
add resource instances to assign role
Browse files Browse the repository at this point in the history
  • Loading branch information
RazcoDev committed Apr 3, 2024
1 parent a27d3d6 commit 6b01ac6
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 14 deletions.
7 changes: 5 additions & 2 deletions pkg/api/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,17 @@ func (u *Users) Delete(ctx context.Context, userKey string) error {

// AssignRole assigns a role to a user in your context's environment, by user key, role key and tenant key.
// Usage Example:
// `roleAssignment, err := PermitClient.Api.Users.AssignRole(ctx, "user-key", "role-key", "default")`
func (u *Users) AssignRole(ctx context.Context, userKey string, roleKey string, tenantKey string) (*models.RoleAssignmentRead, error) {
// `roleAssignment, err := PermitClient.Api.Users.AssignRole(ctx, "user-key", "role-key", "default", "document:mydoc")`
func (u *Users) AssignRole(ctx context.Context, userKey string, roleKey string, tenantKey string, resourceInstance *string) (*models.RoleAssignmentRead, error) {
err := u.lazyLoadPermitContext(ctx)
if err != nil {
u.logger.Error("", zap.Error(err))
return nil, err
}
userRoleCreate := *models.NewUserRoleCreate(roleKey, tenantKey)
if resourceInstance != nil {
userRoleCreate.SetResourceInstance(*resourceInstance)
}
roleAssignmentRead, httpRes, err := u.client.UsersApi.AssignRoleToUser(ctx, u.config.Context.GetProject(), u.config.Context.GetEnvironment(), userKey).UserRoleCreate(userRoleCreate).Execute()
err = errors.HttpErrorHandle(err, httpRes)
if err != nil {
Expand Down
100 changes: 93 additions & 7 deletions pkg/models/model_role_assignment_create.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 91 additions & 5 deletions pkg/models/model_user_role_create.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6b01ac6

Please sign in to comment.