mirror of
https://github.com/LdesignMedia/moodle-availability_ipaddress.git
synced 2026-05-17 05:48:41 +02:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4754b1e03e | ||
|
|
54ac7002d8 | ||
|
|
5d25933dfb | ||
|
|
28f6d4603b | ||
|
|
527831df6b | ||
|
|
d41c96e035 | ||
|
|
29a4857d8a | ||
|
|
163ee678a5 | ||
|
|
c5a8b00380 |
214
.eslintrc
214
.eslintrc
@@ -1,214 +0,0 @@
|
|||||||
{
|
|
||||||
'plugins': [
|
|
||||||
'promise',
|
|
||||||
],
|
|
||||||
'env': {
|
|
||||||
'browser': true,
|
|
||||||
'amd': true
|
|
||||||
},
|
|
||||||
'globals': {
|
|
||||||
'M': true,
|
|
||||||
'Y': true
|
|
||||||
},
|
|
||||||
'rules': {
|
|
||||||
// See http://eslint.org/docs/rules/ for all rules and explanations of all
|
|
||||||
// rules.
|
|
||||||
|
|
||||||
// === Possible Errors ===
|
|
||||||
'comma-dangle': 'off',
|
|
||||||
'no-compare-neg-zero': 'error',
|
|
||||||
'no-cond-assign': 'error',
|
|
||||||
'no-console': 'error',
|
|
||||||
'no-constant-condition': 'error',
|
|
||||||
'no-control-regex': 'error',
|
|
||||||
'no-debugger': 'error',
|
|
||||||
'no-dupe-args': 'error',
|
|
||||||
'no-dupe-keys': 'error',
|
|
||||||
'no-duplicate-case': 'error',
|
|
||||||
'no-empty': 'warn',
|
|
||||||
'no-empty-character-class': 'error',
|
|
||||||
'no-ex-assign': 'error',
|
|
||||||
'no-extra-boolean-cast': 'error',
|
|
||||||
'no-extra-parens': 'off',
|
|
||||||
'no-extra-semi': 'error',
|
|
||||||
'no-func-assign': 'error',
|
|
||||||
'no-inner-declarations': 'error',
|
|
||||||
'no-invalid-regexp': 'error',
|
|
||||||
'no-irregular-whitespace': 'error',
|
|
||||||
'no-obj-calls': 'error',
|
|
||||||
'no-prototype-builtins': 'off',
|
|
||||||
'no-regex-spaces': 'error',
|
|
||||||
'no-sparse-arrays': 'error',
|
|
||||||
'no-unexpected-multiline': 'error',
|
|
||||||
'no-unreachable': 'warn',
|
|
||||||
'no-unsafe-finally': 'error',
|
|
||||||
'no-unsafe-negation': 'error',
|
|
||||||
'use-isnan': 'error',
|
|
||||||
'valid-jsdoc': ['warn', { 'requireReturn': false, 'requireParamDescription': false, 'requireReturnDescription': false }],
|
|
||||||
'valid-typeof': 'error',
|
|
||||||
|
|
||||||
// === Best Practices ===
|
|
||||||
// (these mostly match our jshint config)
|
|
||||||
'array-callback-return': 'warn',
|
|
||||||
'block-scoped-var': 'warn',
|
|
||||||
'complexity': 'warn',
|
|
||||||
'consistent-return': 'warn',
|
|
||||||
'curly': 'error',
|
|
||||||
'dot-notation': 'warn',
|
|
||||||
'no-alert': 'warn',
|
|
||||||
'no-caller': 'error',
|
|
||||||
'no-case-declarations': 'error',
|
|
||||||
'no-div-regex': 'error',
|
|
||||||
'no-empty-pattern': 'error',
|
|
||||||
'no-empty-function': 'warn',
|
|
||||||
'no-eq-null': 'error',
|
|
||||||
'no-eval': 'error',
|
|
||||||
'no-extend-native': 'error',
|
|
||||||
'no-extra-bind': 'warn',
|
|
||||||
'no-fallthrough': 'error',
|
|
||||||
'no-floating-decimal': 'warn',
|
|
||||||
'no-global-assign': 'warn',
|
|
||||||
'no-implied-eval': 'error',
|
|
||||||
'no-invalid-this': 'error',
|
|
||||||
'no-iterator': 'error',
|
|
||||||
'no-labels': 'error',
|
|
||||||
'no-loop-func': 'error',
|
|
||||||
'no-multi-spaces': 'warn',
|
|
||||||
'no-multi-str': 'error',
|
|
||||||
'no-new-func': 'error',
|
|
||||||
'no-new-wrappers': 'error',
|
|
||||||
'no-octal': 'error',
|
|
||||||
'no-octal-escape': 'error',
|
|
||||||
'no-proto': 'error',
|
|
||||||
'no-redeclare': 'warn',
|
|
||||||
'no-return-assign': 'error',
|
|
||||||
'no-script-url': 'error',
|
|
||||||
'no-self-assign': 'error',
|
|
||||||
'no-self-compare': 'error',
|
|
||||||
'no-sequences': 'warn',
|
|
||||||
'no-throw-literal': 'warn',
|
|
||||||
'no-unmodified-loop-condition': 'error',
|
|
||||||
'no-unused-expressions': 'error',
|
|
||||||
'no-unused-labels': 'error',
|
|
||||||
'no-useless-call': 'warn',
|
|
||||||
'no-useless-escape': 'warn',
|
|
||||||
'no-with': 'error',
|
|
||||||
'wrap-iife': ['error', 'any'],
|
|
||||||
|
|
||||||
// === Variables ===
|
|
||||||
'no-delete-var': 'error',
|
|
||||||
'no-undef': 'error',
|
|
||||||
'no-undef-init': 'error',
|
|
||||||
'no-unused-vars': ['error', { 'caughtErrors': 'none' }],
|
|
||||||
|
|
||||||
// === Stylistic Issues ===
|
|
||||||
'array-bracket-spacing': 'warn',
|
|
||||||
'block-spacing': 'warn',
|
|
||||||
'brace-style': ['warn', '1tbs'],
|
|
||||||
'camelcase': 'warn',
|
|
||||||
'capitalized-comments': ['warn', 'always', { 'ignoreConsecutiveComments': true }],
|
|
||||||
'comma-spacing': ['warn', { 'before': false, 'after': true }],
|
|
||||||
'comma-style': ['warn', 'last'],
|
|
||||||
'computed-property-spacing': 'error',
|
|
||||||
'consistent-this': 'off',
|
|
||||||
'eol-last': 'off',
|
|
||||||
'func-call-spacing': ['warn', 'never'],
|
|
||||||
'func-names': 'off',
|
|
||||||
'func-style': 'off',
|
|
||||||
// indent currently not doing well with our wrapping style, so disabled.
|
|
||||||
'indent': ['off', 4, { 'SwitchCase': 1 }],
|
|
||||||
'key-spacing': ['warn', { 'beforeColon': false, 'afterColon': true, 'mode': minimum }],
|
|
||||||
'keyword-spacing': 'warn',
|
|
||||||
'linebreak-style': ['error', 'unix'],
|
|
||||||
'lines-around-comment': 'off',
|
|
||||||
'max-len': ['error', 132],
|
|
||||||
'max-lines': 'off',
|
|
||||||
'max-depth': 'warn',
|
|
||||||
'max-nested-callbacks': ['warn', 5],
|
|
||||||
'max-params': 'off',
|
|
||||||
'max-statements': 'off',
|
|
||||||
'max-statements-per-line': ['warn', { max: 2 }],
|
|
||||||
'new-cap': ['warn', { 'properties': false }],
|
|
||||||
'new-parens': 'warn',
|
|
||||||
'newline-after-var': 'off',
|
|
||||||
'newline-before-return': 'off',
|
|
||||||
'newline-per-chained-call': 'off',
|
|
||||||
'no-array-constructor': 'off',
|
|
||||||
'no-bitwise': 'error',
|
|
||||||
'no-continue': 'off',
|
|
||||||
'no-inline-comments': 'off',
|
|
||||||
'no-lonely-if': 'off',
|
|
||||||
'no-mixed-operators': 'off',
|
|
||||||
'no-mixed-spaces-and-tabs': 'error',
|
|
||||||
'no-multiple-empty-lines': 'warn',
|
|
||||||
'no-negated-condition': 'off',
|
|
||||||
'no-nested-ternary': 'warn',
|
|
||||||
'no-new-object': 'off',
|
|
||||||
'no-plusplus': 'off',
|
|
||||||
'no-tabs': 'error',
|
|
||||||
'no-ternary': 'off',
|
|
||||||
'no-trailing-spaces': 'error',
|
|
||||||
'no-underscore-dangle': 'off',
|
|
||||||
'no-unneeded-ternary': 'off',
|
|
||||||
'no-whitespace-before-property': 'warn',
|
|
||||||
'object-curly-newline': 'off',
|
|
||||||
'object-curly-spacing': 'warn',
|
|
||||||
'object-property-newline': 'off',
|
|
||||||
'one-var': 'off',
|
|
||||||
'one-var-declaration-per-line': ['warn', 'initializations'],
|
|
||||||
'operator-assignment': 'off',
|
|
||||||
'operator-linebreak': 'off',
|
|
||||||
'padded-blocks': 'off',
|
|
||||||
'quote-props': ['warn', 'as-needed', {'unnecessary': false, 'keywords': true, 'numbers': true}],
|
|
||||||
'quotes': 'off',
|
|
||||||
'require-jsdoc': 'warn',
|
|
||||||
'semi': 'error',
|
|
||||||
'semi-spacing': ['warn', {'before': false, 'after': true}],
|
|
||||||
'sort-vars': 'off',
|
|
||||||
'space-before-blocks': 'warn',
|
|
||||||
'space-before-function-paren': ['warn', 'never'],
|
|
||||||
'space-in-parens': 'warn',
|
|
||||||
'space-infix-ops': 'warn',
|
|
||||||
'space-unary-ops': 'warn',
|
|
||||||
'spaced-comment': 'warn',
|
|
||||||
'unicode-bom': 'error',
|
|
||||||
'wrap-regex': 'off',
|
|
||||||
|
|
||||||
// === Promises ===
|
|
||||||
'promise/always-return': 'warn',
|
|
||||||
'promise/no-return-wrap': 'warn',
|
|
||||||
'promise/param-names': 'warn',
|
|
||||||
'promise/catch-or-return': ['warn', {terminationMethod: ['catch', 'fail']}],
|
|
||||||
'promise/no-native': 'warn',
|
|
||||||
'promise/no-promise-in-callback': 'warn',
|
|
||||||
'promise/no-callback-in-promise': 'warn',
|
|
||||||
'promise/avoid-new': 'warn',
|
|
||||||
|
|
||||||
// === Deprecations ===
|
|
||||||
"no-restricted-properties": ['warn', {
|
|
||||||
'object': 'M',
|
|
||||||
'property': 'str',
|
|
||||||
'message': 'Use AMD module "core/str" or M.util.get_string()'
|
|
||||||
}],
|
|
||||||
|
|
||||||
},
|
|
||||||
overrides: [
|
|
||||||
{
|
|
||||||
files: ["**/yui/src/**/*.js"],
|
|
||||||
// Disable some rules which we can't safely define for YUI rollups.
|
|
||||||
rules: {
|
|
||||||
'no-undef': 'off',
|
|
||||||
'no-unused-vars': 'off',
|
|
||||||
'no-unused-expressions': 'off'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
files: ["**/amd/src/*.js"],
|
|
||||||
// Check AMD with some slightly stricter rules.
|
|
||||||
rules: {
|
|
||||||
'no-unused-vars': 'error',
|
|
||||||
'no-implicit-globals': 'error'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
123
.github/workflows/ci.yml
vendored
Normal file
123
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
name: Moodle Plugin CI
|
||||||
|
|
||||||
|
on: [ push, pull_request ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-18.04
|
||||||
|
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:10
|
||||||
|
env:
|
||||||
|
POSTGRES_USER: 'postgres'
|
||||||
|
POSTGRES_HOST_AUTH_METHOD: 'trust'
|
||||||
|
ports:
|
||||||
|
- 5432:5432
|
||||||
|
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
|
||||||
|
mariadb:
|
||||||
|
image: mariadb:10.5
|
||||||
|
env:
|
||||||
|
MYSQL_USER: 'root'
|
||||||
|
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
|
||||||
|
ports:
|
||||||
|
- 3306:3306
|
||||||
|
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- php: '7.4'
|
||||||
|
moodle-branch: 'MOODLE_311_STABLE'
|
||||||
|
database: pgsql
|
||||||
|
- php: '7.4'
|
||||||
|
moodle-branch: 'MOODLE_310_STABLE'
|
||||||
|
database: mariadb
|
||||||
|
- php: '7.3'
|
||||||
|
moodle-branch: 'MOODLE_39_STABLE'
|
||||||
|
database: pgsql
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: plugin
|
||||||
|
|
||||||
|
- name: Setup PHP ${{ matrix.php }}
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: ${{ matrix.php }}
|
||||||
|
extensions: ${{ matrix.extensions }}
|
||||||
|
ini-values: max_input_vars=5000
|
||||||
|
coverage: none
|
||||||
|
|
||||||
|
- name: Initialise moodle-plugin-ci
|
||||||
|
run: |
|
||||||
|
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
|
||||||
|
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
|
||||||
|
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
|
||||||
|
sudo locale-gen en_AU.UTF-8
|
||||||
|
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Install moodle-plugin-ci
|
||||||
|
run: |
|
||||||
|
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
|
||||||
|
env:
|
||||||
|
DB: ${{ matrix.database }}
|
||||||
|
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
|
||||||
|
|
||||||
|
- name: PHP Lint
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci phplint
|
||||||
|
|
||||||
|
- name: PHP Copy/Paste Detector
|
||||||
|
continue-on-error: true # This step will show errors but will not fail
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci phpcpd
|
||||||
|
|
||||||
|
- name: PHP Mess Detector
|
||||||
|
continue-on-error: true # This step will show errors but will not fail
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci phpmd
|
||||||
|
|
||||||
|
- name: Moodle Code Checker
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci codechecker --max-warnings 0
|
||||||
|
|
||||||
|
- name: Moodle PHPDoc Checker
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci phpdoc
|
||||||
|
|
||||||
|
- name: Validating
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci validate
|
||||||
|
|
||||||
|
- name: Check upgrade savepoints
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci savepoints
|
||||||
|
|
||||||
|
- name: Mustache Lint
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci mustache
|
||||||
|
|
||||||
|
- name: Grunt
|
||||||
|
continue-on-error: true # This step will show errors but will not fail
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci grunt --max-lint-warnings 0
|
||||||
|
|
||||||
|
- name: PHPUnit tests
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci phpunit
|
||||||
|
|
||||||
|
- name: Core privacy tests
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: |
|
||||||
|
cd moodle
|
||||||
|
php admin/tool/phpunit/cli/init.php
|
||||||
|
vendor/bin/phpunit --fail-on-risky --disallow-test-output -v --filter tool_dataprivacy_metadata_registry_testcase
|
||||||
|
vendor/bin/phpunit --fail-on-risky --disallow-test-output -v --filter provider_testcase
|
||||||
|
|
||||||
|
- name: Behat features
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci behat --profile chrome
|
||||||
66
.github/workflows/moodle-release.yml
vendored
Normal file
66
.github/workflows/moodle-release.yml
vendored
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#
|
||||||
|
# Whenever a new tag is pushed, add the tagged version
|
||||||
|
# to the Moodle Plugins directory at https://moodle.org/plugins
|
||||||
|
#
|
||||||
|
# revision: 2021070201
|
||||||
|
#
|
||||||
|
name: Releasing in the Plugins directory
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag:
|
||||||
|
description: 'Tag to be released'
|
||||||
|
required: true
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release-at-moodle-org:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
PLUGIN: availability_ipaddress
|
||||||
|
CURL: curl -s
|
||||||
|
ENDPOINT: https://moodle.org/webservice/rest/server.php
|
||||||
|
TOKEN: ${{ secrets.MOODLE_ORG_TOKEN }}
|
||||||
|
FUNCTION: local_plugins_add_version
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Call the service function
|
||||||
|
id: add-version
|
||||||
|
run: |
|
||||||
|
if [[ ! -z "${{ github.event.inputs.tag }}" ]]; then
|
||||||
|
TAGNAME="${{ github.event.inputs.tag }}"
|
||||||
|
elif [[ $GITHUB_REF = refs/tags/* ]]; then
|
||||||
|
TAGNAME="${GITHUB_REF##*/}"
|
||||||
|
fi
|
||||||
|
if [[ -z "${TAGNAME}" ]]; then
|
||||||
|
echo "No tag name has been provided!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
ZIPURL="https://api.github.com/repos/${{ github.repository }}/zipball/${TAGNAME}"
|
||||||
|
RESPONSE=$(${CURL} ${ENDPOINT} --data-urlencode "wstoken=${TOKEN}" \
|
||||||
|
--data-urlencode "wsfunction=${FUNCTION}" \
|
||||||
|
--data-urlencode "moodlewsrestformat=json" \
|
||||||
|
--data-urlencode "frankenstyle=${PLUGIN}" \
|
||||||
|
--data-urlencode "zipurl=${ZIPURL}" \
|
||||||
|
--data-urlencode "vcssystem=git" \
|
||||||
|
--data-urlencode "vcsrepositoryurl=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" \
|
||||||
|
--data-urlencode "vcstag=${TAGNAME}" \
|
||||||
|
--data-urlencode "changelogurl=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commits/${TAGNAME}" \
|
||||||
|
--data-urlencode "altdownloadurl=${ZIPURL}")
|
||||||
|
echo "::set-output name=response::${RESPONSE}"
|
||||||
|
|
||||||
|
- name: Evaluate the response
|
||||||
|
id: evaluate-response
|
||||||
|
env:
|
||||||
|
RESPONSE: ${{ steps.add-version.outputs.response }}
|
||||||
|
run: |
|
||||||
|
jq <<< ${RESPONSE}
|
||||||
|
jq --exit-status ".id" <<< ${RESPONSE} > /dev/null
|
||||||
62
.travis.yml
62
.travis.yml
@@ -1,62 +0,0 @@
|
|||||||
language: php
|
|
||||||
sudo: required
|
|
||||||
dist: trusty
|
|
||||||
|
|
||||||
addons:
|
|
||||||
hosts:
|
|
||||||
- moodle.test
|
|
||||||
firefox: "35.0.1"
|
|
||||||
postgresql: "9.4"
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- oracle-java9-installer
|
|
||||||
- oracle-java9-set-default
|
|
||||||
- redis-server
|
|
||||||
|
|
||||||
services:
|
|
||||||
- redis-server
|
|
||||||
|
|
||||||
cache:
|
|
||||||
directories:
|
|
||||||
- $HOME/.composer/cache
|
|
||||||
- $HOME/.npm
|
|
||||||
|
|
||||||
env:
|
|
||||||
global:
|
|
||||||
- IGNORE_PATHS=vendor,source
|
|
||||||
- IGNORE_NAMES=*.txt,*.md
|
|
||||||
|
|
||||||
# Alternate tests with MySQL and PostgreSQL
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
# PHP 7.0
|
|
||||||
- php: 7.0
|
|
||||||
env: DB=mysqli MOODLE_BRANCH=MOODLE_35_STABLE
|
|
||||||
- php: 7.2
|
|
||||||
env: DB=pgsql MOODLE_BRANCH=MOODLE_37_STABLE
|
|
||||||
- php: 7.2
|
|
||||||
env: DB=pgsql MOODLE_BRANCH=master
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- phpenv config-rm xdebug.ini
|
|
||||||
- cd ../..
|
|
||||||
- nvm install 8.9;
|
|
||||||
nvm use 8.9;
|
|
||||||
composer create-project -n --no-dev --prefer-dist moodlerooms/moodle-plugin-ci ci ^2;
|
|
||||||
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"
|
|
||||||
|
|
||||||
install:
|
|
||||||
- moodle-plugin-ci install -vvv
|
|
||||||
- echo '$CFG->cookiesecure = false;' >> moodle/config.php
|
|
||||||
|
|
||||||
script:
|
|
||||||
- moodle-plugin-ci validate
|
|
||||||
- moodle-plugin-ci phplint
|
|
||||||
- moodle-plugin-ci phpcpd
|
|
||||||
- moodle-plugin-ci phpmd
|
|
||||||
- moodle-plugin-ci codechecker
|
|
||||||
- moodle-plugin-ci savepoints
|
|
||||||
- moodle-plugin-ci mustache
|
|
||||||
- moodle-plugin-ci grunt || false
|
|
||||||
- moodle-plugin-ci phpunit
|
|
||||||
- moodle-plugin-ci behat
|
|
||||||
24
README.md
24
README.md
@@ -1,14 +1,22 @@
|
|||||||
## Moodle - availability ip address plugin
|
## Moodle - availability ip address plugin
|
||||||
Restrict access to any activity by ip-address. Most activities don't support this feature.
|
Restrict access to any activity by ip-address. This plugin can be used to make any chosen activity unavailable based on the user's IP.
|
||||||
|
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||

|

|
||||||
|
|
||||||
* Author: Luuk Verhoeven, [MFreak.nl](https://MFreak.nl/)
|
* Author: Luuk Verhoeven, [MFreak.nl](https://MFreak.nl/)
|
||||||
* Min. required: Moodle 3.2.x
|
* Min. required: Moodle 3.5.x
|
||||||
* Supports PHP: 7.0 | 7.1
|
* Supports PHP: 7.2
|
||||||
|
|
||||||
[](https://travis-ci.org/MFreakNL/moodle-availability_ipaddress)
|
[](https://travis-ci.org/MFreakNL/moodle-availability_ipaddress)
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -24,6 +32,16 @@ Restrict access to any activity by ip-address. Most activities don't support thi
|
|||||||
3. Go to Site Administrator > Notification
|
3. Go to Site Administrator > Notification
|
||||||
4. Install the plugin
|
4. Install the plugin
|
||||||
|
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
1. Add or edit an activity in a Moodle course.
|
||||||
|
2. Go to the section "Restrict access"
|
||||||
|
3. Click IP address in the modal
|
||||||
|
4. There's a new input field that supports a list of comma separated ip address e.g. 127.0.0.1, 192.168.1.0/24
|
||||||
|
1. The users with matching ip addresses can view the activity.
|
||||||
|
5. Save the activity
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
- Behat tests ip validation
|
- Behat tests ip validation
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class condition extends \core_availability\condition {
|
|||||||
*
|
*
|
||||||
* @return bool True if available
|
* @return bool True if available
|
||||||
*/
|
*/
|
||||||
public function is_available($not, info $info, $grabthelot, $userid) {
|
public function is_available($not, info $info, $grabthelot, $userid) : bool {
|
||||||
|
|
||||||
if (empty($this->ipaddresses)) {
|
if (empty($this->ipaddresses)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -118,7 +118,7 @@ class condition extends \core_availability\condition {
|
|||||||
* this item
|
* this item
|
||||||
* @throws \coding_exception
|
* @throws \coding_exception
|
||||||
*/
|
*/
|
||||||
public function get_description($full, $not, info $info) {
|
public function get_description($full, $not, info $info) : string {
|
||||||
return get_string('require_condition', 'availability_ipaddress');
|
return get_string('require_condition', 'availability_ipaddress');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ class condition extends \core_availability\condition {
|
|||||||
*
|
*
|
||||||
* @return string Text representation of parameters
|
* @return string Text representation of parameters
|
||||||
*/
|
*/
|
||||||
protected function get_debug_string() {
|
protected function get_debug_string() : string {
|
||||||
return !empty($this->ipaddresses) ? 'ipaddresses ON' : 'ipaddresses OFF';
|
return !empty($this->ipaddresses) ? 'ipaddresses ON' : 'ipaddresses OFF';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ class condition extends \core_availability\condition {
|
|||||||
*
|
*
|
||||||
* @return \stdClass Object representing condition
|
* @return \stdClass Object representing condition
|
||||||
*/
|
*/
|
||||||
public static function get_json($ipaddresses) {
|
public static function get_json($ipaddresses) : \stdClass {
|
||||||
return (object)[
|
return (object)[
|
||||||
'type' => 'ipaddress',
|
'type' => 'ipaddress',
|
||||||
'ipaddresses' => $ipaddresses,
|
'ipaddresses' => $ipaddresses,
|
||||||
@@ -156,7 +156,7 @@ class condition extends \core_availability\condition {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function is_valid_ipaddresses($ipaddresses) {
|
public static function is_valid_ipaddresses($ipaddresses) : bool {
|
||||||
$ipaddresses = implode(',', $ipaddresses);
|
$ipaddresses = implode(',', $ipaddresses);
|
||||||
foreach ($ipaddresses as $ipaddress) {
|
foreach ($ipaddresses as $ipaddress) {
|
||||||
if (!filter_var($ipaddress, FILTER_VALIDATE_IP)) {
|
if (!filter_var($ipaddress, FILTER_VALIDATE_IP)) {
|
||||||
@@ -173,7 +173,7 @@ class condition extends \core_availability\condition {
|
|||||||
*
|
*
|
||||||
* @return \stdClass Structure object (ready to be made into JSON format)
|
* @return \stdClass Structure object (ready to be made into JSON format)
|
||||||
*/
|
*/
|
||||||
public function save() {
|
public function save() : \stdClass {
|
||||||
return (object)[
|
return (object)[
|
||||||
'type' => 'ipaddress',
|
'type' => 'ipaddress',
|
||||||
'ipaddresses' => $this->ipaddresses,
|
'ipaddresses' => $this->ipaddresses,
|
||||||
|
|||||||
@@ -41,24 +41,10 @@ class frontend extends \core_availability\frontend {
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function get_javascript_strings() {
|
protected function get_javascript_strings() : array {
|
||||||
return [
|
return [
|
||||||
'js:ipaddress',
|
'js:ipaddress',
|
||||||
'error_ipaddress',
|
'error_ipaddress',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Decides whether this plugin should be available in a given course. The
|
|
||||||
* plugin can do this depending on course or system settings.
|
|
||||||
*
|
|
||||||
* @param \stdClass $course Course object
|
|
||||||
* @param \cm_info $cm Course-module currently being edited (null if none)
|
|
||||||
* @param \section_info $section Section currently being edited (null if none)
|
|
||||||
*
|
|
||||||
* @return bool True if there are completion criteria
|
|
||||||
*/
|
|
||||||
protected function allow_add($course, \cm_info $cm = null, \section_info $section = null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
$plugin->component = 'availability_ipaddress';
|
$plugin->component = 'availability_ipaddress';
|
||||||
$plugin->version = 2020061500;
|
$plugin->version = 2021121500;
|
||||||
$plugin->release = '3.9.0';
|
$plugin->release = '3.11.0';
|
||||||
$plugin->requires = 2016120500;
|
$plugin->requires = 2016120500;
|
||||||
$plugin->maturity = MATURITY_BETA;
|
$plugin->maturity = MATURITY_STABLE;
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
YUI.add("moodle-availability_ipaddress-form",function(e,t){M.availability_ipaddress=M.availability_ipaddress||{},M.availability_ipaddress.v4="(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}",M.availability_ipaddress.v6="^((?:[a-fA-F\\d]{1,4}:){7}(?:[a-fA-F\\d]{1,4}|:)|(?:[a-fA-F\\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|:[a-fA-F\\d]{1,4}|:)|(?:[a-fA-F\\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4}){1,2}|:)|(?:[a-fA-F\\d]{1,4}:){4}(?:(:[a-fA-F\\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4}){1,3}|:)|(?:[a-fA-F\\d]{1,4}:){3}(?:(:[a-fA-F\\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4}){1,4}|:)|(?:[a-fA-F\\d]{1,4}:){2}(?:(:[a-fA-F\\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4}){1,5}|:)|(?:[a-fA-F\\d]{1,4}:){1}(?:(:[a-fA-F\\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4}){1,6}|:)|(?::((?::[a-fA-F\\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,7}|:)))(%[0-9a-zA-Z]{1,})?",M.availability_ipaddress.form=e.Object(M.core_availability.plugin),M.availability_ipaddress.form.initInner=function(){"use strict";},M.availability_ipaddress.form.getValue=function(e,t){"use strict";var n=t.one("input[name="+e+"]").get("value");return M.availability_ipaddress.validateIpaddress(n)?n:n},M.availability_ipaddress.form.getNode=function(t){"use strict";var n,r,i,s;return s="ipaddresses"+M.availability_ipaddress.form.instId,M.availability_ipaddress.form.instId+=1,n="",n+='<span class="availability-group"><label for="'+s+'"><span class="p-r-1">'+M.util.get_string("title","availability_ipaddress")+" </span></label>",n+='<input type="text" placeholder="192.168.178.1,231.54.211.0/20,231.3.56.211" name="ipaddresses" id="'+s+'">',r=e.Node.create('<span class="form-inline">'+n+"</span>"),t.ipaddresses!==undefined&&r.one("input[name=ipaddresses]").set("value",t.ipaddresses),M.availability_ipaddress.form.addedEvents||(M.availability_ipaddress.form.addedEvents=!0,i=e.one(".availability-field"),i.delegate("valuechange",function(){M.core_availability.form.update()},".availability_ipaddress input[name=ipaddresses]")),r},M.availability_ipaddress.validateIpaddress=function(e){"use strict";e=e.split(",");for(var t in e){if((new RegExp(/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/gm)).test(e[t]))continue;if((new RegExp(M.availability_ipaddress.v6)).test(e[t]))continue;if((new RegExp("^(?:".concat(M.availability_ipaddress.v4+"\\/(3[0-2]|[12]?[0-9])|(1\\*)",")|(?:").concat(M.availability_ipaddress.v6+"\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])",")?\\/gm"))).test(e[t]))continue;return!1}return!0},M.availability_ipaddress.form.fillValue=function(e,t){e.ipaddresses=this.getValue("ipaddresses",t)},M.availability_ipaddress.form.fillErrors=function(e,t){"use strict";var n={};this.fillValue(n,t),M.availability_ipaddress.validateIpaddress(n.ipaddresses)===!1&&e.push("availability_ipaddress:error_ipaddress")}},"@VERSION@",{requires:["base","node","event","moodle-core_availability-form"]});
|
YUI.add("moodle-availability_ipaddress-form",function(s,d){M.availability_ipaddress=M.availability_ipaddress||{},M.availability_ipaddress.v4="(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}",M.availability_ipaddress.v6="^((?:[a-fA-F\\d]{1,4}:){7}(?:[a-fA-F\\d]{1,4}|:)|(?:[a-fA-F\\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|:[a-fA-F\\d]{1,4}|:)|(?:[a-fA-F\\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4}){1,2}|:)|(?:[a-fA-F\\d]{1,4}:){4}(?:(:[a-fA-F\\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4}){1,3}|:)|(?:[a-fA-F\\d]{1,4}:){3}(?:(:[a-fA-F\\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4}){1,4}|:)|(?:[a-fA-F\\d]{1,4}:){2}(?:(:[a-fA-F\\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4}){1,5}|:)|(?:[a-fA-F\\d]{1,4}:){1}(?:(:[a-fA-F\\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(:[a-fA-F\\d]{1,4}){1,6}|:)|(?::((?::[a-fA-F\\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,7}|:)))(%[0-9a-zA-Z]{1,})?",M.availability_ipaddress.form=s.Object(M.core_availability.plugin),M.availability_ipaddress.form.initInner=function(){},M.availability_ipaddress.form.getValue=function(d,a){"use strict";var i=a.one("input[name="+d+"]").get("value");return M.availability_ipaddress.validateIpaddress(i),i},M.availability_ipaddress.form.getNode=function(d){"use strict";var a,i,e;return e="ipaddresses"+M.availability_ipaddress.form.instId,M.availability_ipaddress.form.instId+=1,a="",a+='<span class="availability-group"><label for="'+e+'"><span class="p-r-1">'+M.util.get_string("title","availability_ipaddress")+" </span></label>",a+='<input type="text" placeholder="192.168.178.1,231.54.211.0/20,231.3.56.211" name="ipaddresses" id="'+e+'">',i=s.Node.create('<span class="form-inline">'+a+"</span>"),d.ipaddresses!==undefined&&i.one("input[name=ipaddresses]").set("value",d.ipaddresses),M.availability_ipaddress.form.addedEvents||(M.availability_ipaddress.form.addedEvents=!0,s.one(".availability-field").delegate("valuechange",function(){M.core_availability.form.update()},".availability_ipaddress input[name=ipaddresses]")),i},M.availability_ipaddress.validateIpaddress=function(d){"use strict";for(var a in d=d.split(","))if(!new RegExp(/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/gm).test(d[a])&&!new RegExp(M.availability_ipaddress.v6).test(d[a])&&!new RegExp("^(?:".concat(M.availability_ipaddress.v4+"\\/(3[0-2]|[12]?[0-9])|(1\\*)",")|(?:").concat(M.availability_ipaddress.v6+"\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])",")?\\/gm")).test(d[a]))return!1;return!0},M.availability_ipaddress.form.fillValue=function(d,a){d.ipaddresses=this.getValue("ipaddresses",a)},M.availability_ipaddress.form.fillErrors=function(d,a){"use strict";var i={};this.fillValue(i,a),!1===M.availability_ipaddress.validateIpaddress(i.ipaddresses)&&d.push("availability_ipaddress:error_ipaddress")}},"@VERSION@",{requires:["base","node","event","moodle-core_availability-form"]});
|
||||||
Reference in New Issue
Block a user