use of cz.metacentrum.perun.webgui.model.User in project perun by CESNET.
the class AddRemoveItemsTable method buildWidget.
/**
* Rebuild widget GUI
*/
private void buildWidget() {
FlexTable ft = new FlexTable();
ft.setStyleName("perun-table");
widget.clear();
widget.add(ft);
if (list.isEmpty()) {
ft.setHTML(0, 0, "<strong>No items found.</strong>");
ft.getFlexCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_TOP);
}
int row = 0;
int column = 0;
for (final T object : list) {
GeneralObject go = object.cast();
String name = "";
if ("User".equalsIgnoreCase(go.getObjectType())) {
User u = go.cast();
name = u.getFullNameWithTitles();
} else if ("RichUser".equalsIgnoreCase(go.getObjectType())) {
User u = go.cast();
name = u.getFullNameWithTitles();
} else if ("RichMember".equalsIgnoreCase(go.getObjectType())) {
RichMember m = go.cast();
name = m.getUser().getFullNameWithTitles();
} else {
name = ((GeneralObject) object).getName();
}
CustomButton rb = new CustomButton("", "Remove item", SmallIcons.INSTANCE.deleteIcon());
rb.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
removeItem(object);
}
});
if (vertical) {
ft.setHTML(row, 0, name);
ft.setWidget(row, 1, rb);
row++;
} else {
ft.setHTML(row, column, name);
ft.setWidget(row, column + 1, rb);
column = column + 2;
}
}
widget.setSize("100%", "100%");
widget.setStyleName("perun-tableScrollPanel", true);
UiElements.runResizeCommands(true);
}
use of cz.metacentrum.perun.webgui.model.User in project perun by CESNET.
the class GetRichAdminsWithAttributes method getTable.
/**
* Returns the table with member-users
*
* @return CellTable widget
*/
public CellTable<User> getTable() {
// Retrieves data
this.retrieveData();
// Table data provider.
dataProvider = new ListDataProvider<User>(list);
// Cell table
table = new PerunTable<User>(list);
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
if (entity.equals(PerunEntity.VIRTUAL_ORGANIZATION)) {
loaderImage.setEmptyResultMessage("VO has no managers (try to switch to 'Groups' view).");
} else if (entity.equals(PerunEntity.GROUP)) {
loaderImage.setEmptyResultMessage("Group has no managers (try to switch to 'Groups' view).");
} else if (entity.equals(PerunEntity.FACILITY)) {
loaderImage.setEmptyResultMessage("Facility has no managers (try to switch to 'Groups' view).");
} else if (entity.equals(PerunEntity.SECURITY_TEAM)) {
loaderImage.setEmptyResultMessage("SecurityTeam has no members (try to switch to 'Groups' view).");
}
// Sorting
ListHandler<User> columnSortHandler = new ListHandler<User>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// Table selection
table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<User>createCheckboxManager());
// Set empty content & loader
table.setEmptyTableWidget(loaderImage);
// Checkbox column column
if (checkable) {
table.addCheckBoxColumn();
}
// Create User ID column.
Column<User, String> userIdColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {
public String getValue(User object) {
return String.valueOf(object.getId());
}
}, this.tableFieldUpdater);
userIdColumn.setSortable(true);
columnSortHandler.setComparator(userIdColumn, new GeneralComparator<User>(GeneralComparator.Column.ID));
table.setColumnWidth(userIdColumn, 110.0, Unit.PX);
if (JsonUtils.isExtendedInfoVisible()) {
table.addColumn(userIdColumn, "User ID");
}
table.setHyperlinksAllowed(false);
table.addNameColumn(tableFieldUpdater);
// Create organization column.
Column<User, String> organizationColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {
public String getValue(User object) {
Attribute at = object.getAttribute("urn:perun:user:attribute-def:def:organization");
if (at != null && at.getValue() != null && !"null".equalsIgnoreCase(at.getValue())) {
return at.getValue();
}
return "";
}
}, this.tableFieldUpdater);
// Create e-mail column.
Column<User, String> emailColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {
public String getValue(User object) {
Attribute at = object.getAttribute("urn:perun:user:attribute-def:def:preferredMail");
if (at != null && at.getValue() != null && !"null".equalsIgnoreCase(at.getValue())) {
return at.getValue().replace(",", " ");
}
return "";
}
}, this.tableFieldUpdater);
// Create name column.
Column<User, String> loginsColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {
public String getValue(User object) {
return object.getLogins();
}
}, this.tableFieldUpdater);
organizationColumn.setSortable(true);
columnSortHandler.setComparator(organizationColumn, new RichUserComparator(RichUserComparator.Column.ORGANIZATION));
emailColumn.setSortable(true);
columnSortHandler.setComparator(emailColumn, new RichUserComparator(RichUserComparator.Column.EMAIL));
// Add the other columns.
table.addColumn(organizationColumn, "Organization");
table.addColumn(emailColumn, "E-mail");
table.addColumn(loginsColumn, "Logins");
return table;
}
use of cz.metacentrum.perun.webgui.model.User in project perun by CESNET.
the class AddFacilityManagerTabItem method startSearching.
/**
* Starts the search for users
*/
protected void startSearching(String text) {
users.clearTable();
// IS searched string IDs?
if (JsonUtils.isStringWithIds(text)) {
FindUsersByIdsNotInRpc req = new FindUsersByIdsNotInRpc(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
ArrayList<User> usersList = JsonUtils.jsoAsList(jso);
for (User u : usersList) {
users.addToTable(u);
}
}
}, text);
req.retrieveData();
return;
}
users.searchFor(text);
}
use of cz.metacentrum.perun.webgui.model.User in project perun by CESNET.
the class SelfSponsoredUsersTabItem method draw.
@Override
public Widget draw() {
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
if (user.isSponsoredUser()) {
// SERVICE TYPE user
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(user.getFullNameWithTitles().trim()) + ": Sponsors");
// request
final GetUsersBySpecificUser request = new GetUsersBySpecificUser(userId);
// menu
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
// table
CellTable<User> table;
if (session.isPerunAdmin()) {
table = request.getTable(new FieldUpdater<User, String>() {
public void update(int i, User user, String s) {
session.getTabManager().addTab(new SelfDetailTabItem(user));
}
});
} else {
table = request.getTable();
}
table.addStyleName("perun-table");
table.setWidth("100%");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
} else {
// PERSON TYPE user
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(user.getFullNameWithTitles().trim()) + ": Sponsored users");
// request
final GetSpecificUsersByUser request = new GetSpecificUsersByUser(userId);
request.setHideService(true);
// menu
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
// table
CellTable<User> table;
if (session.isPerunAdmin()) {
table = request.getTable(new FieldUpdater<User, String>() {
public void update(int i, User user, String s) {
session.getTabManager().addTab(new SelfDetailTabItem(user));
}
});
} else {
table = request.getTable();
}
table.addStyleName("perun-table");
table.setWidth("100%");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
}
contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.User in project perun by CESNET.
the class SelfPasswordTabItem method draw.
public Widget draw() {
String actionText = "Change";
if (action.equals(Actions.CREATE)) {
actionText = "Create";
} else if (action.equals(Actions.DELETE)) {
actionText = "Delete";
}
// set tab name
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(user.getFullNameWithTitles().trim()) + ": " + actionText + " password");
// main panel
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
TabMenu menu = new TabMenu();
// widgets
final Label namespaceLabel = new Label();
namespaceLabel.setText(namespace);
final Label loginLabel = new Label();
loginLabel.setText(login);
final ExtendedPasswordBox newPass = new ExtendedPasswordBox();
final ExtendedPasswordBox confPass = new ExtendedPasswordBox();
final ExtendedPasswordBox oldPass = new ExtendedPasswordBox();
final CustomButton changeButton = new CustomButton("Change password", "Changes your password in selected namespace", SmallIcons.INSTANCE.keyIcon());
final CustomButton createButton = new CustomButton("Create password", "Creates your password in selected namespace", SmallIcons.INSTANCE.keyAddIcon());
final CustomButton deleteButton = new CustomButton("Delete password", "Deletes your password in selected namespace", SmallIcons.INSTANCE.keyDeleteIcon());
final TabItem tab = this;
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (newPass.getTextBox().getValue().trim().equals("")) {
newPass.setError("Password can't be empty!");
return false;
} else if (!newPass.getTextBox().getValue().trim().equals(confPass.getTextBox().getValue().trim())) {
newPass.setError("Password in both textboxes must be the same!");
return false;
} else {
newPass.setOk();
confPass.setOk();
return true;
}
}
};
final ExtendedTextBox.TextBoxValidator validator2 = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (confPass.getTextBox().getValue().trim().equals("")) {
confPass.setError("Password can't be empty!");
return false;
} else if (!confPass.getTextBox().getValue().trim().equals(newPass.getTextBox().getValue().trim())) {
confPass.setError("Password in both textboxes must be the same!");
return false;
} else {
confPass.setOk();
newPass.setOk();
return true;
}
}
};
final ExtendedTextBox.TextBoxValidator oldValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (oldPass.getTextBox().getValue().trim().equals("")) {
oldPass.setError("Password can't be empty!");
return false;
} else {
oldPass.setOk();
return true;
}
}
};
newPass.setValidator(validator);
confPass.setValidator(validator2);
oldPass.setValidator(oldValidator);
// save changes
changeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if ("mu".equals(namespace) && !JsonUtils.checkParseInt(login)) {
UiElements.generateAlert("Operation not supported", "Password change/reset is not supported for non-numeric logins (UČO).");
}
if (session.isPerunAdmin() || user.isServiceUser()) {
if (!validator.validateTextBox() && !validator2.validateTextBox())
return;
ChangePassword changepw = new ChangePassword(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab), false);
changepw.changePassword(user, namespace, oldPass.getTextBox().getValue().trim(), newPass.getTextBox().getValue().trim());
} else {
if (!validator.validateTextBox() && !validator2.validateTextBox() && !oldValidator.validateTextBox())
return;
ChangePassword changepw = new ChangePassword(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab), true);
changepw.changePassword(user, namespace, oldPass.getTextBox().getValue().trim(), newPass.getTextBox().getValue().trim());
}
}
});
if (user.isServiceUser()) {
// for service users it's reset since they don't provide old password
changeButton.setText("Reset password…");
}
createButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
if (validator.validateTextBox() && validator2.validateTextBox()) {
if ("mu".equals(namespace)) {
final GenerateAccount generateAccount = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
BasicOverlayType basic = jso.cast();
final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
// VALIDATE PASSWORD - SET EXT SOURCES
CreatePassword req = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
req.validateAndSetUserExtSources(user.getId(), login, namespace);
}
}));
setLogin.setLogin(user.getId(), "mu", login);
}
}));
final Map<String, String> params = new HashMap<String, String>();
GetEntityById get = new GetEntityById(PerunEntity.RICH_USER_WITH_ATTRS, user.getId(), JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
User usr = jso.cast();
params.put("urn:perun:user:attribute-def:core:firstName", usr.getFirstName());
params.put("urn:perun:user:attribute-def:core:lastName", usr.getLastName());
params.put("urn:perun:member:attribute-def:def:mail", usr.getAttribute("urn:perun:user:attribute-def:def:preferredMail").getValue());
generateAccount.generateAccount(namespace, newPass.getTextBox().getValue().trim(), params);
}
}));
get.retrieveData();
} else {
// NORMAL PWD LOGIC
CreatePassword create = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
create.createPassword(userId, login, namespace, newPass.getTextBox().getValue().trim());
}
}
}
});
deleteButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
UiElements.generateAlert("Not yet implemented", "Not yet implemented");
}
});
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
// change layout
if (action.equals(Actions.CHANGE)) {
int row = 0;
layout.setHTML(row, 0, "Namespace:");
layout.setWidget(row, 1, namespaceLabel);
row++;
layout.setHTML(row, 0, "Login:");
layout.setWidget(row, 1, loginLabel);
row++;
// mu namespace can change without knowing old
if (!session.isPerunAdmin()) {
if (!user.isServiceUser()) {
layout.setHTML(row, 0, "Old password: ");
layout.setWidget(row, 1, oldPass);
row++;
}
}
layout.setHTML(row, 0, "New password:");
layout.setWidget(row, 1, newPass);
row++;
layout.setHTML(row, 0, "Retype new pass:");
layout.setWidget(row, 1, confPass);
menu.addWidget(changeButton);
vp.add(layout);
} else if (action.equals(Actions.CREATE)) {
layout.setHTML(0, 0, "Namespace:");
layout.setWidget(0, 1, namespaceLabel);
if ("mu".equals(namespace)) {
loginLabel.setText("Will be generated...");
loginLabel.addStyleName("inputFormInlineComment");
}
layout.setHTML(1, 0, "Login:");
layout.setWidget(1, 1, loginLabel);
layout.setHTML(2, 0, "New password:");
layout.setWidget(2, 1, newPass);
layout.setHTML(3, 0, "Retype new pass:");
layout.setWidget(3, 1, confPass);
final CustomButton skip = new CustomButton("Skip", "Will set random/empty password", SmallIcons.INSTANCE.arrowRightIcon());
skip.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if ("mu".equals(namespace)) {
final GenerateAccount generateAccount = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
BasicOverlayType basic = jso.cast();
final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
// VALIDATE PASSWORD - SET EXT SOURCES
CreatePassword req = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
req.validateAndSetUserExtSources(user.getId(), login, namespace);
}
}));
setLogin.setLogin(user.getId(), "mu", login);
}
}));
final Map<String, String> params = new HashMap<String, String>();
GetEntityById get = new GetEntityById(PerunEntity.RICH_USER_WITH_ATTRS, user.getId(), JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
User usr = jso.cast();
params.put("urn:perun:user:attribute-def:core:firstName", usr.getFirstName());
params.put("urn:perun:user:attribute-def:core:lastName", usr.getLastName());
params.put("urn:perun:member:attribute-def:def:mail", usr.getAttribute("urn:perun:user:attribute-def:def:preferredMail").getValue());
generateAccount.generateAccount(namespace, newPass.getTextBox().getValue().trim(), params);
}
}));
get.retrieveData();
} else {
CreatePassword create = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(skip, tab));
create.createRandomPassword(userId, login, namespace);
}
}
});
menu.addWidget(skip);
menu.addWidget(createButton);
vp.add(layout);
} else if (action.equals(Actions.DELETE)) {
layout.setHTML(0, 0, "Namespace:");
layout.setWidget(0, 1, namespaceLabel);
layout.setHTML(1, 0, "Login:");
layout.setWidget(1, 1, loginLabel);
menu.addWidget(deleteButton);
vp.add(layout);
}
for (int i = 0; i < layout.getRowCount(); i++) {
layout.getFlexCellFormatter().setStyleName(i, 0, "itemName");
}
if (!action.equals(Actions.CREATE)) {
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().closeTab(tab, false);
}
}));
}
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations