Changeset 2094


Ignore:
Timestamp:
09/19/17 19:34:41 (7 years ago)
Author:
nanardon
Message:

Allow to set allowed_values insde database instead config, this work only for SQL base

Location:
trunk/LATMOS-Accounts
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/Changes

    r2071 r2094  
     15.2.20 
     2    - Allow to limit attribute value from database settings 
     3    - Make netZone attribute for nethost searchable 
     4 
    155.2.19 
    26    - Allow to use a specific cracklib dictionnary  
  • trunk/LATMOS-Accounts/MANIFEST

    r2083 r2094  
    2828bin/la-search 
    2929bin/la-sql-alias 
     30bin/la-sql-attrvalues 
    3031bin/la-sql-crypt-passwd 
    3132bin/la-sql-edit-form 
  • trunk/LATMOS-Accounts/Makefile.PL

    r2083 r2094  
    8787        bin/la-renewEmp 
    8888        bin/la-load-csv 
     89        bin/la-sql-attrvalues 
    8990        ) ], 
    9091        macro => { 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm

    r2083 r2094  
    1818our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; 
    1919 
    20 sub SCHEMA_VERSION { 26 }; 
     20sub SCHEMA_VERSION { 28 }; 
    2121 
    2222=head1 NAME 
     
    796796=head1 ATTRIBUTES FUNCTIONS 
    797797 
     798=cut 
     799 
     800sub obj_attr_allowed_values { 
     801    my ($self, $otype, $attr) = @_; 
     802    if (my @values = $self->SUPER::obj_attr_allowed_values("$otype.$attr", 'allowed')) { 
     803        return @values; 
     804    } else { 
     805        $self->ListAttrValue($otype, $attr); 
     806    } 
     807} 
     808 
     809=head2 ListAttrValue($otype, $attribute) 
     810 
     811List values allow for an attribute set into SQL database 
     812 
     813=cut 
     814 
     815sub ListAttrValue { 
     816    my ($self, $otype, $attr) = @_; 
     817 
     818    my @sqlvalues; 
     819    my $getAllow = $self->db->prepare_cached(q{ 
     820        SELECT * FROM attributes_values WHERE otype = ? AND attributes = ? 
     821        ORDER BY "value" 
     822    }); 
     823    $getAllow->execute($otype, $attr); 
     824    while (my $res = $getAllow->fetchrow_hashref) { 
     825        push(@sqlvalues, $res->{value}); 
     826    } 
     827    return @sqlvalues; 
     828} 
     829 
     830=head2 AddAttrValue($otype, $attr, @values) 
     831 
     832Add given values to allowed attribute list 
     833 
     834=cut 
     835 
     836sub AddAttrValue { 
     837    my ($self, $otype, $attr, @values) = @_; 
     838     
     839    my $addAllow = $self->db->prepare_cached(q{ 
     840        INSERT INTO attributes_values (otype, attributes, "value") values (?,?,?) 
     841    }); 
     842     
     843    foreach my $value (@values) { 
     844        if ($addAllow->execute($otype, $attr, $value)) { 
     845        } else { 
     846            $self->rollback; 
     847            return; 
     848        } 
     849    } 
     850 
     851    return 1; 
     852} 
     853 
     854=head2 DelAttrValue 
     855 
     856Delete a 
     857 
     858=cut 
     859 
     860sub DelAttrValue { 
     861    my ($self, $otype, $attr, @values) = @_; 
     862 
     863    if (@values) { 
     864        my $delAllow = $self->db->prepare_cached(q{ 
     865            DELETE FROM attributes_values WHERE otype = ? and attributes = ? and "value" = ? 
     866        }); 
     867 
     868        foreach my $value (@values) { 
     869 
     870            if ($delAllow->execute($otype, $attr, $value)) { 
     871            } else { 
     872                $self->rollback; 
     873                return; 
     874            } 
     875 
     876        } 
     877        return 1; 
     878    } else { 
     879        my $delAllow = $self->db->prepare_cached(q{ 
     880            DELETE FROM attributes_values WHERE otype = ? and attributes = ? 
     881        }); 
     882        if ($delAllow->execute($otype, $attr)) { 
     883            return 1; 
     884        } else { 
     885            $self->rollback; 
     886            return; 
     887        } 
     888    } 
     889} 
     890 
    798891=head2 register_attribute ($otype, $attribute, $comment) 
    799892 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/upgrade.pm

    r2090 r2094  
    11371137                } 
    11381138            ], 
    1139         } 
     1139        }, 
     1140        { 
     1141            ver => 28, 
     1142            sql => [ 
     1143                q{ 
     1144                CREATE TABLE attributes_values 
     1145                ( 
     1146                -- Hérité(e) from table revisions:  rev integer NOT NULL DEFAULT nextval('revisions_rev_seq'::regclass), 
     1147                -- Hérité(e) from table revisions:  date timestamp with time zone NOT NULL DEFAULT now(), 
     1148                -- Hérité(e) from table revisions:  "create" timestamp with time zone NOT NULL DEFAULT now(), 
     1149                -- Hérité(e) from table revisions:  ikey integer NOT NULL DEFAULT nextval('ikey_seq'::regclass), 
     1150                otype text NOT NULL, 
     1151                attributes text NOT NULL, 
     1152                value text NOT NULL, 
     1153                CONSTRAINT attributes_values_pkey PRIMARY KEY (ikey) 
     1154                ) 
     1155                INHERITS (revisions) 
     1156                ); 
     1157 
     1158                CREATE UNIQUE INDEX attributes_values_idx 
     1159                ON attributes_values 
     1160                USING btree 
     1161                (otype, attributes, value); 
     1162                } 
     1163            ] 
     1164        }; 
    11401165    ); 
    11411166 
Note: See TracChangeset for help on using the changeset viewer.