本文整理汇总了Java中com.gitblit.models.UserModel类的典型用法代码示例。如果您正苦于以下问题:Java UserModel类的具体用法?Java UserModel怎么用?Java UserModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UserModel类属于com.gitblit.models包,在下文中一共展示了UserModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: attribute
import com.gitblit.models.UserModel; //导入依赖的package包/类
/**
* Optionally stamp the payload with an emoji, icon url, or user attributions.
*
* @param payload
* @param user
*/
protected void attribute(Payload payload, UserModel user) {
IRuntimeManager runtimeManager = GitblitContext.getManager(IRuntimeManager.class);
String icon = runtimeManager.getSettings().getString(Plugin.SETTING_TICKET_EMOJI, null);
String defaultIcon = runtimeManager.getSettings().getString(Plugin.SETTING_DEFAULT_EMOJI, null);
if (StringUtils.isEmpty(icon)) {
icon = defaultIcon;
}
// set the username and gravatar
boolean postAsUser = runtimeManager.getSettings().getBoolean(Plugin.SETTING_POST_AS_USER, true);
if (postAsUser) {
payload.username(user.getDisplayName());
if (!StringUtils.isEmpty(user.emailAddress)) {
icon = ActivityUtils.getGravatarThumbnailUrl(user.emailAddress, 36);
}
}
payload.icon(icon);
}
示例2: sendDelete
import com.gitblit.models.UserModel; //导入依赖的package包/类
/**
* Sends a Slack message when a branch or a tag is deleted.
*
* @param receivePack
* @param cmd
* @param rType
*/
protected void sendDelete(GitblitReceivePack receivePack, ReceiveCommand cmd, RefType rType) throws IOException {
UserModel user = receivePack.getUserModel();
RepositoryModel repo = receivePack.getRepositoryModel();
String shortRef = Repository.shortenRefName(cmd.getRefName());
String repoUrl = getUrl(repo.name, null, null);
boolean postAsUser = receivePack.getGitblit().getSettings().getBoolean(Plugin.SETTING_POST_AS_USER, true);
String author;
if (postAsUser) {
// posting as user, do not BOLD username
author = user.getDisplayName();
} else {
// posting as Gitblit, BOLD username to draw attention
author = "*" + user.getDisplayName() + "*";
}
String msg = String.format("%s has deleted %s *%s* from <%s|%s>", author,
rType.name().toLowerCase(), shortRef, repoUrl, StringUtils.stripDotGit(repo.name));
Payload payload = Payload.instance(msg);
attribute(payload, user);
slacker.setChannel(repo, payload);
slacker.sendAsync(payload);
}
示例3: attribute
import com.gitblit.models.UserModel; //导入依赖的package包/类
/**
* Optionally stamp the payload with an emoji, icon url, or user attributions.
*
* @param payload
* @param user
*/
protected void attribute(Payload payload, UserModel user) {
IRuntimeManager runtimeManager = GitblitContext.getManager(IRuntimeManager.class);
String icon = runtimeManager.getSettings().getString(Plugin.SETTING_GIT_EMOJI, null);
String defaultIcon = runtimeManager.getSettings().getString(Plugin.SETTING_DEFAULT_EMOJI, null);
if (StringUtils.isEmpty(icon)) {
icon = defaultIcon;
}
// set the username and gravatar
boolean postAsUser = runtimeManager.getSettings().getBoolean(Plugin.SETTING_POST_AS_USER, true);
if (postAsUser) {
payload.username(user.getDisplayName());
if (!StringUtils.isEmpty(user.emailAddress)) {
icon = ActivityUtils.getGravatarThumbnailUrl(user.emailAddress, 36);
}
}
payload.icon(icon);
}
示例4: sendCreate
import com.gitblit.models.UserModel; //导入依赖的package包/类
/**
* Sends a HipChat message when a branch or a tag is created.
*
* @param receivePack
* @param cmd
* @param rType
*/
protected void sendCreate(GitblitReceivePack receivePack, ReceiveCommand cmd, RefType rType) throws IOException {
UserModel user = receivePack.getUserModel();
RepositoryModel repo = receivePack.getRepositoryModel();
String shortRef = Repository.shortenRefName(cmd.getRefName());
String repoUrl = getUrl(repo.name, null, null);
String logUrl = getUrl(repo.name, shortRef, null);
String msg = String.format("<b>%s</b> has created %s <a href=\"%s\">%s</a> in <a href=\"%s\">%s</a>",
user.getDisplayName(), rType.name().toLowerCase(), logUrl, shortRef, repoUrl, StringUtils.stripDotGit(repo.name));
Payload payload = Payload.html(msg);
payload.setColor(Color.gray);
hipChatter.setRoom(repo, payload);
hipChatter.sendAsync(payload);
}
示例5: onNewTicket
import com.gitblit.models.UserModel; //导入依赖的package包/类
@Override
public void onNewTicket(TicketModel ticket) {
if (!shallPost(ticket)) {
return;
}
Set<TicketModel.Field> fieldExclusions = new HashSet<TicketModel.Field>();
fieldExclusions.addAll(Arrays.asList(TicketModel.Field.watchers, TicketModel.Field.voters,
TicketModel.Field.status, TicketModel.Field.mentions));
Change change = ticket.changes.get(0);
IUserManager userManager = GitblitContext.getManager(IUserManager.class);
UserModel reporter = userManager.getUserModel(change.author);
StringBuilder sb = new StringBuilder();
sb.append(String.format("<b>%s</b> has created <b>%s</b> <a href=\"%s\">ticket-%s</a>", reporter.getDisplayName(),
StringUtils.stripDotGit(ticket.repository), getUrl(ticket), ticket.number));
fields(sb, ticket, ticket.changes.get(0), fieldExclusions);
Payload payload = Payload.html(sb.toString());
payload.color(Color.purple);
hipChatter.sendAsync(payload);
}
示例6: run
import com.gitblit.models.UserModel; //导入依赖的package包/类
@Override
public void run() throws UnloggedFailure {
UserModel user = getUser(true);
IGitblit gitblit = getContext().getGitblit();
if (null != gitblit.getTeamModel(newUserName)) {
throw new UnloggedFailure(1, String.format("Team %s already exists!", newUserName));
}
// set the new name
user.username = newUserName;
try {
gitblit.reviseUser(username, user);
stdout.println(String.format("Renamed user %s to %s.", username, newUserName));
} catch (GitBlitException e) {
String msg = String.format("Failed to rename user from %s to %s", username, newUserName);
log.error(msg, e);
throw new UnloggedFailure(1, msg);
}
}
示例7: run
import com.gitblit.models.UserModel; //导入依赖的package包/类
@Override
public void run() throws UnloggedFailure {
RepositoryModel repo = getRepository(true);
UserModel user = getContext().getClient().getUser();
if (!user.canFork(repo)) {
throw new UnloggedFailure(1, String.format("Sorry, you do not have permission to fork %s", repository));
}
IGitblit gitblit = getContext().getGitblit();
try {
RepositoryModel fork = gitblit.fork(repo, user);
if (fork != null) {
stdout.println(String.format("%s has been forked.", repository));
stdout.println();
stdout.println(String.format(" git clone %s", getRepositoryUrl(fork.name)));
stdout.println();
} else {
throw new UnloggedFailure(1, String.format("Failed to fork %s!", repository));
}
} catch (GitBlitException e) {
throw new UnloggedFailure(1, String.format("Failed to fork %s!", repository), e);
}
}
示例8: createUserModel
import com.gitblit.models.UserModel; //导入依赖的package包/类
/**
* Creates a user model for a git repository on the GitBlit server
*
* @param tenantId tenant Id
* @param baseUrl GitBlit server url
* @param username username of the user to be added
* @param password password of the user to be added
* @param adminUserName admin username of the server
* @param adminPassword admin password of the server
* @return created UserModel instance
*/
private UserModel createUserModel (int tenantId, String baseUrl, String username, String password,
String adminUserName, String adminPassword) {
UserModel userModel = new UserModel(username);
userModel.canAdmin = true;
userModel.password = password;
boolean isUserCreated = false;
try {
isUserCreated = RpcUtils.createUser(userModel, baseUrl, adminUserName, adminPassword.toCharArray());
} catch (IOException e) {
handleError("User creation failed for tenant " + tenantId, e);
}
if(isUserCreated) {
log.info("User created successfully for tenant " + tenantId);
}
else {
handleError("User creation failed for tenant " + tenantId + ", server url: " +
baseUrl);
}
return userModel;
}
示例9: getUserModel
import com.gitblit.models.UserModel; //导入依赖的package包/类
/**
* Checks and returns the corresponding UserModel instance for the given username in the repository at baseUrl
*
* @param baseUrl GitBlit server url
* @param userName username of the user
* @param adminUserName admin username of the server
* @param adminPassword admin password of the server
* @return instance of UserModel if exists, else null
*/
private UserModel getUserModel(String baseUrl, String userName, String adminUserName, String adminPassword) {
UserModel userModel = null;
List<UserModel> users;
try {
users = RpcUtils.getUsers(baseUrl, adminUserName, adminPassword.toCharArray());
} catch (IOException e) {
log.error("Error retrieving user details from git server " + baseUrl, e);
return null;
}
for (UserModel model : users) {
if (model.username.equals(userName)) {
userModel = model;
break;
}
}
return userModel;
}
示例10: newUserModelFrom
import com.gitblit.models.UserModel; //导入依赖的package包/类
private static UserModel newUserModelFrom(PersonIdent ident) {
String name = ident.getName();
String username;
String displayname;
if (name.indexOf('/') > -1) {
int slash = name.indexOf('/');
displayname = name.substring(0, slash);
username = name.substring(slash + 1);
} else {
displayname = name;
username = ident.getEmailAddress();
}
UserModel user = new UserModel(username);
user.displayName = displayname;
user.emailAddress = ident.getEmailAddress();
return user;
}
示例11: deleteRef
import com.gitblit.models.UserModel; //导入依赖的package包/类
/**
* Logs a ref deletion.
*
* @param user
* @param repository
* @param ref
* @return true, if the update was successful
*/
public static boolean deleteRef(UserModel user, Repository repository, Ref ref) {
try {
if (ref == null) {
return false;
}
RefModel reflogBranch = getRefLogBranch(repository);
if (reflogBranch == null) {
return false;
}
List<RevCommit> log = JGitUtils.getRevLog(repository, reflogBranch.getName(), ref.getName(), 0, 1);
if (log.isEmpty()) {
// this ref is not in the reflog branch
return false;
}
ReceiveCommand cmd = new ReceiveCommand(ref.getObjectId(), ObjectId.zeroId(), ref.getName());
return updateRefLog(user, repository, Arrays.asList(cmd));
} catch (Throwable t) {
error(t, repository, "Failed to commit reflog entry to {0}");
}
return false;
}
示例12: addUserAttributions
import com.gitblit.models.UserModel; //导入依赖的package包/类
protected void addUserAttributions(MarkupContainer container, Change entry, int avatarSize) {
UserModel commenter = app().users().getUserModel(entry.author);
if (commenter == null) {
// unknown user
container.add(new AvatarImage("changeAvatar", entry.author,
entry.author, null, avatarSize, false).setVisible(avatarSize > 0));
container.add(new Label("changeAuthor", entry.author.toLowerCase()));
} else {
// known user
container.add(new AvatarImage("changeAvatar", commenter.getDisplayName(),
commenter.emailAddress, avatarSize > 24 ? "gravatar-round" : null,
avatarSize, true).setVisible(avatarSize > 0));
container.add(new LinkPanel("changeAuthor", null, commenter.getDisplayName(),
UserPage.class, WicketUtils.newUsernameParameter(commenter.username)));
}
}
示例13: getUnnamedGerritUser
import com.gitblit.models.UserModel; //导入依赖的package包/类
/**
* GitBlit assumes all users (or user accounts) have a username (account name or login name). Gerrit allows users (accounts) to not have a
* username, for instance if the account is created or logged in via Google OAuth. I such cases, we have to fake a username for GitBlit.
*
* @return a GitBlit {@link UserModel} for an unnamed Gerrit account.
*/
public UserModel getUnnamedGerritUser() {
CurrentUser user = userProvider.get();
if (!user.isIdentifiedUser()) {
log.warn("\"Logged-in\" user according to session is anonymous.");
return new GerritGitBlitUserModel(projectControl, anonymousUser, getDiffPreferences);
}
IdentifiedUser loggedInUser = (IdentifiedUser) user;
// We know that this user has no username. Synthesize one for GitBlit.
String fakeUserName = loggedInUser.getAccount().getPreferredEmail();
if (Strings.isNullOrEmpty(fakeUserName)) {
fakeUserName = loggedInUser.getAccount().getFullName();
if (Strings.isNullOrEmpty(fakeUserName)) {
fakeUserName = "external" + loggedInUser.getAccountId().toString();
}
}
return new GerritGitBlitUserModel(fakeUserName, projectControl, userProvider, getDiffPreferences);
}
示例14: authenticate
import com.gitblit.models.UserModel; //导入依赖的package包/类
@Override
public UserModel authenticate(final HttpServletRequest httpRequest) {
// Added by the GerritAuthenticationFilter.
String username = (String) httpRequest.getAttribute("gerrit-username");
String token = (String) httpRequest.getAttribute("gerrit-token");
String password = (String) httpRequest.getAttribute("gerrit-password");
if (!Strings.isNullOrEmpty(token)) {
return authenticateFromSession(httpRequest, username, token);
} else if (!Strings.isNullOrEmpty(password)) {
return authenticateViaGerrit(httpRequest, username, password);
} else if (GerritGitBlitUserModel.ANONYMOUS_USER.equals(username)) {
// XXX Do we really still need this branch? We "inherited" that from the old official plugin...
return userManager.getUserModel(username);
}
return null;
}
示例15: authenticateViaGerrit
import com.gitblit.models.UserModel; //导入依赖的package包/类
private UserModel authenticateViaGerrit(HttpServletRequest httpRequest, String username, String password) {
if (Strings.isNullOrEmpty(username)) {
log.warn("Authentication failed: no username");
return null;
}
if (Strings.isNullOrEmpty(password)) {
log.warn("Authentication failed: no password for user '{}'", username);
return null;
}
AuthRequest who = AuthRequest.forUser(username);
who.setPassword(password);
try {
AuthResult authResp = gerritAccountManager.authenticate(who);
gerritSession.get().login(authResp, false);
log.info("Logged in {}", username);
return loggedIn(httpRequest, userManager.getUserModel(username), password, authResp);
} catch (AccountException | IOException e) {
log.warn("Authentication failed for user '" + username + '\'', e);
return null;
}
}