mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-22 21:41:37 +00:00
Properly handle changing and removing permissions
This commit is contained in:
parent
955b143ced
commit
d1d70521a3
3 changed files with 73 additions and 23 deletions
|
|
@ -64,6 +64,20 @@ local PermissionsPage = Roact.Component:extend("PermissionsPage")
|
||||||
|
|
||||||
function PermissionsPage:init()
|
function PermissionsPage:init()
|
||||||
self.contentSize, self.setContentSize = Roact.createBinding(Vector2.new(0, 0))
|
self.contentSize, self.setContentSize = Roact.createBinding(Vector2.new(0, 0))
|
||||||
|
|
||||||
|
self:setState({
|
||||||
|
permissions = self.props.headlessAPI._permissions,
|
||||||
|
})
|
||||||
|
|
||||||
|
self.changedListener = self.props.headlessAPI._permissionsChanged:Connect(function()
|
||||||
|
self:setState({
|
||||||
|
permissions = self.props.headlessAPI._permissions,
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function PermissionsPage:willUnmount()
|
||||||
|
self.changedListener:Disconnect()
|
||||||
end
|
end
|
||||||
|
|
||||||
function PermissionsPage:render()
|
function PermissionsPage:render()
|
||||||
|
|
@ -71,7 +85,7 @@ function PermissionsPage:render()
|
||||||
theme = theme.Settings
|
theme = theme.Settings
|
||||||
|
|
||||||
local sources = {}
|
local sources = {}
|
||||||
if next(self.props.headlessAPI._permissions) == nil then
|
if next(self.state.permissions) == nil then
|
||||||
sources.noSources = e("TextLabel", {
|
sources.noSources = e("TextLabel", {
|
||||||
Text = "No third-party plugins have been granted permissions.",
|
Text = "No third-party plugins have been granted permissions.",
|
||||||
Font = Enum.Font.Gotham,
|
Font = Enum.Font.Gotham,
|
||||||
|
|
@ -86,7 +100,11 @@ function PermissionsPage:render()
|
||||||
BackgroundTransparency = 1,
|
BackgroundTransparency = 1,
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
for source in self.props.headlessAPI._permissions do
|
for source, permissions in self.state.permissions do
|
||||||
|
if next(permissions) == nil then
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
|
||||||
local meta = self.props.headlessAPI:_getMetaFromSource(source)
|
local meta = self.props.headlessAPI:_getMetaFromSource(source)
|
||||||
sources[source] = e(Listing, {
|
sources[source] = e(Listing, {
|
||||||
layoutOrder = string.byte(source),
|
layoutOrder = string.byte(source),
|
||||||
|
|
|
||||||
|
|
@ -851,17 +851,19 @@ function App:render()
|
||||||
end,
|
end,
|
||||||
|
|
||||||
onEdit = function(plugin, source, meta, apiMap)
|
onEdit = function(plugin, source, meta, apiMap)
|
||||||
|
local name = meta.Name .. if meta.Creator then " by " .. meta.Creator else ""
|
||||||
local apiList = {}
|
local apiList = {}
|
||||||
for api in apiMap do
|
for api in apiMap do
|
||||||
table.insert(apiList, api)
|
table.insert(apiList, api)
|
||||||
end
|
end
|
||||||
self:requestPermission(
|
local response = self:requestPermission(
|
||||||
plugin,
|
plugin,
|
||||||
source,
|
source,
|
||||||
meta.Name .. if meta.Creator then " by " .. meta.Creator else "",
|
name,
|
||||||
apiList,
|
apiList,
|
||||||
apiMap
|
apiMap
|
||||||
)
|
)
|
||||||
|
self.headlessAPI:_setPermissions(source, name, response)
|
||||||
end,
|
end,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -152,17 +152,6 @@ function API.new(app)
|
||||||
return "CommandBar"
|
return "CommandBar"
|
||||||
end
|
end
|
||||||
|
|
||||||
function Rojo:_permissionCheck(key: string): boolean
|
|
||||||
if apiPermissionAllowlist[key] then return true end
|
|
||||||
|
|
||||||
local source = Rojo:_getCallerSource()
|
|
||||||
if Rojo._permissions[source] == nil then
|
|
||||||
Rojo._permissions[source] = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
return not not Rojo._permissions[source][key]
|
|
||||||
end
|
|
||||||
|
|
||||||
local BUCKET, LIMIT = 10, 15
|
local BUCKET, LIMIT = 10, 15
|
||||||
function Rojo:_checkRateLimit(api: string): boolean
|
function Rojo:_checkRateLimit(api: string): boolean
|
||||||
local source = Rojo:_getCallerSource()
|
local source = Rojo:_getCallerSource()
|
||||||
|
|
@ -189,6 +178,54 @@ function API.new(app)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Rojo._permissionsChangedEvent = Instance.new("BindableEvent")
|
||||||
|
Rojo._permissionsChanged = Rojo._permissionsChangedEvent.Event
|
||||||
|
|
||||||
|
function Rojo:_permissionCheck(key: string): boolean
|
||||||
|
if apiPermissionAllowlist[key] then return true end
|
||||||
|
|
||||||
|
local source = Rojo:_getCallerSource()
|
||||||
|
if Rojo._permissions[source] == nil then
|
||||||
|
Rojo._permissions[source] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
return not not Rojo._permissions[source][key]
|
||||||
|
end
|
||||||
|
|
||||||
|
function Rojo:_setPermissions(source, name, permissions)
|
||||||
|
-- Ensure permissions exist for this source
|
||||||
|
if Rojo._permissions[source] == nil then
|
||||||
|
Rojo._permissions[source] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Set permissions
|
||||||
|
for api, granted in permissions do
|
||||||
|
Log.warn(string.format(
|
||||||
|
"%s Rojo.%s for '%s'",
|
||||||
|
granted and "Granting permission to" or "Denying permission to", api, name
|
||||||
|
))
|
||||||
|
Rojo._permissions[source][api] = granted
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Clear out source if no permissions are granted
|
||||||
|
local hasAnyPermissions = false
|
||||||
|
for _, granted in Rojo._permissions[source] do
|
||||||
|
if granted then
|
||||||
|
hasAnyPermissions = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not hasAnyPermissions then
|
||||||
|
Rojo._permissions[source] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Update stored permissions
|
||||||
|
Settings:set("apiPermissions", Rojo._permissions)
|
||||||
|
|
||||||
|
-- Share changes
|
||||||
|
Rojo._permissionsChangedEvent:Fire(source, Rojo._permissions[source])
|
||||||
|
end
|
||||||
|
|
||||||
Rojo._apiDescriptions.RequestAccess = "Used to gain access to Rojo API members"
|
Rojo._apiDescriptions.RequestAccess = "Used to gain access to Rojo API members"
|
||||||
function Rojo:RequestAccess(plugin: Plugin, apis: {string}): {[string]: boolean}
|
function Rojo:RequestAccess(plugin: Plugin, apis: {string}): {[string]: boolean}
|
||||||
assert(type(apis) == "table", "Rojo:RequestAccess expects an array of valid API names as the second argument")
|
assert(type(apis) == "table", "Rojo:RequestAccess expects an array of valid API names as the second argument")
|
||||||
|
|
@ -245,14 +282,7 @@ function API.new(app)
|
||||||
|
|
||||||
local response = app:requestPermission(plugin, source, name, sanitizedApis, Rojo._permissions[source])
|
local response = app:requestPermission(plugin, source, name, sanitizedApis, Rojo._permissions[source])
|
||||||
|
|
||||||
for api, granted in response do
|
Rojo:_setPermissions(source, name, response)
|
||||||
Log.warn(string.format(
|
|
||||||
"%s Rojo.%s for '%s'",
|
|
||||||
granted and "Granting permission to" or "Denying permission to", api, name
|
|
||||||
))
|
|
||||||
Rojo._permissions[source][api] = granted
|
|
||||||
end
|
|
||||||
Settings:set("apiPermissions", Rojo._permissions)
|
|
||||||
|
|
||||||
Rojo._activePermissionRequests[source] = nil
|
Rojo._activePermissionRequests[source] = nil
|
||||||
return response
|
return response
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue