Exemple #1
0
        /// <summary>
        /// Find software in suite (recursive)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Software FindSoftware(Software software) {

            if (software == null) {
                return null;
            }

            if (this.Equals(software)) {
                return this;
            }

            // Get all software in this suite
            QueryResultRows<SuiteSoftware> suiteSoftwares = Db.SQL<SuiteSoftware>("SELECT o FROM Warehouse.SuiteSoftware o WHERE o.Suite=?", this);
            foreach (SuiteSoftware suiteSoftware in suiteSoftwares) {

                if (suiteSoftware.Software is Suite) {
                    Software result = ((Suite)suiteSoftware.Software).FindSoftware(software);
                    if (result != null) {
                        return result;
                    }
                }
                else {
                    if (suiteSoftware.Software.Equals(software)) {
                        return suiteSoftware.Software;
                    }
                }
            }
            return null;
        }
        /// <summary>
        /// Check is user has permission to invoke action on an application
        /// </summary>
        /// <param name="user"></param>
        /// <param name="action"></param>
        /// <param name="application"></param>
        /// <returns></returns>
        public static bool Check(SystemUser user, ActionType action, Software application) {

            if (user == null) {
                //TODO: an anonymouse user can have access to some functions
                return false;
            }

            SoftwarePermission permission = Db.SQL<SoftwarePermission>("SELECT o FROM Warehouse.SoftwarePermission o WHERE o.User=? AND o.Software=?", user, application).First;
            if (permission != null) {
                // TODO: Add what kind of check, CanRead, CanUpdate or CanDelete
                return true;
            }
            return false;
        }
Exemple #3
0
        public bool CanAddSoftware(Software software) {

            if (software == null) {
                return false;
            }

            if (this.FindSoftware(software) == null) {
                if ((software is Suite)) {
                    if (((Suite)software).FindSoftware(this) != null) {
                        return false;
                    }
                }
                return true;
            }

            return false;
        }
Exemple #4
0
        /// <summary>
        /// Get list of depot where software exists in
        /// </summary>
        /// <param name="software"></param>
        /// <returns>List of depots or empty list</returns>
        public static IList<Depot> GetDepotWhereSoftwareExists(Software software) {

            List<Depot> result = new List<Depot>();
            QueryResultRows<Depot> depots = Db.SQL<Depot>("SELECT o FROM Warehouse.Depot o");

            foreach(Depot depot in depots) {

                if( depot.FindSoftware(software) != null ) {
                    result.Add(depot);
                    continue;
                }
            }
            return result;
        }
Exemple #5
0
        public bool CanAddSoftware(Software software) {

            if (software == null) {
                return false;
            }

            DepotSoftware existing = Db.SQL<DepotSoftware>("SELECT o FROM Warehouse.DepotSoftware o WHERE o.Depot=? AND o.Software=?", this, software).First;
            if (existing != null) {
                return false;
            }

            // If the software is from another organization it has to be "Public"
            if( !this.Organization.Equals(software.Organization)) {
                // Software from other organization
                if (software.Private) {
                    return false;
                }
            }

            return true;
        }
Exemple #6
0
        /// <summary>
        /// Find software in depot (searches in suits)
        /// </summary>
        /// <param name="software">Software</param>
        /// <returns></returns>
        public Software FindSoftware(Software software) {

            if (software == null) {
                return null;
            }

            QueryResultRows<DepotSoftware> depotSoftwares = Db.SQL<DepotSoftware>("SELECT o FROM Warehouse.DepotSoftware o WHERE o.Depot=? AND o.Software IS NOT NULL", this);

            foreach (DepotSoftware depotSoftware in depotSoftwares) {

                if (depotSoftware.Software.Equals(software)) {
                    return depotSoftware.Software;
                }

                if (depotSoftware.Software is Suite) {
                    Software result = ((Suite)depotSoftware.Software).FindSoftware(software);
                    if (result != null) {
                        return result;
                    }
                }
            }
            return null;
        }