Changeset - 6e1af765cdc0
[Not reviewed]
0 6 0
Jan Kaluza - 9 years ago 2016-03-06 14:50:05
jkaluza@redhat.com
AdminInterface: Support labels for commands
6 files changed with 35 insertions and 17 deletions:
0 comments (0 inline, 0 general)
include/transport/AdminInterfaceCommand.h
Show inline comments
 
@@ -66,13 +66,13 @@ class AdminInterfaceCommand {
 

	
 
				std::string name;
 
				std::string label;
 
				std::string example;
 
		};
 

	
 
		AdminInterfaceCommand(const std::string &name, Category category, Context context, AccessMode accessMode, Actions actions);
 
		AdminInterfaceCommand(const std::string &name, Category category, Context context, AccessMode accessMode, Actions actions, const std::string &label = "");
 

	
 
		virtual ~AdminInterfaceCommand() { }
 

	
 
		void setDescription(const std::string &desc) {
 
			m_desc = desc;
 
		}
 
@@ -109,21 +109,26 @@ class AdminInterfaceCommand {
 
		}
 

	
 
		const std::list<Arg> &getArgs() {
 
			return m_args;
 
		}
 

	
 
		const std::string &getLabel() {
 
			return m_label;
 
		}
 

	
 
		virtual std::string handleSetRequest(UserInfo &uinfo, User *user, std::vector<std::string> &args);
 
		virtual std::string handleGetRequest(UserInfo &uinfo, User *user, std::vector<std::string> &args);
 
		virtual std::string handleExecuteRequest(UserInfo &uinfo, User *user, std::vector<std::string> &args);
 

	
 
	private:
 
		std::string m_name;
 
		Category m_category;
 
		Context m_context;
 
		AccessMode m_accessMode;
 
		Actions m_actions;
 
		std::string m_desc;
 
		std::list<Arg> m_args;
 
		std::string m_label;
 
};
 

	
 
}
libtransport/AdminInterface.cpp
Show inline comments
 
@@ -244,13 +244,14 @@ class ReloadCommand : public AdminInterfaceCommand {
 
	public:
 
		
 
		ReloadCommand(Component *component) : AdminInterfaceCommand("reload",
 
							AdminInterfaceCommand::General,
 
							AdminInterfaceCommand::GlobalContext,
 
							AdminInterfaceCommand::AdminMode,
 
							AdminInterfaceCommand::Execute) {
 
							AdminInterfaceCommand::Execute,
 
							"Reload Spectrum 2 configuration") {
 
			m_component = component;
 
			setDescription("Reloads config file");
 
		}
 

	
 
		virtual std::string handleExecuteRequest(UserInfo &uinfo, User *user, std::vector<std::string> &args) {
 
			std::string ret = AdminInterfaceCommand::handleExecuteRequest(uinfo, user, args);
 
@@ -275,13 +276,13 @@ class HasOnlineUserCommand : public AdminInterfaceCommand {
 
	public:
 
		
 
		HasOnlineUserCommand(UserManager *userManager) : AdminInterfaceCommand("has_online_user",
 
							AdminInterfaceCommand::Users,
 
							AdminInterfaceCommand::GlobalContext,
 
							AdminInterfaceCommand::AdminMode,
 
							AdminInterfaceCommand::Execute) {
 
							AdminInterfaceCommand::Execute, "Has online user") {
 
			m_userManager = userManager;
 
			setDescription("Returns 1 if user is online");
 
			addArg("username", "Username", "user@domain.tld");
 
		}
 

	
 
		virtual std::string handleExecuteRequest(UserInfo &uinfo, User *user, std::vector<std::string> &args) {
 
@@ -700,13 +701,14 @@ class MessagesToXMPPCommand : public AdminInterfaceCommand {
 
class RegisterCommand : public AdminInterfaceCommand {
 
	public:
 
		RegisterCommand(UserRegistration *userRegistration, Component *component) : AdminInterfaceCommand("register",
 
							AdminInterfaceCommand::Users,
 
							AdminInterfaceCommand::GlobalContext,
 
							AdminInterfaceCommand::UserMode,
 
							AdminInterfaceCommand::Execute) {
 
							AdminInterfaceCommand::Execute,
 
							"Register") {
 
			m_userRegistration = userRegistration;
 
			setDescription("Registers the new user");
 

	
 
			std::string fields = component->getFrontend()->getRegistrationFields();
 
			std::vector<std::string> args;
 
			boost::split(args, fields, boost::is_any_of("\n"));
 
@@ -758,13 +760,14 @@ class UnregisterCommand : public AdminInterfaceCommand {
 
	public:
 
		
 
		UnregisterCommand(UserRegistration *userRegistration, Component *component) : AdminInterfaceCommand("unregister",
 
							AdminInterfaceCommand::Users,
 
							AdminInterfaceCommand::UserContext,
 
							AdminInterfaceCommand::UserMode,
 
							AdminInterfaceCommand::Execute) {
 
							AdminInterfaceCommand::Execute,
 
							"Unregister") {
 
			m_userRegistration = userRegistration;
 
			setDescription("Unregisters existing user");
 

	
 
// 			std::string fields = component->getFrontend()->getRegistrationFields();
 
// 			std::vector<std::string> args;
 
// 			boost::split(args, fields, boost::is_any_of("\n"));
 
@@ -863,13 +866,14 @@ class HelpCommand : public AdminInterfaceCommand {
 
	public:
 
		
 
		HelpCommand(std::map<std::string, AdminInterfaceCommand *> *commands) : AdminInterfaceCommand("help",
 
							AdminInterfaceCommand::General,
 
							AdminInterfaceCommand::GlobalContext,
 
							AdminInterfaceCommand::AdminMode,
 
							AdminInterfaceCommand::Execute) {
 
							AdminInterfaceCommand::Execute,
 
							"Help") {
 
			m_commands = commands;
 
			setDescription("Shows help message");
 
		}
 

	
 
		void generateCategory(AdminInterfaceCommand::Category category, std::string &output) {
 
			output += getCategoryName(category) + ":\n";
 
@@ -917,13 +921,14 @@ class CommandsCommand : public AdminInterfaceCommand {
 
	public:
 
		
 
		CommandsCommand(std::map<std::string, AdminInterfaceCommand *> *commands) : AdminInterfaceCommand("commands",
 
							AdminInterfaceCommand::General,
 
							AdminInterfaceCommand::GlobalContext,
 
							AdminInterfaceCommand::AdminMode,
 
							AdminInterfaceCommand::Execute) {
 
							AdminInterfaceCommand::Execute,
 
							"Available commands") {
 
			m_commands = commands;
 
			setDescription("Shows all the available commands with extended information.");
 
		}
 

	
 
		virtual std::string handleExecuteRequest(UserInfo &uinfo, User *user, std::vector<std::string> &args) {
 
			std::string ret = AdminInterfaceCommand::handleExecuteRequest(uinfo, user, args);
 
@@ -955,12 +960,14 @@ class CommandsCommand : public AdminInterfaceCommand {
 
					output += " User";
 
				}
 
				else {
 
					output += " Global";
 
				}
 

	
 
				output += " Label: \"" + (command->getLabel().empty() ? command->getName() : command->getLabel()) + "\"";
 

	
 
				output += "\n";
 
			}
 

	
 
			return output;
 
		}
 

	
 
@@ -973,13 +980,14 @@ class VariablesCommand : public AdminInterfaceCommand {
 
	public:
 
		
 
		VariablesCommand(std::map<std::string, AdminInterfaceCommand *> *commands) : AdminInterfaceCommand("variables",
 
							AdminInterfaceCommand::General,
 
							AdminInterfaceCommand::GlobalContext,
 
							AdminInterfaceCommand::AdminMode,
 
							AdminInterfaceCommand::Execute) {
 
							AdminInterfaceCommand::Execute,
 
							"Available variables") {
 
			m_commands = commands;
 
			setDescription("Shows all the available variables.");
 
		}
 

	
 
		virtual std::string handleExecuteRequest(UserInfo &uinfo, User *user, std::vector<std::string> &args) {
 
			std::string ret = AdminInterfaceCommand::handleExecuteRequest(uinfo, user, args);
 
@@ -1037,13 +1045,13 @@ class ArgsCommand : public AdminInterfaceCommand {
 
	public:
 
		
 
		ArgsCommand(std::map<std::string, AdminInterfaceCommand *> *commands) : AdminInterfaceCommand("args",
 
							AdminInterfaceCommand::General,
 
							AdminInterfaceCommand::GlobalContext,
 
							AdminInterfaceCommand::AdminMode,
 
							AdminInterfaceCommand::Execute) {
 
							AdminInterfaceCommand::Execute, "Command's arguments") {
 
			m_commands = commands;
 
			setDescription("Shows descripton of arguments for command");
 
			addArg("command", "Command", "register");
 
		}
 

	
 
		virtual std::string handleExecuteRequest(UserInfo &uinfo, User *user, std::vector<std::string> &args) {
libtransport/AdminInterfaceCommand.cpp
Show inline comments
 
@@ -27,18 +27,19 @@
 

	
 
#include <Swiften/Version.h>
 
#define HAVE_SWIFTEN_3  (SWIFTEN_VERSION >= 0x030000)
 

	
 
namespace Transport {
 

	
 
AdminInterfaceCommand::AdminInterfaceCommand(const std::string &name, Category category, Context context, AccessMode accessMode, Actions actions) {
 
AdminInterfaceCommand::AdminInterfaceCommand(const std::string &name, Category category, Context context, AccessMode accessMode, Actions actions, const std::string &label) {
 
	m_name = name;
 
	m_category = category;
 
	m_context = context;
 
	m_accessMode = accessMode;
 
	m_actions = actions;
 
	m_label = label;
 
}
 

	
 
const std::string AdminInterfaceCommand::getCategoryName(Category category) {
 
	switch (category) {
 
		case AdminInterfaceCommand::General:
 
			return "General";
spectrum/src/frontends/slack/SlackUserManager.cpp
Show inline comments
 
@@ -46,13 +46,14 @@ class ListRoomsCommand : public AdminInterfaceCommand {
 
	public:
 
		
 
		ListRoomsCommand(StorageBackend *storageBackend) : AdminInterfaceCommand("list_rooms",
 
							AdminInterfaceCommand::Frontend,
 
							AdminInterfaceCommand::UserContext,
 
							AdminInterfaceCommand::UserMode,
 
							AdminInterfaceCommand::Execute) {
 
							AdminInterfaceCommand::Execute,
 
							"List joined 3rd-party network rooms") {
 
			m_storageBackend = storageBackend;
 
			setDescription("List connected rooms");
 
		}
 

	
 
		virtual std::string handleExecuteRequest(UserInfo &uinfo, User *user, std::vector<std::string> &args) {
 
			std::string ret = AdminInterfaceCommand::handleExecuteRequest(uinfo, user, args);
 
@@ -78,13 +79,14 @@ class JoinRoomCommand : public AdminInterfaceCommand {
 
	public:
 
		
 
		JoinRoomCommand(StorageBackend *storageBackend, Config *cfg) : AdminInterfaceCommand("join_room",
 
							AdminInterfaceCommand::Frontend,
 
							AdminInterfaceCommand::UserContext,
 
							AdminInterfaceCommand::UserMode,
 
							AdminInterfaceCommand::Execute) {
 
							AdminInterfaceCommand::Execute,
 
							"Join 3rd-party network room") {
 
			m_storageBackend = storageBackend;
 
			setDescription("Join the room");
 

	
 
			std::string legacyRoomLabel = CONFIG_STRING_DEFAULTED(cfg, "service.join_room_room_label", "3rd-party room name");
 
			if (legacyRoomLabel[0] == '%') {
 
				legacyRoomLabel[0] = '#';
 
@@ -137,13 +139,14 @@ class LeaveRoomCommand : public AdminInterfaceCommand {
 
	public:
 
		
 
		LeaveRoomCommand(StorageBackend *storageBackend) : AdminInterfaceCommand("leave_room",
 
							AdminInterfaceCommand::Frontend,
 
							AdminInterfaceCommand::UserContext,
 
							AdminInterfaceCommand::UserMode,
 
							AdminInterfaceCommand::Execute) {
 
							AdminInterfaceCommand::Execute,
 
							"Leave 3rd-party network room") {
 
			m_storageBackend = storageBackend;
 
			setDescription("Leave the room");
 

	
 
			addArg("slack_channel", "Slack Chanel", "mychannel");
 
		}
 

	
spectrum_manager/src/APIServer.cpp
Show inline comments
 
@@ -307,13 +307,13 @@ void APIServer::serve_instances_commands(Server *server, Server::session *sessio
 

	
 
		std::vector<std::string> tokens;
 
		for(tokenizer<escaped_list_separator<char> >::iterator beg=tok.begin(); beg!=tok.end(); ++beg) {
 
			tokens.push_back(*beg);
 
		}
 

	
 
		if (tokens.size() != 9) {
 
		if (tokens.size() != 11) {
 
			continue;
 
		}
 

	
 
		if (!session->admin && tokens[6] == "Admin") {
 
			continue;
 
		}
 
@@ -334,12 +334,13 @@ void APIServer::serve_instances_commands(Server *server, Server::session *sessio
 
		Value cmd;
 
		cmd.SetObject();
 
		cmd.AddMember("name", tokens[0].c_str(), json.GetAllocator());
 
		cmd.AddMember("desc", tokens[2].c_str(), json.GetAllocator());
 
		cmd.AddMember("category", tokens[4].c_str(), json.GetAllocator());
 
		cmd.AddMember("context", tokens[8].c_str(), json.GetAllocator());
 
		cmd.AddMember("label", tokens[10].c_str(), json.GetAllocator());
 
		cmds.PushBack(cmd, json.GetAllocator());
 
	}
 

	
 
	json.AddMember("commands", cmds, json.GetAllocator());
 
	send_json(conn, json);
 
}
 
@@ -419,13 +420,13 @@ void APIServer::serve_instances_command_args(Server *server, Server::session *se
 

	
 
		std::vector<std::string> tokens;
 
		for(tokenizer<escaped_list_separator<char> >::iterator beg=tok.begin(); beg!=tok.end(); ++beg) {
 
			tokens.push_back(*beg);
 
		}
 

	
 
		if (tokens.size() != 9) {
 
		if (tokens.size() != 11) {
 
			continue;
 
		}
 

	
 
		std::cout << tokens[0] << " " << command << "\n";
 
		if (tokens[0] != command) {
 
			continue;
 
@@ -521,13 +522,13 @@ void APIServer::serve_instances_execute(Server *server, Server::session *session
 

	
 
		std::vector<std::string> tokens;
 
		for(tokenizer<escaped_list_separator<char> >::iterator beg=tok.begin(); beg!=tok.end(); ++beg) {
 
			tokens.push_back(*beg);
 
		}
 

	
 
		if (tokens.size() != 9) {
 
		if (tokens.size() != 11) {
 
			continue;
 
		}
 

	
 
		std::cout << tokens[0] << " " << command << "\n";
 
		if (tokens[0] != command) {
 
			continue;
spectrum_manager/src/html/js/app.js
Show inline comments
 
@@ -242,13 +242,13 @@ function show_instance() {
 

	
 
	$("#main_content").html("<h2>Instance: " + query.id + "</h2><h4>Available commands:</h4><table id='commands'><tr><th>Name<th>Category</th><th>Description</th></tr></table><h4>Available variables:</h4><table id='variables'><tr><th>Name<th>Value</th><th>Read-only</th><th>Desc</th></tr></table>");
 

	
 
	$.get($.cookie("base_location") + "api/v1/instances/commands/" + query.id, function(data) {
 
		$.each(data.commands, function(i, command) {
 
			var row = '<tr>'
 
			row += '<td><a class="button_command" command="' + command.name + '" instance="' + query.id + '" href="' + $.cookie("base_location") +  'api/v1/instances/command_args/' + query.id + '?command=' + command.name +'">' + command.name + '</a></td>';
 
			row += '<td><a class="button_command" command="' + command.name + '" instance="' + query.id + '" href="' + $.cookie("base_location") +  'api/v1/instances/command_args/' + query.id + '?command=' + command.name +'">' + command.label + '</a></td>';
 
			row += '<td>' + command.category + '</td>';
 
			row += '<td>' + command.desc + '</td>';
 
			row += '</tr>';
 
			$("#commands  > tbody:last-child").append(row);
 
		});
 

	
0 comments (0 inline, 0 general)