View | Details | Raw Unified | Return to bug 10190
Collapse All | Expand All

(-)a/Koha/REST/V1/CirculationRules.pm (+21 lines)
Lines 316-319 sub _all_kinds { Link Here
316
    return \@all_valid_kinds;
316
    return \@all_valid_kinds;
317
}
317
}
318
318
319
=head3 config
320
321
Return the configuration options needed for the Circulations Triggers Vue app
322
323
=cut
324
325
sub config {
326
    my $c = shift->openapi->valid_input or return;
327
328
    my $patron      = $c->stash('koha.user');
329
    my $userflags   = C4::Auth::haspermission( $patron->userid );
330
    my $permissions = Koha::Auth::Permissions->get_authz_from_flags( { flags => $userflags } );
331
332
    return $c->render(
333
        status  => 200,
334
        openapi => {
335
            permissions => $permissions,
336
        },
337
    );
338
}
339
319
1;
340
1;
(-)a/api/v1/swagger/definitions/circulation_rules_config.yaml (+7 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  permissions:
5
    type: object
6
    description: List of permissions for the user
7
additionalProperties: false
(-)a/api/v1/swagger/paths/circulation_rules_config.yaml (+39 lines)
Line 0 Link Here
1
---
2
/circulation_rules/config:
3
  get:
4
    x-mojo-to: CirculationRules#config
5
    operationId: getCirculationRulesConfig
6
    description: This resource returns a list of options needed for the Circulation Triggers Vue app
7
    summary: get the CirculationRules config
8
    tags:
9
      - circulation_rules_config
10
    produces:
11
      - application/json
12
    responses:
13
      200:
14
        description: The Circulation Rules config
15
        schema:
16
          $ref: "../swagger.yaml#/definitions/circulation_rules_config"
17
      400:
18
        description: Bad request
19
        schema:
20
          $ref: "../swagger.yaml#/definitions/error"
21
      403:
22
        description: Access forbidden
23
        schema:
24
          $ref: "../swagger.yaml#/definitions/error"
25
      500:
26
        description: |
27
          Internal server error. Possible `error_code` attribute values:
28
29
          * `internal_server_error`
30
        schema:
31
          $ref: "../swagger.yaml#/definitions/error"
32
      503:
33
        description: Under maintenance
34
        schema:
35
          $ref: "../swagger.yaml#/definitions/error"
36
    x-koha-authorization:
37
      permissions:
38
        - acquisition: '*'
39
        - erm: 1
(-)a/api/v1/swagger/swagger.yaml (+7 lines)
Lines 16-21 definitions: Link Here
16
    $ref: ./definitions/authorised_value_category.yaml
16
    $ref: ./definitions/authorised_value_category.yaml
17
  circulation_rules:
17
  circulation_rules:
18
    $ref: ./definitions/circulation_rules.yaml
18
    $ref: ./definitions/circulation_rules.yaml
19
  circulation_rules_config:
20
    $ref: ./definitions/circulation_rules_config.yaml
19
  identity_provider:
21
  identity_provider:
20
    $ref: ./definitions/identity_provider.yaml
22
    $ref: ./definitions/identity_provider.yaml
21
  identity_provider_domain:
23
  identity_provider_domain:
Lines 323-328 paths: Link Here
323
    $ref: ./paths/circulation_rules.yaml#/~1circulation_rules
325
    $ref: ./paths/circulation_rules.yaml#/~1circulation_rules
324
  /circulation_rules/kinds:
326
  /circulation_rules/kinds:
325
    $ref: ./paths/circulation_rules.yaml#/~1circulation_rules~1kinds
327
    $ref: ./paths/circulation_rules.yaml#/~1circulation_rules~1kinds
328
  /circulation_rules/config:
329
    $ref: ./paths/circulation_rules_config.yaml#/~1circulation_rules~1config 
326
  /cities:
330
  /cities:
327
    $ref: ./paths/cities.yaml#/~1cities
331
    $ref: ./paths/cities.yaml#/~1cities
328
  "/cities/{city_id}":
332
  "/cities/{city_id}":
Lines 1239-1244 tags: Link Here
1239
  - description: "Manage circulation rules\n"
1243
  - description: "Manage circulation rules\n"
1240
    name: circulation_rules
1244
    name: circulation_rules
1241
    x-displayName: Circulation rules
1245
    x-displayName: Circulation rules
1246
  - description: "Retrieve configuration relevant to circulation rules\n"
1247
    name: circulation_rules_config
1248
    x-displayName: Circulation rules config
1242
  - description: "Manage cities\n"
1249
  - description: "Manage cities\n"
1243
    name: cities
1250
    name: cities
1244
    x-displayName: Cities
1251
    x-displayName: Cities
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (-1 / +1 lines)
Lines 96-102 Link Here
96
                        <dt><a href="/cgi-bin/koha/admin/smart-rules.pl">Circulation and fine rules</a></dt>
96
                        <dt><a href="/cgi-bin/koha/admin/smart-rules.pl">Circulation and fine rules</a></dt>
97
                        <dd>Define circulation and fine rules for combinations of libraries, patron categories, and item types</dd>
97
                        <dd>Define circulation and fine rules for combinations of libraries, patron categories, and item types</dd>
98
                    [% END %]
98
                    [% END %]
99
                    [% IF ( CAN_user_tools_edit_notice_status_triggers ) %]
99
                    [% IF ( CAN_user_parameters_manage_circ_rules ) %]
100
                        <dt><a href="/cgi-bin/koha/admin/circulation_triggers">Circulation triggers</a></dt>
100
                        <dt><a href="/cgi-bin/koha/admin/circulation_triggers">Circulation triggers</a></dt>
101
                        <dd>Define triggers for circulation notices</dd>
101
                        <dd>Define triggers for circulation notices</dd>
102
                    [% END %]
102
                    [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/fetch/circulation-rules-api-client.js (+9 lines)
Lines 5-10 export class CircRuleAPIClient { Link Here
5
        });
5
        });
6
    }
6
    }
7
7
8
    get config() {
9
        return {
10
            getAll: () =>
11
                this.httpClient.get({
12
                    endpoint: "/config",
13
                }),
14
        };
15
    }
16
8
    get circ_rules() {
17
    get circ_rules() {
9
        return {
18
        return {
10
            getAll: (query, params, headers) =>
19
            getAll: (query, params, headers) =>
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Admin/CirculationTriggers/CirculationTriggersList.vue (-1 lines)
Lines 288-294 import { storeToRefs } from "pinia"; Link Here
288
export default {
288
export default {
289
    setup() {
289
    setup() {
290
        const circRulesStore = inject("circRulesStore");
290
        const circRulesStore = inject("circRulesStore");
291
        circRulesStore.init();
292
        const {
291
        const {
293
            updateTriggerCount,
292
            updateTriggerCount,
294
            setAllRawRuleSets,
293
            setAllRawRuleSets,
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Admin/CirculationTriggers/Main.vue (+1 lines)
Lines 29-34 import { inject } from "vue"; Link Here
29
export default {
29
export default {
30
    setup() {
30
    setup() {
31
        const circRulesStore = inject("circRulesStore");
31
        const circRulesStore = inject("circRulesStore");
32
        circRulesStore.init();
32
        letters.unshift({
33
        letters.unshift({
33
            name: "No letter",
34
            name: "No letter",
34
            code: "",
35
            code: "",
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/modules/admin/circulation_triggers.ts (-3 / +27 lines)
Lines 51-57 app.provide("navigationStore", navigationStore); Link Here
51
app.provide("circRulesStore", circRulesStore);
51
app.provide("circRulesStore", circRulesStore);
52
app.mount("#__app");
52
app.mount("#__app");
53
53
54
router.beforeEach(to => {
54
router.beforeEach((to, from, next) => {
55
    navigationStore.$patch({ current: to.matched, params: to.params || {} });
55
    circRulesStore
56
    removeMessages(); // This will actually flag the messages as displayed already
56
        .loadUserPermissions()
57
        .then(() => {
58
            if (
59
                !circRulesStore.isUserPermitted(
60
                    "CAN_user_parameters_manage_circ_rules"
61
                )
62
            ) {
63
                navigationStore.$patch({
64
                    navigationBlocked: true,
65
                    currentPermission: null,
66
                });
67
                removeMessages(); // This will actually flag the messages as displayed already
68
                window.location.href = "/cgi-bin/koha/mainpage.pl";
69
                return;
70
            }
71
            navigationStore.$patch({
72
                current: to.matched,
73
                params: to.params || {},
74
            });
75
            removeMessages(); // This will actually flag the messages as displayed already
76
            next();
77
        })
78
        .catch(() => {
79
            window.location.href = "/cgi-bin/koha/mainpage.pl";
80
        });
57
});
81
});
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/circulation-rules.js (-13 / +34 lines)
Lines 2-17 import { defineStore } from "pinia"; Link Here
2
import { $__ } from "../i18n";
2
import { $__ } from "../i18n";
3
import { APIClient } from "../fetch/api-client.js";
3
import { APIClient } from "../fetch/api-client.js";
4
import { isEqual } from "lodash";
4
import { isEqual } from "lodash";
5
import { permissionsActions } from "../composables/permissions";
6
import { reactive, toRefs } from "vue";
5
7
6
export const useCircRulesStore = defineStore("circRules", {
8
// NOTES ON RULE SETS TYPES
7
    // NOTES ON RULE SETS TYPES
9
// exhaustive:  includes 'pure fallback' rules sets for contexts that no rules match.
8
    // exhaustive:  includes 'pure fallback' rules sets for contexts that no rules match.
10
//              Format: [{overdue_X_<rule_name>: {value: mixed: isFallback: bool}}]
9
    //              Format: [{overdue_X_<rule_name>: {value: mixed: isFallback: bool}}]
11
// effective:   includes sets only for contexts for which one or more rule exists in the db. These sets will include fallbacks.
10
    // effective:   includes sets only for contexts for which one or more rule exists in the db. These sets will include fallbacks.
12
//              Format: [{overdue_X_<rule_name>: <value>}}
11
    //              Format: [{overdue_X_<rule_name>: <value>}}
13
// raw:         includes only the exact sets as they are found in the db
12
    // raw:         includes only the exact sets as they are found in the db
14
//              Format: [{overdue_X_<rule_name>: <value>}}]
13
    //              Format: [{overdue_X_<rule_name>: <value>}}]
15
14
    state: () => ({
16
export const useCircRulesStore = defineStore("circRules", () => {
17
    const store = reactive({
15
        // context
18
        // context
16
        currentLibraryId: "*",
19
        currentLibraryId: "*",
17
        currentPatronCategoryId: null,
20
        currentPatronCategoryId: null,
Lines 21-26 export const useCircRulesStore = defineStore("circRules", { Link Here
21
        itemTypes: [],
24
        itemTypes: [],
22
        libraries: [],
25
        libraries: [],
23
        patronCategories: [],
26
        patronCategories: [],
27
        userPermissions: null,
24
        letters: [],
28
        letters: [],
25
        ruleSuffixes: ["delay", "notice", "mtt", "restrict", "has_rules"],
29
        ruleSuffixes: ["delay", "notice", "mtt", "restrict", "has_rules"],
26
        transportTypes: [
30
        transportTypes: [
Lines 36-49 export const useCircRulesStore = defineStore("circRules", { Link Here
36
        allExhaustiveEffectiveRuleSets: [], // main data set for display all applied rules for current library
40
        allExhaustiveEffectiveRuleSets: [], // main data set for display all applied rules for current library
37
        currentAndDefaultRawRuleSets: [], // data set to identify effective rules from (combines allDefaultLibraryRawRuleSets and allCurrentLibraryRawRuleSets)
41
        currentAndDefaultRawRuleSets: [], // data set to identify effective rules from (combines allDefaultLibraryRawRuleSets and allCurrentLibraryRawRuleSets)
38
        storeInitialized: false,
42
        storeInitialized: false,
39
    }),
43
    });
40
    actions: {
44
45
    const actions = {
41
        // controllers
46
        // controllers
42
        async init() {
47
        async init() {
43
            await this.getItemTypes();
48
            await this.getItemTypes();
44
            await this.getLibraries();
49
            await this.getLibraries();
45
            await this.getPatronCategories();
50
            await this.getPatronCategories();
46
        },
51
        },
52
        async loadUserPermissions() {
53
            if (this.userPermissions !== null) {
54
                return;
55
            }
56
            await this.getConfigurationOptions();
57
        },
47
        // utilities
58
        // utilities
48
        formatTriggerSpecificRuleSetForDisplay(
59
        formatTriggerSpecificRuleSetForDisplay(
49
            context,
60
            context,
Lines 403-408 export const useCircRulesStore = defineStore("circRules", { Link Here
403
                throw e;
414
                throw e;
404
            }
415
            }
405
        },
416
        },
417
        async getConfigurationOptions() {
418
            const client = APIClient.circRule;
419
            const { permissions } = await client.config.getAll();
420
            this.userPermissions = permissions;
421
        },
406
        async getItemTypes() {
422
        async getItemTypes() {
407
            const client = APIClient.item;
423
            const client = APIClient.item;
408
            let itemTypes = [];
424
            let itemTypes = [];
Lines 485-489 export const useCircRulesStore = defineStore("circRules", { Link Here
485
                //TODO: handle e
501
                //TODO: handle e
486
            }
502
            }
487
        },
503
        },
488
    },
504
        ...permissionsActions(store),
505
    };
506
507
    return {
508
        ...toRefs(store),
509
        ...actions,
510
    };
489
});
511
});
490
- 

Return to bug 10190