Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
---
version: "6.1.1"
version: "6.2.0"
changelog:
- date: 2026-10-21
version: v6.2.0
changes:
- type: feature
text: "Add `categories` support to `grant` and `grant_token` for granting enumeration (`get`) permission on all `channels` and `uuids` metadata."
- date: 2026-07-21
version: v6.1.1
changes:
Expand Down Expand Up @@ -656,7 +661,7 @@ sdks:
- x86-64
- distribution-type: package
distribution-repository: RubyGems
package-name: pubnub-6.1.1.gem
package-name: pubnub-6.2.0.gem
location: https://rubygems.org/gems/pubnub
requires:
- name: addressable
Expand Down Expand Up @@ -761,8 +766,8 @@ sdks:
- x86-64
- distribution-type: library
distribution-repository: GitHub release
package-name: pubnub-6.1.1.gem
location: https://github.com/pubnub/ruby/releases/download/v6.1.1/pubnub-6.1.1.gem
package-name: pubnub-6.2.0.gem
location: https://github.com/pubnub/ruby/releases/download/v6.2.0/pubnub-6.2.0.gem
requires:
- name: addressable
min-version: 2.0.0
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v6.2.0
October 21 2026

#### Added
- Add `categories` support to `grant` and `grant_token` for granting enumeration (`get`) permission on all `channels` and `uuids` metadata.

## v6.1.1
July 21 2026

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
pubnub (6.1.1)
pubnub (6.2.0)
addressable (>= 2.0.0)
base64
concurrent-ruby (~> 1.3.4)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.1.1
6.2.0
114 changes: 114 additions & 0 deletions fixtures/vcr_cassettes/lib/events/grant-categories.yml

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

126 changes: 126 additions & 0 deletions fixtures/vcr_cassettes/lib/events/grant-token-categories.yml

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

22 changes: 18 additions & 4 deletions lib/pubnub/events/grant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Grant < PAM

def initialize(options, app)
@event = current_operation
@categories = format_categories(options[:categories])
super
@uuids = Formatter::format_uuid(options[:uuids]) unless options[:uuids].nil?
@ttl ||= Pubnub::Constants::DEFAULT_TTL
Expand All @@ -18,10 +19,22 @@ def current_operation
Pubnub::Constants::OPERATION_GRANT
end

def format_categories(categories)
formatted = case categories
when NilClass then return nil
when Array then categories.map { |category| category.to_s.strip }
when String, Symbol then categories.to_s.split(',').map(&:strip)
else return categories
end

formatted.empty? ? nil : formatted
end

def parameters(signature = false)
write = [0, '0', false].include?(@write) ? 0 : 1
read = [0, '0', false].include?(@read) ? 0 : 1
manage = [0, '0', false].include?(@manage) ? 0 : 1 # unless @group.blank?
category_grant = !@categories.nil?
write = (category_grant && @write.nil?) || [0, '0', false].include?(@write) ? 0 : 1
read = (category_grant && @read.nil?) || [0, '0', false].include?(@read) ? 0 : 1
manage = (category_grant && @manage.nil?) || [0, '0', false].include?(@manage) ? 0 : 1 # unless @group.blank?
delete = [0, '0', false].include?(@delete) ? 0 : 1 unless @delete.nil?
get = [0, '0', false].include?(@get) ? 0 : 1 unless @get.nil?
update = [0, '0', false].include?(@update) ? 0 : 1 unless @update.nil?
Expand All @@ -35,7 +48,8 @@ def parameters(signature = false)
g: get,
u: update,
j: join,
ttl: @ttl }.delete_if { |_k, v| v.nil? }.merge(super(signature))
ttl: @ttl,
category: (@categories.join(',') unless @categories.nil?) }.delete_if { |_k, v| v.nil? }.merge(super(signature))
end

def path
Expand Down
17 changes: 16 additions & 1 deletion lib/pubnub/events/grant_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def initialize(options, app)
options[:channel_groups] = options[:channel_groups] || {}
@spaces_permissions = options[:spaces_permissions] || {}
@users_permissions = options[:users_permissions] || {}
@categories = options[:categories] || {}
super
end

Expand All @@ -31,7 +32,8 @@ def fire
meta: @meta,
uuid: uuid,
resources: prepare_permissions(:resource, @channels, @channel_groups, @uuids, @spaces_permissions, @users_permissions),
patterns: prepare_permissions(:pattern, @channels, @channel_groups, @uuids, @spaces_permissions, @users_permissions)
patterns: prepare_permissions(:pattern, @channels, @channel_groups, @uuids, @spaces_permissions, @users_permissions),
categories: prepare_categories(@categories)
}.select { |_, v| v }
}
body = Formatter.format_message(raw_body, nil, false)
Expand Down Expand Up @@ -70,6 +72,12 @@ def prepare_single_permissions(type, resources)
.to_h { |k, v| [k, v.calculate_bitmask] }
end

def prepare_categories(categories)
return nil if categories.empty?

categories.to_h { |k, v| [k.to_s, v.calculate_bitmask] }
end

def valid_envelope(parsed_response, req_res_objects)
Pubnub::Envelope.new(
event: @event,
Expand Down Expand Up @@ -146,6 +154,13 @@ def res(read: false, write: false, manage: false, delete: false, create: false,
join: join
)
end

def cat(get: false)
Permissions.new(
type: :category,
get: get
)
end
end

def initialize(options)
Expand Down
Loading
Loading