Beispiel #1
0
        /// <summary>Creates a new Activity instance representing an existing activity with the specified entity and operation.</summary>
        /// <returns>The created Activity object.</returns>
        /// <param name="context">The execution environment context.</param>
        /// <param name="entity">The entity to which the activity relates.</param>
        /// <param name="operation">The operation performed on the entity.</param>
        public static Activity FromEntityAndPrivilege(IfyContext context, Entity entity, EntityOperationType operation)
        {
            var      etype  = EntityType.GetEntityType(entity.GetType());
            var      priv   = Privilege.Get(EntityType.GetEntityTypeFromId(etype.Id), Privilege.GetOperationType(((char)operation).ToString()));
            Activity result = new Activity(context);

            result.Entity       = entity;
            result.EntityTypeId = etype.Id;
            result.Privilege    = priv;
            result.Load();
            return(result);
        }
Beispiel #2
0
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>Gets the privileges associated to this role.</summary>
        /// <returns>An array of privileges.</returns>
        public Privilege[] GetPrivileges()
        {
            List <Privilege> result = new List <Privilege> ();

            string        sql          = string.Format("SELECT id_priv FROM role_priv WHERE id_role={0};", Id);
            IDbConnection dbConnection = context.GetDbConnection();
            IDataReader   reader       = context.GetQueryResult(sql, dbConnection);

            while (reader.Read())
            {
                result.Add(Privilege.Get(reader.GetInt32(0)));
            }
            context.CloseQueryResult(reader, dbConnection);

            return(result.ToArray());
        }
Beispiel #3
0
 /// <summary>Creates a new Activity instance.</summary>
 /// <param name="context">The execution environment context.</param>
 /// <param name="entity">Entity.</param>
 /// <param name="operation">The name of the operation performed on the entity.</param>
 public Activity(IfyContext context, Entity entity, string operation) : base(context)
 {
     if (entity != null)
     {
         try {
             this.EntityId           = entity.Id;
             this.Entity             = entity;
             this.EntityIdentifier   = entity.Identifier;
             this.ActivityEntityType = EntityType.GetEntityType(entity.GetType());
             this.EntityTypeId       = (this.ActivityEntityType.Id != 0 ? this.ActivityEntityType.Id : this.ActivityEntityType.TopTypeId);
             this.DomainId           = entity.DomainId;
             this.Privilege          = Privilege.Get(EntityType.GetEntityTypeFromId(this.EntityTypeId), Privilege.GetOperationType(operation));
         } catch (Exception e) {
             var t = e;
         }
     }
     this.OwnerId = entity.OwnerId;
 }
Beispiel #4
0
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>Returns the privileges of a user for the specified entity item.</summary>
        /// <param name="context">The execution environment context.</param>
        /// <param name="userId">The database ID of the user in question.</param>
        /// <param name="item">The entity item for which the privileges are calculated.</param>
        /// <returns>An array of the privileges related to the entity type that contains only those privileges granted to the user for the item.</returns>
        public static Privilege[] GetUserPrivileges(IfyContext context, int userId, Entity item)
        {
            StringBuilder sql = new StringBuilder();

            sql.Append("SELECT DISTINCT p.id FROM ");
            sql.Append(PrivilegeBaseJoinSql);
            sql.Replace("{0}", userId.ToString());
            sql.Append(String.Format(" WHERE p.id_type={0} AND ", item.EntityType.TopTypeId));
            sql.Append(String.Format("(rg.id_usr={0} OR ug.id_usr={0}) AND ", userId));
            sql.Append(item.DomainId == 0 ? "rg.id_domain IS NULL" : String.Format("(rg.id_domain IS NULL OR rg.id_domain={0});", item.DomainId));

            List <Privilege> result       = new List <Privilege>();
            IDbConnection    dbConnection = context.GetDbConnection();
            IDataReader      reader       = context.GetQueryResult(sql.ToString(), dbConnection);

            while (reader.Read())
            {
                result.Add(Privilege.Get(reader.GetInt32(0)));
            }
            context.CloseQueryResult(reader, dbConnection);

            return(result.ToArray());
        }