<commit_before>package org.minimalj.frontend.json;

import org.minimalj.frontend.action.Action;
import org.minimalj.frontend.action.Action.ActionChangeListener;
import org.minimalj.util.StringUtils;

public class JsonAction extends JsonComponent {
	private static final long serialVersionUID = 1L;
	private final Action action;
	
	public JsonAction(Action action) {
		super("Action");
		this.action = action;
		put("name", action.getName());
		if (!StringUtils.isEmpty(action.getDescription())) {
			put("description", action.getDescription());
		}
		put("enabled", action.isEnabled());
		action.setChangeListener(new JsonActionChangeListener());
	}

	public void action() {
		action.action();
	}
	
	public static class JsonActionGroup extends JsonComponent {
		private static final long serialVersionUID = 1L;
		
		public JsonActionGroup() {
			super("ActionGroup", false);
		}
	}
	
	private class JsonActionChangeListener implements ActionChangeListener {

		@Override
		public void change() {
			put("enabled", action.isEnabled());
		}
	}
	
}<commit_msg>JsonClient security: don't let user execute disabled actions<commit_after>package org.minimalj.frontend.json;

import org.minimalj.frontend.action.Action;
import org.minimalj.frontend.action.Action.ActionChangeListener;
import org.minimalj.util.StringUtils;

public class JsonAction extends JsonComponent {
	private static final long serialVersionUID = 1L;
	private final Action action;
	
	public JsonAction(Action action) {
		super("Action");
		this.action = action;
		put("name", action.getName());
		if (!StringUtils.isEmpty(action.getDescription())) {
			put("description", action.getDescription());
		}
		put("enabled", action.isEnabled());
		action.setChangeListener(new JsonActionChangeListener());
	}

	public void action() {
		// The user should not be able to execute action if it is disabled.
		// Still he could manipulate the DOM to reactive the action. Check here again.
		if (Boolean.TRUE.equals(get("enabled"))) {
			action.action();
		}
	}
	
	public static class JsonActionGroup extends JsonComponent {
		private static final long serialVersionUID = 1L;
		
		public JsonActionGroup() {
			super("ActionGroup", false);
		}
	}
	
	private class JsonActionChangeListener implements ActionChangeListener {

		@Override
		public void change() {
			put("enabled", action.isEnabled());
		}
	}
	
}
{'fraction_non_alphanumeric': 0.111346316680779, 'fraction_numerical': 0.001693480101608806, 'mean_word_length': 4.820197044334975, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3398858', 'n_tokens_mistral': 735, 'n_tokens_neox': 649, 'n_words': 175}