FIRE-35685: Allow (re-)importing access lists from exported lists in CSV files (or any CSV file containing a UUID column)
parent
f4e30fdd1d
commit
759654adab
|
|
@ -46,6 +46,8 @@
|
|||
#include <map>
|
||||
#include <set>
|
||||
#include <boost/range.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
|
||||
// <FS:ND> Suppress warnings about the string fiddling
|
||||
#if LL_LINUX
|
||||
|
|
@ -205,6 +207,39 @@ std::string ll_stream_notation_sd(const LLSD& sd)
|
|||
return stream.str();
|
||||
}
|
||||
|
||||
// <FS:Ansariel> Create LLSD from CSV
|
||||
LLSD ll_sd_from_csv(std::istream& csv, std::string_view delimiters)
|
||||
{
|
||||
LLSD data;
|
||||
bool headerRead{ false };
|
||||
std::vector<std::string> columnNames;
|
||||
std::string line;
|
||||
|
||||
while (std::getline(csv, line))
|
||||
{
|
||||
std::vector<std::string> columns;
|
||||
boost::split(columns, line, boost::is_any_of(delimiters));
|
||||
|
||||
if (!headerRead)
|
||||
{
|
||||
headerRead = true;
|
||||
columnNames = std::move(columns);
|
||||
}
|
||||
else
|
||||
{
|
||||
LLSD rowData;
|
||||
for (size_t i = 0; i < columnNames.size() && i < columns.size(); ++i)
|
||||
{
|
||||
rowData[columnNames.at(i)] = columns.at(i);
|
||||
}
|
||||
|
||||
data.append(rowData);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
// </FS:Ansariel>
|
||||
|
||||
//compares the structure of an LLSD to a template LLSD and stores the
|
||||
//"valid" values in a 3rd LLSD. Default values pulled from the template
|
||||
|
|
|
|||
|
|
@ -65,6 +65,9 @@ LL_COMMON_API char* ll_pretty_print_sd(const LLSD& sd);
|
|||
|
||||
LL_COMMON_API std::string ll_stream_notation_sd(const LLSD& sd);
|
||||
|
||||
// <FS:Ansariel> Create LLSD from CSV
|
||||
LL_COMMON_API LLSD ll_sd_from_csv(std::istream& csv, std::string_view delimiters = ",");
|
||||
|
||||
//compares the structure of an LLSD to a template LLSD and stores the
|
||||
//"valid" values in a 3rd LLSD. Default values
|
||||
//are pulled from the template. Extra keys/values in the test
|
||||
|
|
|
|||
|
|
@ -431,7 +431,7 @@ bool LLScrollListCtrl::setMaxItemCount(S32 max_count)
|
|||
}
|
||||
|
||||
// <FS:PP>
|
||||
S32 LLScrollListCtrl::getMaxItemCount()
|
||||
S32 LLScrollListCtrl::getMaxItemCount() const
|
||||
{
|
||||
return mMaxItemCount;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ public:
|
|||
|
||||
// returns false if unable to set the max count so low
|
||||
bool setMaxItemCount(S32 max_count);
|
||||
S32 getMaxItemCount(); // <FS:PP>
|
||||
S32 getMaxItemCount() const; // <FS:PP>
|
||||
|
||||
bool selectByID( const LLUUID& id ); // false if item not found
|
||||
|
||||
|
|
|
|||
|
|
@ -3395,24 +3395,19 @@ void LLPanelLandAccess::importListCallback(LLNameListCtrl* list, const std::vect
|
|||
return;
|
||||
}
|
||||
|
||||
std::string line;
|
||||
std::vector<LLUUID> uuids;
|
||||
uuid_vec_t uuids;
|
||||
LLSD csvData = ll_sd_from_csv(file);
|
||||
file.close();
|
||||
|
||||
while (std::getline(file, line))
|
||||
for (const auto& entry : llsd::inArray(csvData))
|
||||
{
|
||||
LLStringUtil::trim(line);
|
||||
if (line.empty())
|
||||
if (entry.has("UUID"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
LLUUID uuid;
|
||||
if (uuid.set(line))
|
||||
{
|
||||
uuids.push_back(uuid);
|
||||
LLUUID id{ entry["UUID"].asUUID() };
|
||||
if (id.notNull())
|
||||
uuids.push_back(std::move(id));
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
|
||||
if (uuids.empty())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4767,24 +4767,19 @@ void LLPanelEstateAccess::importListCallback(LLNameListCtrl* list, const std::ve
|
|||
return;
|
||||
}
|
||||
|
||||
std::string line;
|
||||
std::vector<LLUUID> uuids;
|
||||
uuid_vec_t uuids;
|
||||
LLSD csvData = ll_sd_from_csv(file);
|
||||
file.close();
|
||||
|
||||
while (std::getline(file, line))
|
||||
for (const auto& entry : llsd::inArray(csvData))
|
||||
{
|
||||
LLStringUtil::trim(line);
|
||||
if (line.empty())
|
||||
if (entry.has("UUID"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
LLUUID uuid;
|
||||
if (uuid.set(line))
|
||||
{
|
||||
uuids.push_back(uuid);
|
||||
LLUUID id{ entry["UUID"].asUUID() };
|
||||
if (id.notNull())
|
||||
uuids.push_back(std::move(id));
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
|
||||
if (uuids.empty())
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue