GithubHelp home page GithubHelp logo

whatwasit's People

Contributors

gmile avatar lpil avatar mebezac avatar smpallen99 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

whatwasit's Issues

Diff support for String

I want to easily generate diff for %MyProject.User (admin and/or editor role) to preview multi line String e.g %MyProject.Post body field.
This should be method that accept type argument (Atom or String) and optionally lines (Integer).

Lines argument is to limit diff response for X lines around change (not need when type is json).

Type argument may be:

  1. json (for API)
  2. normal (default)
  3. patch-file (for download - file patching and reverting by Linux patch command)
  4. side-by-side

Format for normal:
We have Enum of lines. Each line have String(s) and/or Tuple(s). String(s) are not affected text. Tuple is info about affected text, where:

  • type is in: ["delete", "insert"]
  • change is afftected text

When side-by-side we have tuple: {left_column, right_column} where each column is array of lines (see format for nomal).
For example:
[ ["same text 1", {"insert", "text inserted in first line"}, "same text 2"], ["same text for second line ..."] ]

JSON API:
Returns json with two fields:
source - original text
changes - array of changes where each element has type, line, column, change_length.
For example:
{"source": "First line\nSecondd line\nThird line", "changes":[{"change_length": 1, "column": 7, "line": 2, "type": "delete"}]}
API says: "remove 7th character of 2nd column for given source".

Generating diff should be available for one and all versions (Version) for same model and model id.

Diff support can be optional when installing.

Track creates

Create creates for the purpose of complete auditing. Make it configurable.

Fork: Refactor and simplify code

TODO:

  1. Better code configuration
  2. Better code modularization
  3. No code duplication
  4. No code generation (by templates)
  5. Remove install task

installation error

mix whatwasit.install

running above command throwing below error

* creating priv/repo/migrations/20180219080831_create_whatwasit_version.exs
** (UndefinedFunctionError) function Mix.Phoenix.copy_from/5 is undefined or private. Did you mean one of:

      * copy_from/4
(phoenix) Mix.Phoenix.copy_from([".", :whatwasit], "priv/templates/whatwasit.install/models/whatwasit", "", [base: "AppName", alias: "AppName", human: "AppName", web_module: "AppNameWeb", module: "AppName.AppName", scoped: "AppName", singular: "appName", path: "appName", schema_fields: "", changeset_fields: "~w(item_type item_id object action)a"], [{:eex, "version.ex", "web/models/whatwasit/version.ex"}])

lib/mix/tasks/whatwasit.install.ex:122: Mix.Tasks.Whatwasit.Install.gen_version_model/1
    lib/mix/tasks/whatwasit.install.ex:84: Mix.Tasks.Whatwasit.Install.do_run/1
    (mix) lib/mix/task.ex:314: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:80: Mix.CLI.run_task/2
    (elixir) lib/code.ex:677: Code.require_file/2

basically (phoenix) Mix.Phoenix.copy_from takes only 4 args and 5 are sent from here.
kindly help fixing this.

Conflicts with local function

When use whatwasit with phoenix framework, i use mix phoenix.gen.model Post posts title:string body:string generate a model that include a local changeset function which conflicts with <PROJECT_NAME>.Whatwasit.Version model. I can rename my post model changeset function to other name, but every time i created a model, i need to do repeat rename operations.

So, i suggest rename changset function name in <PROJECT_NAME>.Whatwasit.Version model.

Compiling 1 file (.ex)

== Compilation error on file web/models/post.ex ==
** (CompileError) web/models/post.ex:1: imported WhatwasitExample.Whatwasit.Version.changeset/2 conflicts with local function
    (elixir) src/elixir_locals.erl:138: :elixir_locals."-ensure_no_import_conflict/4-lc$^0/1-0-"/3
    (elixir) src/elixir_locals.erl:137: anonymous fn/4 in :elixir_locals.ensure_no_import_conflict/4
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (elixir) lib/kernel/parallel_compiler.ex:116: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1

Story only changed fields in object

No need to have copy of other data.
When I fetch version I want to see what was changed, but got all properties from object with old values.

Violation of changeset design principals?

Isn't the concept of a changeset that it's in preparation for a change? IE, you create the changeset then later you apply it.. it seems by suggesting users add prepare_version to their models changeset method that you're now making calling changeset have side-effects (writing to the DB), where-as before (intentionally) it had none.

Could be I'm misunderstanding the concept, but I don't think so. I feel like we need yet another function to encapsulate the concept of versioning without piggy-backing on changeset itself.

Question: why migration and model are generated?

In migration we can easily add if statement for app config.

I know that calculating changeset_fields and schema_fields on each request is not a good idea.
Is saving them in configuration (or :ets) after app start (and before listen for requests) and read them in model is bad idea?
Now we have: version.ex and version_map.ex templates.
They are similar and could be written at once with some if's (based on app config).

What do you think about it?

Add log file support (fail2ban and other log tools)

If log file path was specified in configuration (for all tracked changes - dynamic, umbrella apps etc).
Example:
On %{date} %{what} with id %{id} was %{action} by '%{whodoneit_name}' (id: %{whodoneit_id}).
where:
date: when
what: for example article
id: for example Article id
action: one of: ["create", "destroy", "update"]
whodoneit_name: for example John
whodoneit_id: for example John's id

Optionally (in options):
log_formatter_module (if not specified use default formatter).

defmodule MyProject.LogFormatter
    def format(what_was_it) do
        # returns: {:ok, result} tuple where result is log string
    end
end

Why? For example:

  1. fail2ban or other third-party program - for example: rule to ban ip (matched with: whodoneit_id - same ip and same author/user) from which created too more entries (spam bot using REST API).
  2. Somebody may not have accesss to database (company restrictions) - he only want to get all IP addresses (or last activity date) for John (grep by regex where for example whodoneit_id is 5). Here I mean server admin/user, not project web admin or project developer.

Advenced reverting

These methods can be useful:

  1. revert_last_version - reverts last change (only update) - returns tuple: {:ok, version} or raise Whatwasit.NoUpdateVersionError
  2. revert_to_version - revert all changes from X version
  3. revert_by_whodoneit (when whodoneite is a Enum)
  4. revert_by_whodoneit - calls: revert_by_whodoneit([whodoneit])
  5. revert_by_sql (sql part that for example do search in map; adequately to point 3)

For 3rd and 4th point:
revert all changes made by User(s)
returns tuple: {:ok, versions} or {:error, whodoneit} or raise Whatwasit.NoUpdateVersionError
where: whodoneit is User Enum that made changes after one or more changes made by selected whodoneit(s).
Optionally: force parameter that not return error tuple and delete all versions (from selected whodoneit(s) first update version).

This can be done in optional module:

defmodule MyProject.Post do
    use Whatwasit
    use Whatwasit.Revert
    # ...
end

Maybe optionally add is_deleted field for Version (to preview admin activity)? What do you think about it?

User model should be an option

whatwasit.install creates an association for the user model. This does not work if you don't have a user model and don't want to track changes.

The addition of a user model should be an option in the installer, with the default to not create the user association

Auditing branch doesnt work with --whodoneit-map

Whatwasit.Repo calls always module.get_whodoneit_name_and_id/1 in insert_version/3.
With --whodoneit-map this doesn't work, since that code is not generated and can not return sensible values anyway.

Support a user model that is not an Ecto model

For a project that uses an LDAP user model, we should be able to support this. The LDAP id is a big int.

To support this, we can provide an install option to define the type type of the whodoneit field. As well, we can provide an option to set :name_field config item to a {Module, Fun} value. When set to a tuple, the function will be called to get the whodoneit_name value.

Add map for additional data e.g data of request

I want to save more data that is not stored in User model e.g request data.
For example:

  1. Store map with IP address to easily detect what changes was made from particular IP.
  2. Store user agent for statistics.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.