From ab34bc6dfdeb80a47054a1283b64f03af00fd6c0 Mon Sep 17 00:00:00 2001 From: ewallah Date: Thu, 12 Nov 2020 14:27:37 +0100 Subject: [PATCH] Dev (#5) * version update * quiet docker * quiet docker * quiet docker * quiet docker * quiet docker * quiet docker --- .travis.yml | 14 +- db/access.php | 4 +- tests/behat/s3bucket.feature | 67 -------- tests/behat/s3bucket_course.feature | 88 +++++++++++ ...tances.feature => s3bucket_global.feature} | 41 +++-- tests/behat/s3bucket_user.feature | 147 ++++++++++++++++++ tests/other_test.php | 3 +- version.php | 2 +- 8 files changed, 268 insertions(+), 98 deletions(-) delete mode 100644 tests/behat/s3bucket.feature create mode 100644 tests/behat/s3bucket_course.feature rename tests/behat/{s3bucket_instances.feature => s3bucket_global.feature} (79%) create mode 100644 tests/behat/s3bucket_user.feature diff --git a/.travis.yml b/.travis.yml index e526d7d..bdcf120 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,7 @@ env: jobs: include: + #- env: DB=mysqli MOODLE_BRANCH=MOODLE_38_STABLE - env: DB=mysqli MOODLE_BRANCH=MOODLE_39_STABLE - env: DB=mysqli MOODLE_BRANCH=MOODLE_310_STABLE @@ -39,10 +40,8 @@ before_install: install: #- moodle-plugin-ci add-plugin --clone https://github.com/ewallah/moodle-local_aws.git - moodle-plugin-ci add-plugin --clone https://github.com/catalyst/moodle-local_aws.git - - moodle-plugin-ci install + - moodle-plugin-ci install -q - cd moodle - -script: - moodle-plugin-ci phplint - moodle-plugin-ci phpcpd - moodle-plugin-ci phpmd @@ -52,14 +51,17 @@ script: - moodle-plugin-ci savepoints - moodle-plugin-ci mustache - moodle-plugin-ci grunt + - moodle-plugin-ci behat -q --profile default blocks/admin_bookmarks + - moodle-plugin-ci behat -q --profile chrome blocks/admin_bookmarks + - vendor/bin/phpunit --testsuite core_privacy_testsuite,tool_dataprivacy_testsuite + +script: - moodle-plugin-ci phpunit --coverage-text --coverage-clover - - moodle-plugin-ci behat --profile chrome blocks/admin_bookmarks - moodle-plugin-ci behat - moodle-plugin-ci behat --profile chrome - - php admin/tool/behat/cli/init.php -a="classic" + - php admin/tool/behat/cli/init.php -a="classic" > /dev/null - moodle-plugin-ci behat --suite="classic" - moodle-plugin-ci behat --suite="classic" --profile chrome - - vendor/bin/phpunit --testsuite core_privacy_testsuite,tool_dataprivacy_testsuite > /dev/null after_success: - moodle-plugin-ci coveralls-upload diff --git a/db/access.php b/db/access.php index af25e55..203e161 100644 --- a/db/access.php +++ b/db/access.php @@ -26,9 +26,11 @@ defined('MOODLE_INTERNAL') || die(); $capabilities = [ - 'repository/s3bucket:view' => ['captype' => 'write', 'contextlevel' => CONTEXT_MODULE, + 'repository/s3bucket:view' => ['captype' => 'read', 'contextlevel' => CONTEXT_MODULE, 'archetypes' => ['editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW]], 'repository/s3bucket:addinstance' => ['captype' => 'write', 'contextlevel' => CONTEXT_SYSTEM, 'archetypes' => ['manager' => CAP_ALLOW]], + 'repository/s3bucket:addinstance' => ['captype' => 'write', 'contextlevel' => CONTEXT_USER, + 'archetypes' => ['editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW]], 'repository/s3bucket:addinstance' => ['captype' => 'write', 'contextlevel' => CONTEXT_COURSE, 'archetypes' => ['editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW]]]; diff --git a/tests/behat/s3bucket.feature b/tests/behat/s3bucket.feature deleted file mode 100644 index 37a9b3b..0000000 --- a/tests/behat/s3bucket.feature +++ /dev/null @@ -1,67 +0,0 @@ -@repository @repository_s3bucket @javascript -Feature: S3 bucket repository should throw no errors - An admin should be able to configure the plugin - - Background: - Given the following "courses" exist: - | fullname | shortname | category | - | Course 1 | C1 | 0 | - And the following "users" exist: - | username | email | firstname | lastname | - | student | s@example.com | Student | 1 | - | teacher | t@example.com | Teacher | 1 | - And the following "course enrolments" exist: - | user | course | role | - | student | C1 | student | - | teacher | C1 | editingteacher | - And I enable repository "s3bucket" - And I log in as "admin" - And I navigate to "Plugins > Repositories > Amazon S3 bucket" in site administration - And I click on "Create a repository instance" "button" - And I set the following fields to these values: - | name | Testrepo | - | bucket_name | Testbucket | - And I click on "Save" "button" - Then I should see "Required" - And I set the field "Access key" to "anoTherfake@1" - And I set the field "Secret key" to "anotherFake_$2" - And I click on "Save" "button" - And I click on "Allow users to add a repository instance into the course" "checkbox" - And I click on "Allow users to add a repository instance into the user context" "checkbox" - And I click on "Save" "button" - And I log out - - Scenario: An admin can add a user and course instances - When I log in as "admin" - And I navigate to "Plugins > Repositories > Manage repositories" in site administration - Then I should see "Amazon S3 bucket" - And I should see "1 Site-wide common instance(s)" - And I follow "Preferences" in the user menu - Then I should see "Repositories" - And I follow "Manage instances" - Then I should see "Amazon S3 bucket" - And I should see "Create" - And I am on "Course 1" course homepage with editing mode on - And I navigate to "Repositories" in current page administration - Then I should see "Amazon S3 bucket" - And I should see "Create" - - Scenario: A teacher cannot add a user or course instance - When I log in as "teacher" - And I follow "Preferences" in the user menu - Then I should see "Repositories" - And I follow "Manage instances" - Then I should not see "Amazon S3 bucket" - And I am on "Course 1" course homepage with editing mode on - And I navigate to "Repositories" in current page administration - Then I should see "Amazon S3 bucket" - And I should see "Create" - - Scenario: A student cannot add an instance - When I log in as "student" - And I follow "Preferences" in the user menu - Then I should see "Repositories" - And I follow "Manage instances" - Then I should not see "Amazon S3 bucket" - And I am on "Course 1" course homepage - And I should not see "Amazon S3 bucket" diff --git a/tests/behat/s3bucket_course.feature b/tests/behat/s3bucket_course.feature new file mode 100644 index 0000000..bcd7ad0 --- /dev/null +++ b/tests/behat/s3bucket_course.feature @@ -0,0 +1,88 @@ +@repository @repository_s3bucket @javascript +Feature: S3 bucket repository is private in user context + + Background: + Given the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + | Course 2 | C2 | 0 | + And the following "users" exist: + | username | email | firstname | lastname | + | student | s@example.com | Student | 1 | + | teacher | t@example.com | Teacher | 1 | + | facilitator | f@example.com | Teacher | 2 | + And the following "course enrolments" exist: + | user | course | role | + | student | C1 | student | + | teacher | C1 | editingteacher | + | teacher | C2 | editingteacher | + | facilitator | C1 | editingteacher | + And I enable repository "s3bucket" + And I log in as "admin" + And I navigate to "Plugins > Repositories > Amazon S3 bucket" in site administration + And I click on "Allow users to add a repository instance into the course" "checkbox" + And I click on "Save" "button" + And I log out + And I log in as "teacher" + And I am on "Course 1" course homepage with editing mode on + And I navigate to "Repositories" in current page administration + And I follow "Create \"Amazon S3 bucket\" instance" + And I set the field "Name" to "Course 1 Bucket" + And I set the field "Bucket name" to "coursebucket" + And I set the field "Access key" to "anoTherfake@1" + And I set the field "Secret key" to "anotherFake_$2" + And I click on "Save" "button" + And I log out + + Scenario: A teacher can add files from the s3 bucket repository in course context + When I log in as "teacher" + And I am on "Course 1" course homepage with editing mode on + When I add a "Folder" to section "1" + And I set the following fields to these values: + | Name | Folder name | + | Description | Folder description | + And I click on "Add..." "button" in the "Files" "form_row" + Then I should see "Course 1 Bucket" + + Scenario: A teacher cannot see the s3 bucket repository in another course context + When I log in as "teacher" + And I am on "Course 2" course homepage with editing mode on + And I navigate to "Repositories" in current page administration + Then I should not see "Course 1 Bucket" + + Scenario: Another teacher can see the s3 bucket repository in same course context + When I log in as "facilitator" + And I am on "Course 1" course homepage with editing mode on + When I add a "Folder" to section "1" + And I set the following fields to these values: + | Name | Folder name | + | Description | Folder description | + And I click on "Add..." "button" in the "Files" "form_row" + Then I should see "Course 1 Bucket" + + Scenario: A student cannot see a s3 course bucket + When I log in as "teacher" + And I am on "Course 1" course homepage with editing mode on + And I add a "Assignment" to section "1" and I fill the form with: + | Assignment name | Test assignment name | + | Description | Submit your online text | + | assignsubmission_onlinetext_enabled | 0 | + | assignsubmission_file_enabled | 1 | + | Maximum number of uploaded files | 2 | + And I log out + And I log in as "student" + And I am on "Course 1" course homepage + And I follow "Test assignment name" + When I press "Add submission" + And I follow "Add..." + Then I should not see "Course 1 Bucket" + + Scenario: An admin can see a s3 course bucket + When I log in as "admin" + And I am on "Course 1" course homepage with editing mode on + When I add a "Folder" to section "1" + And I set the following fields to these values: + | Name | Folder name | + | Description | Folder description | + And I click on "Add..." "button" in the "Files" "form_row" + Then I should see "Course 1 Bucket" diff --git a/tests/behat/s3bucket_instances.feature b/tests/behat/s3bucket_global.feature similarity index 79% rename from tests/behat/s3bucket_instances.feature rename to tests/behat/s3bucket_global.feature index c10bf25..e32ba2f 100644 --- a/tests/behat/s3bucket_instances.feature +++ b/tests/behat/s3bucket_global.feature @@ -1,5 +1,5 @@ @repository @repository_s3bucket @_file_upload -Feature: S3 bucket repository should be seen by admins +Feature: S3 bucket global repositories should be seen by admins and teachers Background: Given the following "courses" exist: @@ -17,24 +17,21 @@ Feature: S3 bucket repository should be seen by admins And I log in as "admin" And I navigate to "Plugins > Repositories > Amazon S3 bucket" in site administration And I click on "Create a repository instance" "button" - And I set the following fields to these values: - | name | Testrepo | - | bucket_name | Testbucket | - And I click on "Save" "button" - Then I should see "Required" + And I set the field "Name" to "Global bucket" + And I set the field "Bucket name" to "globalbucket" And I set the field "Access key" to "anoTherfake@1" And I set the field "Secret key" to "anotherFake_$2" And I click on "Save" "button" And I log out @javascript - Scenario: An admin can see the s3 bucket repository + Scenario: An admin can see the global s3 bucket repository When I log in as "admin" Then I should see "No files available" in the "Private files" "block" And I follow "Manage private files..." And I click on "Add..." "button" in the "Files" "form_row" - Then I should see "Testrepo" - And I follow "Testrepo" + Then I should see "Global bucket" + And I follow "Global bucket" Then I should see "2020_dir" And I should see "2020_f.jpg" And I follow "2020_f.jpg" @@ -47,12 +44,12 @@ Feature: S3 bucket repository should be seen by admins And I should see "2020_f.jpg" in the "Private files" "block" @javascript - Scenario: An admin can search the s3 bucket repository + Scenario: An admin can search the global s3 bucket repository When I log in as "admin" And I follow "Manage private files..." And I click on "Add..." "button" in the "Files" "form_row" - Then I should see "Testrepo" - And I follow "Testrepo" + Then I should see "Global bucket" + And I follow "Global bucket" Then I should see "2" elements in repository content area And I click on "Display folder with file details" "link" in the ".file-picker" "css_element" And I click on "Display folder as file tree" "link" in the ".file-picker" "css_element" @@ -65,14 +62,14 @@ Feature: S3 bucket repository should be seen by admins When I press enter Then I should see "0" elements in repository content area - Scenario: A teacher cannot see the s3 bucket repository in private area + Scenario: A teacher cannot see the global s3 bucket repository in private area When I log in as "teacher" And I follow "Manage private files..." And I click on "Add..." "button" in the "Files" "form_row" - Then I should not see "Testrepo" + Then I should not see "Global bucket" @javascript - Scenario: A teacher can see the s3 bucket repository in a course module + Scenario: A teacher can see the global s3 bucket repository in a course module When I log in as "teacher" And I am on "Course 1" course homepage with editing mode on When I add a "Folder" to section "1" @@ -80,8 +77,8 @@ Feature: S3 bucket repository should be seen by admins | Name | Folder name | | Description | Folder description | And I click on "Add..." "button" in the "Files" "form_row" - Then I should see "Testrepo" - And I follow "Testrepo" + Then I should see "Global bucket" + And I follow "Global bucket" Then I should see "2020_dir" And I should see "2020_f.jpg" And I follow "2020_f.jpg" @@ -93,14 +90,14 @@ Feature: S3 bucket repository should be seen by admins And I should see "2020_f.jpg" @javascript - Scenario: A teacher can add a s3 bucket link in a url module + Scenario: A teacher can add a global s3 bucket link in a url module When I log in as "teacher" And I am on "Course 1" course homepage with editing mode on When I add a "URL" to section "1" and I fill the form with: | Name | Url name | And I click on "Choose a link..." "button" - Then I should see "Testrepo" - And I follow "Testrepo" + Then I should see "Global bucket" + And I follow "Global bucket" Then I should see "2020_dir" And I should see "2020_f.jpg" And I follow "2020_f.jpg" @@ -108,8 +105,8 @@ Feature: S3 bucket repository should be seen by admins And I click on "Save and return to course" "button" Then I should see "Url name" - Scenario: A student cannot see the s3 bucket repository + Scenario: A student cannot see the global s3 bucket repository When I log in as "student" And I follow "Manage private files..." And I click on "Add..." "button" in the "Files" "form_row" - Then I should not see "Testrepo" + Then I should not see "Global bucket" diff --git a/tests/behat/s3bucket_user.feature b/tests/behat/s3bucket_user.feature new file mode 100644 index 0000000..b25f3d5 --- /dev/null +++ b/tests/behat/s3bucket_user.feature @@ -0,0 +1,147 @@ +@repository @repository_s3bucket @javascript +Feature: S3 bucket repository can be used in user context + + Background: + Given the following "users" exist: + | username | email | firstname | lastname | + | student | s@example.com | Student | 1 | + | teacher | t@example.com | Teacher | 1 | + | editor | e@example.com | Editor | 1 | + | manager | m@example.com | Manager | 1 | + And the following "role assigns" exist: + | user | role | contextlevel | reference | + | teacher | editingteacher | System | | + | editor | editingteacher | System | | + | manager | manager | System | | + And I enable repository "s3bucket" + And I log in as "admin" + And I navigate to "Plugins > Repositories > Amazon S3 bucket" in site administration + And I click on "Allow users to add a repository instance into the user context" "checkbox" + And I click on "Save" "button" + And I log out + + Scenario: A teacher can add files from the s3 bucket repository in user context + When I log in as "teacher" + And I follow "Preferences" in the user menu + Then I should see "Repositories" + And I follow "Manage instances" + Then I should see "Amazon S3 bucket" + And I follow "Create \"Amazon S3 bucket\" instance" + And I set the field "Name" to "Teacher user bucket" + And I set the field "Bucket name" to "teacherbucket" + And I set the field "Access key" to "anoTherfake@1" + And I set the field "Secret key" to "anotherFake_$2" + And I click on "Save" "button" + And I follow "Dashboard" in the user menu + And I follow "Manage private files..." + And I click on "Add..." "button" in the "Files" "form_row" + Then I should see "Teacher user bucket" + And I follow "Teacher user bucket" + Then I should see "2020_dir" + + Scenario: An admin does not have access to a private s3 bucket repository in user context + When I log in as "teacher" + And I follow "Preferences" in the user menu + And I follow "Manage instances" + And I follow "Create \"Amazon S3 bucket\" instance" + And I set the field "Name" to "Teacher user bucket" + And I set the field "Bucket name" to "userbucket" + And I set the field "Access key" to "anoTherfake@1" + And I set the field "Secret key" to "anotherFake_$2" + And I click on "Save" "button" + And I log out + And I log in as "admin" + And I follow "Dashboard" in the user menu + And I follow "Manage private files..." + And I click on "Add..." "button" in the "Files" "form_row" + Then I should not see "Teacher user bucket" + + Scenario: An admin cannot access a private s3 bucket repository in user context + When I log in as "teacher" + And I follow "Preferences" in the user menu + And I follow "Manage instances" + And I follow "Create \"Amazon S3 bucket\" instance" + And I set the field "Name" to "Teacher user bucket" + And I set the field "Bucket name" to "userbucket" + And I set the field "Access key" to "anoTherfake@1" + And I set the field "Secret key" to "anotherFake_$2" + And I click on "Save" "button" + And I log out + And I log in as "admin" + And I navigate to "Users > Accounts > Browse list of users" in site administration + And I follow "Teacher 1" + And I click on "Preferences" "link" in the ".profile_tree" "css_element" + # And I follow "Manage instances" throws an error: You can not view/edit repository instances of another user. + + Scenario: A manager does not have access to a private s3 bucket repository in user context + When I log in as "teacher" + And I follow "Preferences" in the user menu + And I follow "Manage instances" + And I follow "Create \"Amazon S3 bucket\" instance" + And I set the field "Name" to "Teacher user bucket" + And I set the field "Bucket name" to "userbucket" + And I set the field "Access key" to "anoTherfake@1" + And I set the field "Secret key" to "anotherFake_$2" + And I click on "Save" "button" + And I log out + And I log in as "manager" + And I follow "Dashboard" in the user menu + And I follow "Manage private files..." + And I click on "Add..." "button" in the "Files" "form_row" + Then I should not see "Teacher user bucket" + + Scenario: Another teacher does not has access to a private s3 bucket repository in user context + When I log in as "teacher" + And I follow "Preferences" in the user menu + And I follow "Manage instances" + And I follow "Create \"Amazon S3 bucket\" instance" + And I set the field "Name" to "Teacher user bucket" + And I set the field "Bucket name" to "userbucket" + And I set the field "Access key" to "anoTherfake@1" + And I set the field "Secret key" to "anotherFake_$2" + And I click on "Save" "button" + And I log out + And I log in as "editor" + And I follow "Dashboard" in the user menu + And I follow "Manage private files..." + And I click on "Add..." "button" in the "Files" "form_row" + Then I should not see "Teacher user bucket" + + Scenario: A student cannot add files from the s3 bucket repository in user context + When I log in as "student" + And I follow "Preferences" in the user menu + Then I should see "Repositories" + And I follow "Manage instances" + Then I should not see "Amazon S3 bucket" + + Scenario: An manager can add files from the s3 bucket repository in user context + When I log in as "manager" + And I follow "Preferences" in the user menu + Then I should see "Repositories" + And I follow "Manage instances" + Then I should see "Amazon S3 bucket" + And I follow "Create \"Amazon S3 bucket\" instance" + And I set the field "Name" to "Manager user bucket" + And I set the field "Bucket name" to "userbucket" + And I set the field "Access key" to "anoTherfake@1" + And I set the field "Secret key" to "anotherFake_$2" + And I click on "Save" "button" + And I follow "Dashboard" in the user menu + And I follow "Manage private files..." + And I click on "Add..." "button" in the "Files" "form_row" + Then I should see "Manager user bucket" + And I follow "Manager user bucket" + Then I should see "2020_dir" + + Scenario: An admin can add files from the s3 bucket repository in user context + When I log in as "admin" + And I follow "Preferences" in the user menu + Then I should see "Repositories" + And I follow "Manage instances" + Then I should see "Amazon S3 bucket" + And I follow "Create \"Amazon S3 bucket\" instance" + And I set the field "Name" to "Admin user bucket" + And I set the field "Bucket name" to "userbucket" + And I set the field "Access key" to "anoTherfake@1" + And I set the field "Secret key" to "anotherFake_$2" + And I click on "Save" "button" diff --git a/tests/other_test.php b/tests/other_test.php index 01da7fa..704e935 100644 --- a/tests/other_test.php +++ b/tests/other_test.php @@ -118,8 +118,9 @@ public function test_empty() { */ public function test_search() { $userid = $this->getDataGenerator()->create_user()->id; - $this->data['endpoint'] = 'eu-central-1'; $repo = new \repository_s3bucket($this->repo, \context_user::instance($userid), $this->data); + $this->data['endpoint'] = 'eu-central-1'; + $repo->set_option($this->data); $result = $repo->search('filesearch'); $this->assertCount(0, $result['list']); $result = $repo->search('2020'); diff --git a/version.php b/version.php index 463b7f0..9ce9cd3 100644 --- a/version.php +++ b/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2020110101; +$plugin->version = 2020111100; $plugin->requires = 2019111800; $plugin->component = 'repository_s3bucket'; $plugin->maturity = MATURITY_STABLE;