1 module vibelog.config;
2 
3 import vibe.data.bson;
4 
5 class Config {
6 	BsonObjectID id;
7 	string name;
8 	string[] categories;
9 	string language = "en-us";
10 	string copyrightString;
11 	string mailServer;
12 	string feedTitle;
13 	string feedLink;
14 	string feedDescription;
15 	string feedImageTitle;
16 	string feedImageUrl;
17 
18 	this()
19 	{
20 		id  = BsonObjectID.generate();
21 	}
22 
23 	@property string[] groups() const { return ["admin"]; }
24 
25 	bool hasCategory(string cat) const {
26 		foreach( c; categories )
27 			if( c == cat )
28 				return true;
29 		return false;
30 	}
31 
32 	static Config fromBson(Bson bson)
33 	{
34 		auto ret = new Config;
35 		ret.id = bson["_id"].opt!BsonObjectID();
36 		ret.name = bson["name"].opt!string();
37 		foreach( grp; cast(Bson[])bson["categories"] )
38 			ret.categories ~= grp.opt!string();
39 		ret.language = bson["language"].opt!string("en-us");
40 		ret.copyrightString = bson["copyrightString"].opt!string();
41 		ret.mailServer = bson["mailServer"].opt!string();
42 		ret.feedTitle = bson["feedTitle"].opt!string();
43 		ret.feedLink = bson["feedLink"].opt!string();
44 		ret.feedDescription = bson["feedDescription"].opt!string();
45 		ret.feedImageTitle = bson["feedImageTitle"].opt!string();
46 		ret.feedImageUrl = bson["feedImageUrl"].opt!string();
47 		return ret;
48 	}
49 	
50 	Bson toBson()
51 	const {
52 		Bson[] bcategories;
53 		foreach( grp; categories )
54 			bcategories ~= Bson(grp);
55 
56 		Bson[string] ret;
57 		ret["_id"] = Bson(id);
58 		ret["name"] = Bson(name);
59 		ret["categories"] = Bson(bcategories);
60 		ret["language"] = Bson(language);
61 		ret["copyrightString"] = Bson(copyrightString);
62 		ret["mailServer"] = Bson(mailServer);
63 		ret["feedTitle"] = Bson(feedTitle);
64 		ret["feedLink"] = Bson(feedLink);
65 		ret["feedDescription"] = Bson(feedDescription);
66 		ret["feedImageTitle"] = Bson(feedImageTitle);
67 		ret["feedImageUrl"] = Bson(feedImageUrl);
68 
69 		return Bson(ret);
70 	}
71 }