jmueller17 / Aixada

Aixada helps self-managed consumption cooperatives to organize their flow of products, money, and information.
Other
33 stars 37 forks source link

Filtrar llista proveïdors a manage_providers.php segons responsible_uf_id #282

Open joancortes opened 3 years ago

joancortes commented 3 years ago

Hola,

Estem adaptant l'Aixada al funcionament del nostre grup de consum de Llagostera, on cada membre assumeix la gestió de cada proveïdor. He trobat la manera de filtrar el llistat de proveïdors que es mostra a manage_providers.php perquè només es mostrin aquells proveïdors dels quals n'és responsable la UF que ha iniciat la sessió, però que no es filtri quan estigui el rol de caixa o hacker actiu. Aquí va la proposta.

Creo un nou procediment SQL:

create procedure get_provider_listing_resp_uf(in the_provider_id int, in include_inactive boolean, in resp_uf int)

begin
    declare wherec varchar(255) default "";

    -- show all providers including inactive or just active ones -- 
    set wherec = if(include_inactive=1,"","and pv.active = 1"); 

    -- filter for specific provider --
    if the_provider_id > 0 then
        set wherec = concat(wherec," and pv.id=",the_provider_id);
    end if;

             -- filter for responsible uf --
    if resp_uf_id > 0 then
        set wherec = concat(wherec," and uf.id=",resp_uf_id);
    end if;

    set @q = concat("select pv.*, uf.id as responsible_uf_id, uf.name as responsible_uf_name from aixada_provider pv, aixada_uf uf where pv.responsible_uf_id = uf.id",wherec,"order by pv.name, pv.id;");

    prepare st from @q;
    execute st;
     deallocate prepare st;

end|

A config.php, afegeixo: // Providers management rights // 0 is rights on all, 1 in only providers where the user is responsible public $rights_on_all_providers = array( 'Consumer' => 1, 'Checkout' => 0, 'Consumer Commission' => 1, 'Econo-Legal Commission' => 1, 'Logistic Commission' => 1, 'Hacker Commission' => 0, 'Fifth Column Commission' => 1, 'Producer' => 1 );

A Providers.php, modifico el switch amb : case 'getProviders': printXML(stored_query_XML_fields('get_provider_listing_resp_uf', get_param('provider_id',0), get_param('all',0), get_session_value('uf_id')*get_config('rights_on_all_providers')[get_current_role()])); exit;

No sé si és molt barroera la solució, però funciona.

jorix commented 3 years ago

@joancortes

A mi em sembla una solució correcta.
(vaig pensar, ja m'ho mirare però ja no hi havia pensat més)

Per mirar coses així és més aclaridor fer una branca i posar-hi els commits.

NOTA: El nom $rights_on_all_providers és just al contrari del que hom pensaria que vol dir.