{"id":15089212,"url":"https://github.com/dmstr/yii2-filefly-module","last_synced_at":"2025-04-08T04:17:56.912Z","repository":{"id":17602307,"uuid":"82327401","full_name":"dmstr/yii2-filefly-module","owner":"dmstr","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-06T07:54:22.000Z","size":249,"stargazers_count":9,"open_issues_count":7,"forks_count":8,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-24T09:28:10.496Z","etag":null,"topics":["api","filefly","rbac","yii2"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmstr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-17T18:44:12.000Z","updated_at":"2025-02-06T07:52:21.000Z","dependencies_parsed_at":"2024-06-19T09:56:01.361Z","dependency_job_id":"587d7aa6-6349-488f-8c63-d53c385b4ab8","html_url":"https://github.com/dmstr/yii2-filefly-module","commit_stats":{"total_commits":246,"total_committers":11,"mean_commits":"22.363636363636363","dds":"0.46341463414634143","last_synced_commit":"5cfde0dffd999a1401edfd66d0821cadb97d5219"},"previous_names":[],"tags_count":81,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmstr%2Fyii2-filefly-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmstr%2Fyii2-filefly-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmstr%2Fyii2-filefly-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmstr%2Fyii2-filefly-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmstr","download_url":"https://codeload.github.com/dmstr/yii2-filefly-module/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247773722,"owners_count":20993639,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","filefly","rbac","yii2"],"created_at":"2024-09-25T08:41:44.269Z","updated_at":"2025-04-08T04:17:56.860Z","avatar_url":"https://github.com/dmstr.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Yii2 FileFly Module\n=======\n\n[![Latest Stable Version](https://poser.pugx.org/dmstr/yii2-filefly-module/v/stable.svg)](https://packagist.org/packages/dmstr/yii2-filefly-module)\n[![Total Downloads](https://poser.pugx.org/dmstr/yii2-filefly-module/downloads.svg)](https://packagist.org/packages/dmstr/yii2-filefly-module)\n[![License](https://poser.pugx.org/dmstr/yii2-filefly-module/license.svg)](https://packagist.org/packages/dmstr/yii2-filefly-module)\n\nFlySystem API for [dmstr/yii2-filemanager-widgets](https://github.com/dmstr/yii2-filemanager-widgets)\n\nInstallation\n------------\n\n#### ENV variables\n\nVariable | Value | Required\n------------- | ------------- | -------------\nAFM_FILESYSTEM | yii component name | yes\nAFM_REPAIR | default: true | no\nAFM_SLUG_NAMES | default: true | no\nAFM_DELETE_RECURSIVE | default: false | no\n\ni.e. `AFM_FILESYSTEM=fsLocal`\n\n:question: How to configure a filesystem component [Filesystem docs](https://github.com/creocoder/yii2-flysystem/blob/master/README.md)\n\n#### Yii config\n\n```php\n'filefly' =\u003e [\n    'class'              =\u003e 'hrzg\\filefly\\Module',\n    'layout'             =\u003e '@backend/views/layouts/main',\n    'filesystem'         =\u003e getenv('AFM_FILESYSTEM'),\n    'slugNames'\t\t\t =\u003e (getenv('AFM_SLUG_NAMES')) ? getenv('AFM_SLUG_NAMES') : true,\n    'repair'             =\u003e (getenv('AFM_REPAIR')) ? getenv('AFM_REPAIR') : true,\n    'deleteRecursive'    =\u003e (getenv('AFM_DELETE_RECURSIVE')) ? getenv('AFM_DELETE_RECURSIVE') : false,\n    'streamExpireOffset' =\u003e 604800 # Offset (in seconds) for Expires Header in stream action\n    'defaultPermissions' =\u003e [\n        \\hrzg\\filefly\\Module::ACCESS_OWNER  =\u003e 1,\n        \\hrzg\\filefly\\Module::ACCESS_READ   =\u003e \\hrzg\\filefly\\models\\FileflyHashmap::$_all,\n        \\hrzg\\filefly\\Module::ACCESS_UPDATE =\u003e \\hrzg\\filefly\\models\\FileflyHashmap::$_all,\n        \\hrzg\\filefly\\Module::ACCESS_DELETE =\u003e \\hrzg\\filefly\\models\\FileflyHashmap::$_all,\n    ],\n    # the urlCallbck property can be used to provide customized urls for each file item which (if defined) will overwrite \n    # the default handler URLs\n    'urlCallback'        =\u003e function($item) {\n\t\t$urls = [];\n\t\t$isImageFileExtList = ['jpg', 'jpeg', 'gif', 'tiff', 'tif', 'svg', 'png', 'bmp'] ;\n\t\tif ($item['type'] === 'file') {\n\t\t\tif (in_array(strtolower($item['extension']), $isImageFileExtList)) {\n\t\t\t\t$urls['image url'] = \\dmstr\\willnorrisImageproxy\\Url::image($item['path']);\n\t\t\t}\n\t\t\telse {\n\t\t\t\t$urls['download url'] = implode('/', ['/img/download', ltrim($item['path'], '/')]) . ',p1';\n\t\t\t}\n\t\t}\n\t\treturn $urls;\n\t},\n\t// previewCallback can be used to overwrite the default downloadUrl for preview URLs within filemanagerApp\n\t'previewCallback' =\u003e function($item) {\n\t\t$isImageFileExtList = ['jpg', 'jpeg', 'gif', 'tiff', 'tif', 'png', 'bmp'] ;\n\t\tif ($item['type'] === 'file') {\n\t\t\tif (in_array(strtolower($item['extension']), $isImageFileExtList)) {\n\t\t\t\treturn \\dmstr\\willnorrisImageproxy\\Url::image($item['path'], '500x');\n\t\t\t}\n\t\t}\n\t\treturn '';\n\t}\n],\n```\n\n## RBAC\n\n**Prosa**\n- `FileflyAdmin` full module access including debug information\n- `FileflyDefault` management access (eg. POST request for upload, change, delete)\n- `FileflyPermissions` assigned users can set or unset roles or permissions which the user himself has assigned\n\n- `access_owner` permission before `access_read`, `access_update`, `access_delete`\n- If no permission is set, it will check if any inherited permission can be granted\n\nSo if inherited `access_*` permissions should be used, set defaultPermissions to `null` NOT to `'*'`.\n\n```\n            'defaultPermissions' =\u003e [\n                \\hrzg\\filefly\\Module::ACCESS_OWNER  =\u003e 1,\n                \\hrzg\\filefly\\Module::ACCESS_READ   =\u003e null,\n                \\hrzg\\filefly\\Module::ACCESS_UPDATE =\u003e null,\n                \\hrzg\\filefly\\Module::ACCESS_DELETE =\u003e null,\n            ],\n```\n\n**ActiveRecord: FileflyHashmap**\n- uses `dmstr\\activeRecordPermissions\\ActiveRecordAccessTrait` with `$activeAccessTrait = false`\n- access checks will be done for each permission type explicitly, `hasPermission($action)`\n- uses a `pathValidator` rule to ensure the `path` syntax on active record operations\n\n#### Roles\n\n- FileflyAdmin\n\t- filefly\n\n- FileflyDefault\n\t- filefly_default_index\n\n- FileflyApi\n\t- filefly_api_index\n\n- FileflyPermissions\n\n#### Permissions\n\n- filefly\n- filefly_default_index\n- filefly_api_index\n\n## RBAC Plugins\n\nPermission checks will ever come after file or folder operation\n\n**GrantPermission**\n```\nGranted or deny permission\n\n1. access field empty (is owner, true or continue)\n2. access field set (permission granted, true)\n   access field set (is access owner, true, permission denied, false)\n```\n\n**SetPermission**\n```\nCreate or update permission\n\n1. Add new hash records\n2. Update hash records (recursive option)\n\n- Multi create and update option\n```\n\n**RemovePermission**\n```\nRemove permission\n\n1. Deletes file or folder records\n\n- Multi delete option\n```\n\n## CLI\n\nConfigure\n\n    'controllerMap' =\u003e [\n        'fs' =\u003e [\n            'class' =\u003e '\\hrzg\\filefly\\commands\\FsController',\n            'filesystemComponents' =\u003e [\n                'local' =\u003e 'fs',\n                's3' =\u003e 'fsS3',\n                'storage' =\u003e 'fsFtp',\n            ],\n        ],\n    ]\n\n## Widget\n\nsee https://github.com/dmstr/yii2-filemanager-widgets\n\n```\n    {{ use ('hrzg/filemanager/widgets') }}\n    {{ file_manager_widget_widget(\n        {\n            \"handlerUrl\": \"/#{app.language}/filefly/api\"\n        }\n    ) }}\n```\n\nOptions for the yii2-filemanager-widgets Widget can be injected via the Module property `fileManagerWidgetOptions`\n\nexample:\n```php\n\n        'filefly' =\u003e [\n            'filesystemComponents' =\u003e [\n                'ftp' =\u003e 'fsFtp',\n                'ftpcrud' =\u003e 'fsFtpCrud',\n            ],\n            // ...\n            // other configs\n            // ...\n            // Options for the angular fileManagerWidget\n            'fileManagerWidgetOptions' =\u003e [\n                'searchForm' =\u003e false,\n                'allowedActions' =\u003e [\n                    'move' =\u003e false,\n                    'upload' =\u003e false,\n                    'createFolder' =\u003e false,\n                    ],\n            ],\n        ],\n```        \n\n### Controller action in iFrame\n\nModal button\n\n```\n\u003ca type=\"button\" data-toggle=\"modal\" data-target=\"#modal-filemanager\" id=\"filefly-iframe-toggle\"\u003e  \n    \u003ci class=\"fa fa-folder-open\"\u003e\u003c/i\u003e\n\u003c/a\u003e\n```\n\nLoad event listener\n\n```\n\u003cscript\u003e\n    window.addEventListener('load', function () {\n        var fileflyIframeToggle = document.querySelector('#filefly-iframe-toggle');\n        var iframe = document.querySelector('#filefly-iframe');\n        \n        fileflyIframeToggle.addEventListener('click', function () {\n            iframe.src = \"/filefly/default/filemanager-full-screen\";\n        });\n    });\n\u003c/script\u003e\n```\n\nIframe\n```\n{{ use ('yii/bootstrap') }}\n{{ modal_begin(    \n{        \n    'id': 'modal-filemanager',\n\t'size': 'modal-lg'    \n}) }}\n\n\u003ciframe id=\"filefly-iframe\"  width=\"100%\" height=\"100%\" frameborder=\"0\" src=\"\"\u003e\u003c/iframe\u003e\n\n{{ modal_end() }}'\n```\n\n## Helper\n\nDescription | Method call | Example output\n--- | --- | ---\nTotal size for all filesystems | `FileflyHashmap::getTotalSize()` | 202.82 MiB\nTotal size for all filesystems (raw bytes) | `FileflyHashmap::getTotalSize(true)` | 212670464\nTotal size for `local` filesystems | `FileflyHashmap::getTotalSize(false, 'local')` | 48.32 MiB\nTotal size for `s3` filesystems (raw bytes) | `FileflyHashmap::getTotalSize(true, 's3')` | 166546843\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmstr%2Fyii2-filefly-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmstr%2Fyii2-filefly-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmstr%2Fyii2-filefly-module/lists"}