示例#1
0
 @Override
 public List<Corporation> getCorporationListWithPager(long userId, int pageNum, int pageSize) {
   User user = accountMgr.getUser(userId);
   if (user.isAdmin()) {
     return getCorporationListWithPager(pageNum, pageSize);
   }
   List<Corporation> list = organizationDao.getCorporationListWithPager(userId, pageNum, pageSize);
   for (Corporation c : list) {
     long memberNum = organizationDao.getMemberNumOfCorporation(c.getId());
     c.setMemberNum(memberNum + 1); // +1 project creator
     c.setHasAccess(canUserManageCorp(userId, c.getId()));
     c.setCreatorName(accountMgr.getUser(c.getUserId()).getName());
   }
   return list;
 }
示例#2
0
  @Override
  public boolean canUserAccessProject(long userId, int projectId) {
    User u = accountMgr.getUser(userId);
    Project p = projectMgr.getProject(projectId);

    return u.isAdmin() || p.isUserMember(userId);
  }
示例#3
0
  @Override
  public int addProject(Project project) {
    project.setUpdateTime(new Date());
    project.setCreateDate(new Date());
    List<User> usersInformed = new ArrayList<User>();
    for (String account : project.getMemberAccountList()) {
      User user = accountDao.getUser(account);
      if (user != null) {
        boolean addSuccess = project.addMember(user);
        if (addSuccess) {
          usersInformed.add(user);
        }
      }
    }
    int result = projectDao.addProject(project);
    for (User u : usersInformed) {
      Notification o = new Notification();
      o.setTypeId((short) 2);
      o.setTargetUser(project.getUser());
      o.setUser(u);
      o.setParam1(new Integer(result).toString());
      o.setParam2(project.getName());
      accountMgr.addNotification(o);
    }

    Group g = organizationDao.getGroup(project.getGroupId());
    if (g.getProductionLineId() > 0) {
      organizationDao.updateCountersInProductionLine(g.getProductionLineId());
    }

    return result;
  }
示例#4
0
 @Override
 public long getCorporationListWithPagerNum(long userId) {
   User user = accountMgr.getUser(userId);
   if (user.isAdmin()) {
     return getCorporationListWithPagerNum();
   }
   return organizationDao.getCorporationListWithPagerNum(userId);
 }
示例#5
0
 @Override
 public boolean canUserAccessCorp(long userId, int corpId) {
   Corporation c = getCorporation(corpId);
   if (c == null) return false;
   if (c.getUserId() == userId) return true;
   User user = accountMgr.getUser(userId);
   if (user != null && user.isAdmin()) return true;
   return organizationDao.isUserInCorp(userId, corpId);
 }
示例#6
0
 private boolean canUserManageUserInCorp(long curUserId, long userId, int corpId) {
   User curUser = accountMgr.getUser(curUserId);
   if (curUser.isAdmin()) {
     return true;
   }
   int roleId = getUserRoleInCorp(curUserId, corpId);
   if (roleId >= 1 || roleId <= 2) {
     return true;
   }
   return false;
 }
示例#7
0
  @Override
  public List<Corporation> getCorporationListWithPager(int pageNum, int pageSize) {

    List<Corporation> list = organizationDao.getCorporationListWithPager(pageNum, pageSize);

    for (Corporation c : list) {
      long memberNum = organizationDao.getMemberNumOfCorporation(c.getId());
      c.setMemberNum(memberNum + 1); // +1 project creator
      c.setHasAccess(true);
      c.setCreatorName(accountMgr.getUser(c.getUserId()).getName());
    }
    return list;
  }
示例#8
0
 @Override
 public int addTeam(Corporation team) {
   int corpId = organizationDao.addCorporation(team);
   for (String account : team.getAccountList()) {
     if (account == null || account.trim().isEmpty()) continue;
     User u = accountMgr.getUser(account);
     if (u.getId() == team.getUserId()) {
       // if the user is creator, there's no need to add again
       continue;
     }
     organizationDao.addUserToCorp(corpId, u.getId(), 3); // 3, normal member
   }
   return corpId;
 }
示例#9
0
  @Override
  public boolean addTeamMembers(long curUserId, int corpId, String accountList) {
    if (!canUserManageCorp(curUserId, corpId)) return false;

    String[] accs = accountList.split(",");
    Corporation c = getCorporation(corpId);
    for (String acc : accs) {
      User u = accountMgr.getUser(acc);
      if (u != null) {
        if (!organizationDao.isUserInCorp(u.getId(), corpId) && u.getId() != c.getUserId()) {
          organizationDao.addUserToCorp(corpId, u.getId(), 3);
        }
      }
    }

    return true;
  }
示例#10
0
 @Override
 public List<User> getUserLisOfCorp(int corpId) {
   List<User> list = organizationDao.getUserLisOfCorp(corpId);
   Corporation c = getCorporation(corpId);
   User u = accountMgr.getUser(c.getUserId());
   list.add(u);
   for (User user : list) {
     int roleId = getUserRoleInCorp(user.getId(), corpId);
     if (user.isAdmin()) {
       roleId = 1; // user is the RAP platform admin
     } else if (user.getId() == c.getUserId()) {
       roleId = 1; // user is the author
     }
     user.setRoleId(roleId);
   }
   return list;
 }
示例#11
0
  @Override
  public int updateProject(Project outerProject) {
    Project project = getProject(outerProject.getId());
    project.setName(outerProject.getName());
    project.setIntroduction(outerProject.getIntroduction());
    project.setUpdateTime(new Date());

    if (outerProject.getMemberAccountList() != null) {
      // adding new ones
      for (String account : outerProject.getMemberAccountList()) {
        User user = accountDao.getUser(account);
        if (user != null) {
          boolean addSuccess = project.addMember(user);
          if (addSuccess) {
            Notification o = new Notification();
            o.setTypeId((short) 2);
            o.setTargetUser(outerProject.getUser());
            o.setUser(user);
            o.setParam1(new Integer(outerProject.getId()).toString());
            o.setParam2(outerProject.getName());
            accountMgr.addNotification(o);
          }
        }
      }

      if (project.getUserList() != null) {
        // remove old ones
        List<User> userListToBeRemoved = new ArrayList<User>();
        for (User user : project.getUserList()) {
          if (!outerProject.getMemberAccountList().contains(user.getAccount())) {
            userListToBeRemoved.add(user);
          }
        }

        for (User user : userListToBeRemoved) {
          project.removeMember(user);
        }
      }
    }

    return projectDao.updateProject(project);
  }
示例#12
0
  @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {

    String url = null;

    if (request instanceof HttpServletRequest) {
      url = ((HttpServletRequest) request).getRequestURL().toString();
    }
    String domain = URLUtils.getDomain(url);
    if (domain != "") {
      SystemConstant.setDOMAIN_URL(domain);
    }

    // all requests count into realtime charts
    SystemVisitorLog.count();

    if (URLUtils.shouldLog(url)) SystemVisitorLog.count(request.getRemoteAddr());

    if (SystemConstant.DOMAIN_URL.isEmpty()) {
      SystemConstant.DOMAIN_URL = request.getServerName();
      if (request.getServerPort() != 80) {
        SystemConstant.DOMAIN_URL += ":" + request.getServerPort();
      }
    }
    HttpSession session = ((HttpServletRequest) request).getSession();
    Object userAccount = session.getAttribute(ContextManager.KEY_ACCOUNT);
    Object userName = session.getAttribute(ContextManager.KEY_NAME);
    boolean logined = userAccount != null;

    SystemConstant.README_PATH =
        session.getServletContext().getRealPath(File.separator + "README.md");
    SystemConstant.ROOT = session.getServletContext().getRealPath(File.separator);

    if (!logined) {
      BucSSOUser user = SimpleUserUtil.getBucSSOUser((HttpServletRequest) request);
      // System.out.println("user:"******"user.getEmpId:" + user.getEmpId());
        // System.out.println("user.getLastName:" + user.getLastName());
        // System.out.println("user.emailAddr:" + user.getEmailAddr());
        // System.out.println("user.loginName:" + user.getLoginName());

        String emailPrefix =
            user.getEmailAddr().substring(0, user.getEmailAddr().indexOf("@alibaba"));
        // System.out.println("emailPrefix:" + emailPrefix);
        User rapUser = accountMgr.getUser(emailPrefix);
        if (rapUser == null) {
          // proceed register
          User newUser = new User();
          newUser.setAccount(emailPrefix);
          newUser.setPassword("RESERVED");
          String name = user.getNickNameCn();
          if (name == null || name.isEmpty()) {
            name = user.getLastName();
          }
          newUser.setName(name);
          newUser.setEmail(user.getEmailAddr());
          newUser.setRealname(user.getLastName());
          newUser.setEmpId(user.getEmpId());
          getAccountMgr().addUser(newUser);
          rapUser = accountMgr.getUser(emailPrefix);
          if (rapUser == null) {
            try {
              throw new Exception("user register failed!");
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        }
        // proceed login
        String account = rapUser.getAccount();
        long userId = rapUser.getId();
        session.setAttribute(ContextManager.KEY_ACCOUNT, account);
        session.setAttribute(ContextManager.KEY_USER_ID, userId);
        session.setAttribute(ContextManager.KEY_NAME, rapUser.getName());
      }

    } else {
      if (URLUtils.shouldLog(url)) {
        User logUser = new User();
        logUser.setAccount((String) userAccount);
        logUser.setName((String) userName);
        SystemVisitorLog.count(logUser);
      }
    }

    chain.doFilter(request, response);
  }
示例#13
0
 @Override
 public boolean canUserManageCorp(long userId, int corpId) {
   int roleId = organizationDao.getUserRoleInCorp(userId, corpId);
   return (roleId >= 1 && roleId <= 2 || userId == getCorporation(corpId).getUserId())
       || accountMgr.getUser(userId).isAdmin();
 }