Commit 12e98266 authored by serk's avatar serk Committed by Francesc Guasch
Browse files

docs: How to create a new grant (#1002)

docs(devel): How to create a new grant

* documentation about how grants system works and references about how to do a test for it.
* docs: add clarification about pci-stubs ( issue #742 )

issue  #996
parent 8f6ea938
How to create a new grants
========================
If you want to add a new grant, you have to do two things:
- Add the grant and enable it in to the BD
- Add the condition
You can see all the grants in the table 'grants_type', to add it automatically on start up the
backend you have to modify the functions ``_add_grants`` and `` _enable_grants`` in the file "lib/Ravada.pm"
Now the test file is like this:
::
...
sub _add_grants($self) {
# How to
# $self->_add_grant('grant_name', enable/disable by default, "description")
# Examples
$self->_add_grant('shutdown', 1,"Can shutdown own virtual machines");
$self->_add_grant('start_many',0,"Can have more than one machine started")
}
...
sub _enable_grants($self) {
...
my @grants = (
# How to
# 'grant_name'
# Examples
'change_settings', 'change_settings_all', 'change_settings_clones'
,'clone', 'clone_all', 'create_base', 'create_machine'
,'grant'
,'manage_users'
,'remove', 'remove_all', 'remove_clone', 'remove_clone_all'
,'screenshot'
,'shutdown', 'shutdown_all', 'shutdown_clone'
,'screenshot'
,'start_many'
);
...
Next for adding the conditions it depends of the situations but you may want to lock in to thins functions:
- "templates/main/settings_machine_tabs_head.html.ep" & "templates/main/settings_machine_tabs_head.html.ep" for Virtual Machine edit settings web page.
- "lib/Ravada/Auth/SQL.pm" all the grants conditions created (i.e. ``is_admin``, ``can_list_clones``, etc...).
**Note**:If the function is named ``can_'grant_name'`` this function is automatically generated with the BD data.
Testing
-------
Some examples for testing can be found in "/t/user/50_admin.t" and "/t/user/40_grant_shutdown.t" also you may want to read the section **How to create tests**.
......@@ -33,7 +33,8 @@ To enable SR-IOV in the kernel add any of these following options for pass-throu
GRUB_CMDLINE_LINUX_DEFAULT="radeon.blacklist=1 quiet splash amd_iommu=on pci-stub.ids=1002:6608,1002:aab0"
GRUB_CMDLINE_LINUX_DEFAULT="radeon.blacklist=1 amdgpu.blacklist=1 quiet splash intel_iommu=on amd_iommu=on iommu=pt rd.driver.pre=vfio-pci video=efifb:off pci-stub.ids=1028:2120,1028:aab0"
Add pci-stubs in ``/etc/initramfs-tools/modules``.
Add pci-stubs in ``/etc/initramfs-tools/modules``, just add this line: ``pci-stub ids=1002:6608,1002:aab0;``.
Then add these additional drivers to ``/etc/modules``:
::
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment