@@ -312,13 +312,14 @@ inline void write_element<relation>(const relation &r, output_formatter &formatt
312
312
}
313
313
314
314
struct static_data_selection : public data_selection {
315
- explicit static_data_selection (database& db) : static_data_selection(db, {}) {}
315
+ explicit static_data_selection (database& db) : static_data_selection(db, {}, {} ) {}
316
316
317
- explicit static_data_selection (database& db, user_roles_t m_user_roles)
317
+ explicit static_data_selection (database& db, user_roles_t m_user_roles, oauth2_tokens m_oauth2_tokens )
318
318
: m_db(db)
319
319
, m_include_changeset_comments(false )
320
320
, m_redactions_visible(false )
321
- , m_user_roles(m_user_roles) {}
321
+ , m_user_roles(m_user_roles)
322
+ , m_oauth2_tokens(m_oauth2_tokens){}
322
323
323
324
~static_data_selection () override = default ;
324
325
@@ -591,6 +592,16 @@ struct static_data_selection : public data_selection {
591
592
std::optional< osm_user_id_t > get_user_id_for_oauth2_token (
592
593
const std::string &token_id, bool &expired, bool &revoked,
593
594
bool &allow_api_write) {
595
+
596
+ auto itr = m_oauth2_tokens.find (token_id);
597
+ if (itr != m_oauth2_tokens.end ())
598
+ {
599
+ expired = itr->second .expired ;
600
+ revoked = itr->second .revoked ;
601
+ allow_api_write = itr->second .api_write ;
602
+ return itr->second .user_id ;
603
+ }
604
+
594
605
expired = false ;
595
606
revoked = false ;
596
607
allow_api_write = false ;
@@ -751,6 +762,7 @@ struct static_data_selection : public data_selection {
751
762
std::set<osm_edition_t > m_historic_nodes, m_historic_ways, m_historic_relations;
752
763
bool m_include_changeset_comments, m_redactions_visible;
753
764
user_roles_t m_user_roles;
765
+ oauth2_tokens m_oauth2_tokens;
754
766
};
755
767
756
768
template <>
@@ -769,16 +781,17 @@ const std::map<id_version, relation> &static_data_selection::map_of<relation>()
769
781
}
770
782
771
783
struct factory : public data_selection ::factory {
772
- explicit factory (const std::string &file) : factory(file, {}) {}
784
+ explicit factory (const std::string &file) : factory(file, {}, {} ) {}
773
785
774
- explicit factory (const std::string &file, user_roles_t user_roles)
775
- : m_database(parse_xml(file.c_str())),
776
- m_user_roles(user_roles) {}
786
+ explicit factory (const std::string &file, user_roles_t user_roles, oauth2_tokens oauth2_tokens)
787
+ : m_database(parse_xml(file.c_str()))
788
+ , m_user_roles(user_roles)
789
+ , m_oauth2_tokens(oauth2_tokens) {}
777
790
778
791
~factory () override = default ;
779
792
780
793
std::unique_ptr<data_selection> make_selection (Transaction_Owner_Base&) const override {
781
- return std::make_unique<static_data_selection>(*m_database, m_user_roles);
794
+ return std::make_unique<static_data_selection>(*m_database, m_user_roles, m_oauth2_tokens );
782
795
}
783
796
784
797
std::unique_ptr<Transaction_Owner_Base> get_default_transaction () override {
@@ -788,15 +801,17 @@ struct factory : public data_selection::factory {
788
801
private:
789
802
std::unique_ptr<database> m_database;
790
803
user_roles_t m_user_roles;
804
+ oauth2_tokens m_oauth2_tokens;
791
805
};
792
806
793
807
struct staticxml_backend : public backend {
794
- staticxml_backend () : staticxml_backend(user_roles_t {}) {}
808
+ staticxml_backend () : staticxml_backend(user_roles_t {}, oauth2_tokens{} ) {}
795
809
796
- staticxml_backend (user_roles_t user_roles) {
810
+ staticxml_backend (user_roles_t user_roles, oauth2_tokens oauth2_tokens ) {
797
811
m_options.add_options ()(" file" , po::value<std::string>()->required (),
798
812
" file to load static OSM XML from." );
799
813
m_user_roles = user_roles;
814
+ m_oauth2_tokens = oauth2_tokens;
800
815
}
801
816
802
817
~staticxml_backend () override = default ;
@@ -806,7 +821,7 @@ struct staticxml_backend : public backend {
806
821
807
822
std::unique_ptr<data_selection::factory> create (const po::variables_map &opts) override {
808
823
std::string file = opts[" file" ].as <std::string>();
809
- return std::make_unique<factory>(file, m_user_roles);
824
+ return std::make_unique<factory>(file, m_user_roles, m_oauth2_tokens );
810
825
}
811
826
812
827
std::unique_ptr<data_update::factory> create_data_update (const po::variables_map &) override {
@@ -817,11 +832,12 @@ struct staticxml_backend : public backend {
817
832
std::string m_name{" staticxml" };
818
833
po::options_description m_options{" Static XML backend options" };
819
834
user_roles_t m_user_roles;
835
+ oauth2_tokens m_oauth2_tokens;
820
836
};
821
837
822
838
} // anonymous namespace
823
839
824
840
825
- std::unique_ptr<backend> make_staticxml_backend (user_roles_t user_roles) {
826
- return std::make_unique<staticxml_backend>(user_roles);
841
+ std::unique_ptr<backend> make_staticxml_backend (user_roles_t user_roles, oauth2_tokens oauth2_tokens ) {
842
+ return std::make_unique<staticxml_backend>(user_roles, oauth2_tokens );
827
843
}
0 commit comments