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

(-)a/Koha/Schema/Result/ApiKey.pm (-32 / +12 lines)
Lines 23-40 __PACKAGE__->table("api_keys"); Link Here
23
23
24
=head1 ACCESSORS
24
=head1 ACCESSORS
25
25
26
=head2 id
27
28
  data_type: 'integer'
29
  is_auto_increment: 1
30
  is_nullable: 0
31
32
=head2 patron_id
33
34
  data_type: 'integer'
35
  is_foreign_key: 1
36
  is_nullable: 0
37
38
=head2 client_id
26
=head2 client_id
39
27
40
  data_type: 'varchar'
28
  data_type: 'varchar'
Lines 53-58 __PACKAGE__->table("api_keys"); Link Here
53
  is_nullable: 0
41
  is_nullable: 0
54
  size: 255
42
  size: 255
55
43
44
=head2 patron_id
45
46
  data_type: 'integer'
47
  is_foreign_key: 1
48
  is_nullable: 0
49
56
=head2 active
50
=head2 active
57
51
58
  data_type: 'tinyint'
52
  data_type: 'tinyint'
Lines 62-77 __PACKAGE__->table("api_keys"); Link Here
62
=cut
56
=cut
63
57
64
__PACKAGE__->add_columns(
58
__PACKAGE__->add_columns(
65
  "id",
66
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
67
  "patron_id",
68
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
69
  "client_id",
59
  "client_id",
70
  { data_type => "varchar", is_nullable => 0, size => 191 },
60
  { data_type => "varchar", is_nullable => 0, size => 191 },
71
  "secret",
61
  "secret",
72
  { data_type => "varchar", is_nullable => 0, size => 191 },
62
  { data_type => "varchar", is_nullable => 0, size => 191 },
73
  "description",
63
  "description",
74
  { data_type => "varchar", is_nullable => 0, size => 255 },
64
  { data_type => "varchar", is_nullable => 0, size => 255 },
65
  "patron_id",
66
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
75
  "active",
67
  "active",
76
  { data_type => "tinyint", default_value => 1, is_nullable => 0 },
68
  { data_type => "tinyint", default_value => 1, is_nullable => 0 },
77
);
69
);
Lines 80-107 __PACKAGE__->add_columns( Link Here
80
72
81
=over 4
73
=over 4
82
74
83
=item * L</id>
75
=item * L</client_id>
84
76
85
=back
77
=back
86
78
87
=cut
79
=cut
88
80
89
__PACKAGE__->set_primary_key("id");
81
__PACKAGE__->set_primary_key("client_id");
90
82
91
=head1 UNIQUE CONSTRAINTS
83
=head1 UNIQUE CONSTRAINTS
92
84
93
=head2 C<client_id>
94
95
=over 4
96
97
=item * L</client_id>
98
99
=back
100
101
=cut
102
103
__PACKAGE__->add_unique_constraint("client_id", ["client_id"]);
104
105
=head2 C<secret>
85
=head2 C<secret>
106
86
107
=over 4
87
=over 4
Lines 132-139 __PACKAGE__->belongs_to( Link Here
132
);
112
);
133
113
134
114
135
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-04-14 00:56:23
115
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-04-14 14:48:10
136
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:b7AUAgl2SClXJ2lzPVV0FA
116
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:qnu4QSACpOSQaZgd52ozmw
137
117
138
__PACKAGE__->add_columns(
118
__PACKAGE__->add_columns(
139
    '+active' => { is_boolean => 1 }
119
    '+active' => { is_boolean => 1 }
(-)a/installer/data/mysql/atomicupdate/bug_20568_api_keys.perl (-4 / +2 lines)
Lines 4-17 if(CheckVersion($DBversion)) { Link Here
4
    if (!TableExists('api_keys')) {
4
    if (!TableExists('api_keys')) {
5
        $dbh->do(q{
5
        $dbh->do(q{
6
            CREATE TABLE `api_keys` (
6
            CREATE TABLE `api_keys` (
7
                `id`          INT(11) NOT NULL AUTO_INCREMENT,
8
                `patron_id`   INT(11) NOT NULL,
9
                `client_id`   VARCHAR(191) NOT NULL,
7
                `client_id`   VARCHAR(191) NOT NULL,
10
                `secret`      VARCHAR(191) NOT NULL,
8
                `secret`      VARCHAR(191) NOT NULL,
11
                `description` VARCHAR(255) NOT NULL,
9
                `description` VARCHAR(255) NOT NULL,
10
                `patron_id`   INT(11) NOT NULL,
12
                `active`      TINYINT(1) DEFAULT 1 NOT NULL,
11
                `active`      TINYINT(1) DEFAULT 1 NOT NULL,
13
                PRIMARY KEY (`id`),
12
                PRIMARY KEY `client_id` (`client_id`),
14
                UNIQUE KEY `client_id` (`client_id`),
15
                UNIQUE KEY `secret` (`secret`),
13
                UNIQUE KEY `secret` (`secret`),
16
                KEY `patron_id` (`patron_id`),
14
                KEY `patron_id` (`patron_id`),
17
                CONSTRAINT `api_keys_fk_patron_id`
15
                CONSTRAINT `api_keys_fk_patron_id`
(-)a/installer/data/mysql/kohastructure.sql (-5 / +3 lines)
Lines 1719-1734 CREATE TABLE borrower_sync ( Link Here
1719
1719
1720
DROP TABLE IF EXISTS `api_keys`;
1720
DROP TABLE IF EXISTS `api_keys`;
1721
CREATE TABLE `api_keys` (
1721
CREATE TABLE `api_keys` (
1722
    `id`          INT(11) NOT NULL AUTO_INCREMENT, -- API key internal identifier
1723
    `patron_id`   INT(11) NOT NULL,                -- Foreign key to the borrowers table
1724
    `client_id`   VARCHAR(191) NOT NULL,           -- API client ID
1722
    `client_id`   VARCHAR(191) NOT NULL,           -- API client ID
1725
    `secret`      VARCHAR(191) NOT NULL,           -- API client secret used for API authentication
1723
    `secret`      VARCHAR(191) NOT NULL,           -- API client secret used for API authentication
1726
    `description` VARCHAR(255) NOT NULL,           -- API client description
1724
    `description` VARCHAR(255) NOT NULL,           -- API client description
1725
    `patron_id`   INT(11) NOT NULL,                -- Foreign key to the borrowers table
1727
    `active`      TINYINT(1) DEFAULT 1 NOT NULL,   -- 0 means this API key is revoked
1726
    `active`      TINYINT(1) DEFAULT 1 NOT NULL,   -- 0 means this API key is revoked
1728
    PRIMARY KEY (`id`),
1727
    PRIMARY KEY `client_id` (`client_id`),
1729
    KEY `patron_id` (`patron_id`),
1730
    UNIQUE KEY `client_id` (`client_id`),
1731
    UNIQUE KEY `secret` (`secret`),
1728
    UNIQUE KEY `secret` (`secret`),
1729
    KEY `patron_id` (`patron_id`),
1732
    CONSTRAINT `api_keys_fk_patron_id`
1730
    CONSTRAINT `api_keys_fk_patron_id`
1733
      FOREIGN KEY (`patron_id`)
1731
      FOREIGN KEY (`patron_id`)
1734
      REFERENCES `borrowers` (`borrowernumber`)
1732
      REFERENCES `borrowers` (`borrowernumber`)
(-)a/members/apikeys.pl (-3 / +3 lines)
Lines 68-74 if ($op) { Link Here
68
68
69
    if ( $op eq 'delete' ) {
69
    if ( $op eq 'delete' ) {
70
        my $api_key_id = $cgi->param('key');
70
        my $api_key_id = $cgi->param('key');
71
        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $api_key_id });
71
        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, client_id => $api_key_id });
72
        if ($key) {
72
        if ($key) {
73
            $key->delete;
73
            $key->delete;
74
        }
74
        }
Lines 78-84 if ($op) { Link Here
78
78
79
    if ( $op eq 'revoke' ) {
79
    if ( $op eq 'revoke' ) {
80
        my $api_key_id = $cgi->param('key');
80
        my $api_key_id = $cgi->param('key');
81
        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $api_key_id });
81
        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, client_id => $api_key_id });
82
        if ($key) {
82
        if ($key) {
83
            $key->active(0);
83
            $key->active(0);
84
            $key->store;
84
            $key->store;
Lines 89-95 if ($op) { Link Here
89
89
90
    if ( $op eq 'activate' ) {
90
    if ( $op eq 'activate' ) {
91
        my $api_key_id = $cgi->param('key');
91
        my $api_key_id = $cgi->param('key');
92
        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $api_key_id });
92
        my $key = Koha::ApiKeys->find({ patron_id => $patron_id, client_id => $api_key_id });
93
        if ($key) {
93
        if ($key) {
94
            $key->active(1);
94
            $key->active(1);
95
            $key->store;
95
            $key->store;
(-)a/opac/opac-apikeys.pl (-4 / +3 lines)
Lines 63-69 if ($op) { Link Here
63
63
64
    if ($op eq 'delete') {
64
    if ($op eq 'delete') {
65
        my $key_id  = $cgi->param('key');
65
        my $key_id  = $cgi->param('key');
66
        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $key_id });
66
        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, client_id => $key_id });
67
        if ($api_key) {
67
        if ($api_key) {
68
            $api_key->delete;
68
            $api_key->delete;
69
        }
69
        }
Lines 73-79 if ($op) { Link Here
73
73
74
    if ($op eq 'revoke') {
74
    if ($op eq 'revoke') {
75
        my $key_id  = $cgi->param('key');
75
        my $key_id  = $cgi->param('key');
76
        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $key_id });
76
        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, client_id => $key_id });
77
        if ($api_key) {
77
        if ($api_key) {
78
            $api_key->active(0);
78
            $api_key->active(0);
79
            $api_key->store;
79
            $api_key->store;
Lines 84-90 if ($op) { Link Here
84
84
85
    if ($op eq 'activate') {
85
    if ($op eq 'activate') {
86
        my $key_id  = $cgi->param('key');
86
        my $key_id  = $cgi->param('key');
87
        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, id => $key_id });
87
        my $api_key = Koha::ApiKeys->find({ patron_id => $patron_id, client_id => $key_id });
88
        if ($api_key) {
88
        if ($api_key) {
89
            $api_key->active(1);
89
            $api_key->active(1);
90
            $api_key->store;
90
            $api_key->store;
91
- 

Return to bug 20568