| | |
| | | import java.util.Collections;
|
| | | import java.util.HashSet;
|
| | | import java.util.List;
|
| | | import java.util.Locale;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | | import java.util.concurrent.ConcurrentHashMap;
|
| | |
| | |
|
| | | import com.gitblit.Constants.AccessPermission;
|
| | | import com.gitblit.Constants.AccountType;
|
| | | import com.gitblit.Constants.Role;
|
| | | import com.gitblit.Constants.Transport;
|
| | | import com.gitblit.manager.IRuntimeManager;
|
| | | import com.gitblit.models.TeamModel;
|
| | | import com.gitblit.models.UserModel;
|
| | |
| | | private static final String STARRED = "starred";
|
| | |
|
| | | private static final String LOCALE = "locale";
|
| | |
|
| | | private static final String EMAILONMYTICKETCHANGES = "emailMeOnMyTicketChanges";
|
| | |
|
| | | private static final String TRANSPORT = "transport";
|
| | |
|
| | | private static final String ACCOUNTTYPE = "accountType";
|
| | |
|
| | |
| | | config.setBoolean(USER, model.username, DISABLED, true);
|
| | | }
|
| | | if (model.getPreferences() != null) {
|
| | | if (!StringUtils.isEmpty(model.getPreferences().locale)) {
|
| | | config.setString(USER, model.username, LOCALE, model.getPreferences().locale);
|
| | | Locale locale = model.getPreferences().getLocale();
|
| | | if (locale != null) {
|
| | | String val;
|
| | | if (StringUtils.isEmpty(locale.getCountry())) {
|
| | | val = locale.getLanguage();
|
| | | } else {
|
| | | val = locale.getLanguage() + "_" + locale.getCountry();
|
| | | }
|
| | | config.setString(USER, model.username, LOCALE, val);
|
| | | }
|
| | |
|
| | | config.setBoolean(USER, model.username, EMAILONMYTICKETCHANGES, model.getPreferences().isEmailMeOnMyTicketChanges());
|
| | |
|
| | | if (model.getPreferences().getTransport() != null) {
|
| | | config.setString(USER, model.username, TRANSPORT, model.getPreferences().getTransport().name());
|
| | | }
|
| | | }
|
| | |
|
| | | // user roles
|
| | | List<String> roles = new ArrayList<String>();
|
| | | if (model.canAdmin) {
|
| | | roles.add(Constants.ADMIN_ROLE);
|
| | | roles.add(Role.ADMIN.getRole());
|
| | | }
|
| | | if (model.canFork) {
|
| | | roles.add(Constants.FORK_ROLE);
|
| | | roles.add(Role.FORK.getRole());
|
| | | }
|
| | | if (model.canCreate) {
|
| | | roles.add(Constants.CREATE_ROLE);
|
| | | roles.add(Role.CREATE.getRole());
|
| | | }
|
| | | if (model.excludeFromFederation) {
|
| | | roles.add(Constants.NOT_FEDERATED_ROLE);
|
| | | roles.add(Role.NOT_FEDERATED.getRole());
|
| | | }
|
| | | if (roles.size() == 0) {
|
| | | // we do this to ensure that user record with no password
|
| | | // is written. otherwise, StoredConfig optimizes that account
|
| | | // away. :(
|
| | | roles.add(Constants.NO_ROLE);
|
| | | roles.add(Role.NONE.getRole());
|
| | | }
|
| | | config.setStringList(USER, model.username, ROLE, roles);
|
| | |
|
| | |
| | | // team roles
|
| | | List<String> roles = new ArrayList<String>();
|
| | | if (model.canAdmin) {
|
| | | roles.add(Constants.ADMIN_ROLE);
|
| | | roles.add(Role.ADMIN.getRole());
|
| | | }
|
| | | if (model.canFork) {
|
| | | roles.add(Constants.FORK_ROLE);
|
| | | roles.add(Role.FORK.getRole());
|
| | | }
|
| | | if (model.canCreate) {
|
| | | roles.add(Constants.CREATE_ROLE);
|
| | | roles.add(Role.CREATE.getRole());
|
| | | }
|
| | | if (roles.size() == 0) {
|
| | | // we do this to ensure that team record is written.
|
| | | // Otherwise, StoredConfig might optimizes that record away.
|
| | | roles.add(Constants.NO_ROLE);
|
| | | roles.add(Role.NONE.getRole());
|
| | | }
|
| | | config.setStringList(TEAM, model.name, ROLE, roles);
|
| | | if (model.accountType != null) {
|
| | |
| | | user.stateProvince = config.getString(USER, username, STATEPROVINCE);
|
| | | user.countryCode = config.getString(USER, username, COUNTRYCODE);
|
| | | user.cookie = config.getString(USER, username, COOKIE);
|
| | | user.getPreferences().locale = config.getString(USER, username, LOCALE);
|
| | | if (StringUtils.isEmpty(user.cookie) && !StringUtils.isEmpty(user.password)) {
|
| | | user.cookie = StringUtils.getSHA1(user.username + user.password);
|
| | | }
|
| | |
|
| | | // preferences
|
| | | user.getPreferences().setLocale(config.getString(USER, username, LOCALE));
|
| | | user.getPreferences().setEmailMeOnMyTicketChanges(config.getBoolean(USER, username, EMAILONMYTICKETCHANGES, true));
|
| | | user.getPreferences().setTransport(Transport.fromString(config.getString(USER, username, TRANSPORT)));
|
| | |
|
| | | // user roles
|
| | | Set<String> roles = new HashSet<String>(Arrays.asList(config.getStringList(
|
| | | USER, username, ROLE)));
|
| | | user.canAdmin = roles.contains(Constants.ADMIN_ROLE);
|
| | | user.canFork = roles.contains(Constants.FORK_ROLE);
|
| | | user.canCreate = roles.contains(Constants.CREATE_ROLE);
|
| | | user.excludeFromFederation = roles.contains(Constants.NOT_FEDERATED_ROLE);
|
| | | user.canAdmin = roles.contains(Role.ADMIN.getRole());
|
| | | user.canFork = roles.contains(Role.FORK.getRole());
|
| | | user.canCreate = roles.contains(Role.CREATE.getRole());
|
| | | user.excludeFromFederation = roles.contains(Role.NOT_FEDERATED.getRole());
|
| | |
|
| | | // repository memberships
|
| | | if (!user.canAdmin) {
|
| | |
| | | TeamModel team = new TeamModel(teamname);
|
| | | Set<String> roles = new HashSet<String>(Arrays.asList(config.getStringList(
|
| | | TEAM, teamname, ROLE)));
|
| | | team.canAdmin = roles.contains(Constants.ADMIN_ROLE);
|
| | | team.canFork = roles.contains(Constants.FORK_ROLE);
|
| | | team.canCreate = roles.contains(Constants.CREATE_ROLE);
|
| | | team.canAdmin = roles.contains(Role.ADMIN.getRole());
|
| | | team.canFork = roles.contains(Role.FORK.getRole());
|
| | | team.canCreate = roles.contains(Role.CREATE.getRole());
|
| | | team.accountType = AccountType.fromString(config.getString(TEAM, teamname, ACCOUNTTYPE));
|
| | |
|
| | | if (!team.canAdmin) {
|