Esempio n. 1
0
        //--- Methods ---
        public virtual BanBE Copy()
        {
            BanBE ban = new BanBE();

            ban.BanAddresses = new List <string>(BanAddresses);
            ban.BanUserIds   = new List <uint>(BanUserIds);
            ban.ByUserId     = ByUserId;
            ban.Expires      = Expires;
            ban.Id           = Id;
            ban.LastEdit     = LastEdit;
            ban.Reason       = Reason;
            ban.RevokeMask   = RevokeMask;
            return(ban);
        }
Esempio n. 2
0
 //--- Methods ---
 public virtual BanBE Copy() {
     BanBE ban = new BanBE();
     ban.BanAddresses = new List<string>(BanAddresses);
     ban.BanUserIds = new List<uint>(BanUserIds);
     ban.ByUserId = ByUserId;
     ban.Expires = Expires;
     ban.Id = Id;
     ban.LastEdit = LastEdit;
     ban.Reason = Reason;
     ban.RevokeMask = RevokeMask;
     return ban;
 }
Esempio n. 3
0
 public static void DeleteBan(BanBE ban) {
     if (ban != null) {
         DbUtils.CurrentSession.Bans_Delete(ban.Id);
         TokenReset();
     }
 }
Esempio n. 4
0
 public static XDoc GetBanXml(BanBE ban) {
     return AppendBanXml(new XDoc("ban"), ban);
 }
Esempio n. 5
0
        private static XDoc AppendBanXml(XDoc doc, BanBE ban) {
            UserBE createdBy = UserBL.GetUserById(ban.ByUserId);

            doc.Attr("id", ban.Id);
            doc.Attr("href", DekiContext.Current.ApiUri.At("site", "bans", ban.Id.ToString()));

            if (createdBy != null) {
                doc.Add(UserBL.GetUserXml(createdBy, "createdby", Utils.ShowPrivateUserInfo(createdBy)));
            }

            doc.Elem("date.modified", ban.LastEdit);
            doc.Elem("description", ban.Reason);
            doc.Elem("date.expires", ban.Expires);
            doc.Add(PermissionsBL.GetPermissionXml(ban.RevokeMask, "revoked"));

            doc.Start("ban.addresses");
            if (ban.BanAddresses != null) {
                foreach (string address in ban.BanAddresses) {
                    doc.Elem("address", address);
                }
            }
            doc.End();

            doc.Start("ban.users");
            if (ban.BanUserIds != null) {
                IList<UserBE> banUsers = DbUtils.CurrentSession.Users_GetByIds(ban.BanUserIds);
                foreach(UserBE u in banUsers){
                    doc.Add(UserBL.GetUserXml(u, null, Utils.ShowPrivateUserInfo(createdBy)));
                }
                
            }
            doc.End();

            return doc;
        }
Esempio n. 6
0
        private static BanBE ReadBanXml(XDoc doc) {
            BanBE b = new BanBE();
            b.BanAddresses = new List<string>();
            b.BanUserIds = new List<uint>();
            try {
                b.Reason = doc["description"].AsText;
                b.RevokeMask = PermissionsBL.MaskFromPermissionList(PermissionsBL.PermissionListFromString(doc["permissions.revoked/operations"].AsText ?? string.Empty));
                b.LastEdit = DateTime.UtcNow;
                b.Expires = doc["date.expires"].AsDate;
                b.ByUserId = DekiContext.Current.User.ID;

                foreach (XDoc val in doc["ban.addresses/address"]) {
                    if (!val.IsEmpty) {
                        b.BanAddresses.Add(val.AsText);
                    }
                }

                foreach (XDoc val in doc["ban.users/user"]) {
                    uint? id = val["@id"].AsUInt;
                    if (id != null) {
                        b.BanUserIds.Add(id ?? 0);
                    }
                }
            } catch (Exception x) {
                throw new DreamAbortException(DreamMessage.BadRequest(x.Message));
            }

            return b;
        }
 private void BanEvent(DateTime eventTime, BanBE ban, params string[] channelPath) {
     try {
         XUri channel = _channel.At(BAN).At(channelPath);
         XDoc doc = new XDoc("deki-event")
             .Elem("channel", channel)
             .Elem("banid", ban.Id)
             .Elem("reason", ban.Reason)
             .Elem("by", ban.ByUserId);
         if(ban.BanAddresses.Count > 0) {
             doc.Start("addresses");
             foreach(string address in ban.BanAddresses) {
                 doc.Elem("address", address);
             }
             doc.End();
         }
         if(ban.BanUserIds.Count > 0) {
             doc.Start("users");
             foreach(uint userId in ban.BanUserIds) {
                 doc.Start("user").Attr("id", userId).End();
             }
             doc.End();
         }
         Queue(eventTime, channel, null, new string[] { string.Format("http://{0}/deki", _wikiid) }, doc);
     } catch(Exception e) {
         _log.WarnExceptionMethodCall(e, "BanEvent", "event couldn't be created");
     }
 }
 public void BanRemoved(DateTime eventTime, BanBE ban) {
     BanEvent(eventTime, ban, DELETE);
 }
 public void BanCreated(DateTime eventTime, BanBE ban) {
     BanEvent(eventTime, ban, CREATE);
 }
Esempio n. 10
0
 public uint Bans_Insert(BanBE ban) {
     Stopwatch sw = Stopwatch.StartNew();
     var ret = _next.Bans_Insert(ban);
     LogQuery(CATEGORY_BANS, "Bans_Insert", sw, "ban", ban);
     return ret;
 }