예제 #1
0
 def addpu(self, user):
     userId = user.get('userId', 0)
     if not userId:
         return 4
     user = User.query.filter_by(isDelete=False, id=userId).first()
     flag = True if user.power == 1 else False
     if not user:
         return 5
     data = self.getjson()
     try:
         userid = int(data.get('id', 0))
         projectid = int(data.get('projectid'))
         isAdmin = int(data.get('isAdmin', 0))
     except:
         return 2
     if not all([userid, projectid]):
         return 1
     puadmin = ProjectUser.query.filter_by(isDelete=False,
                                           userid=user.id,
                                           projectid=projectid).first()
     if not puadmin and not flag:  #判断权限
         return 5
     if not puadmin.isAdmin and not flag:  #判断权限
         return 5
     pu = ProjectUser.query.filter_by(isDelete=False,
                                      userid=userid,
                                      projectid=projectid).first()
     if pu:
         return 3
     pu = ProjectUser()
     pu.userid = userid
     pu.projectid = projectid
     pu.isAdmin = isAdmin
     self.create(pu)
     return 3
예제 #2
0
 def addproject(self, user):
     body = self.getjson()
     name = body.get('name', '')
     pname = body.get('pname', '')
     token = body.get('token', [])
     isGit = body.get('isGit', 0)
     groupId = body.get('groupId', 0)
     groupName = body.get('groupName', '')
     if type(token) is str:
         token = [token]
     res = [
         i for i in pname if not (97 <= ord(i) <= 122 or 65 <= ord(i) <= 90)
     ]
     if res:
         return 2
     repos_url = body.get('repos_url', '')
     ip = body.get('ip', '')
     # startip = body.get('startip', '')备用 统一更新启动
     # flag = self.verip(ip)
     # if not flag or not ip:
     #     return 5
     # flag = self.verip(startip)
     # if not flag or not startip:
     #  return 5
     msg = body.get('msg', '')
     if not all([name, repos_url, token]):
         return 1
     project = Project.query.filter(
         or_(Project.repos_url == repos_url, Project.pname == pname),
         Project.isDelete == False).first()
     userId = user.get('userId', 0)
     if not userId:
         return 4
     if project:
         return 3
     pobj = Project()
     pobj.name = name
     pobj.pname = pname
     pobj.repos_url = repos_url
     pobj.ip = ip
     # pobj.startip = startip
     pobj.msg = msg
     pobj.token = json.dumps(token)
     pobj.groupId = 0
     self.create(pobj)
     if isGit:
         pobj.groupId = pobj.id
     if groupId:
         pobj.groupId = groupId
     if groupName:
         pobj.groupName = groupName
     self.update(pobj)
     pu = ProjectUser()
     pu.projectid = pobj.id
     pu.userid = userId
     pu.isAdmin = 1
     self.create(pu)
     data = {
         "name": name,
         "id": pobj.id,
         "pname": pname,
         "repos_url": repos_url,
         "ip": ip,
         "msg": msg,
         "token": token
     }
     return data